… | |
… | |
132 | Scalar::Util::weaken (my $self = $self); |
132 | Scalar::Util::weaken (my $self = $self); |
133 | |
133 | |
134 | $arg{secret} = AnyEvent::MP::Base::default_secret () |
134 | $arg{secret} = AnyEvent::MP::Base::default_secret () |
135 | unless exists $arg{secret}; |
135 | unless exists $arg{secret}; |
136 | |
136 | |
137 | $arg{timeout} = 30 |
137 | $arg{timeout} = 3#d# |
138 | unless exists $arg{timeout}; |
138 | unless exists $arg{timeout}; |
139 | |
|
|
140 | my $keepalive = (int $arg{timeout} * 0.75) || 1; |
|
|
141 | |
139 | |
142 | my $secret = $arg{secret}; |
140 | my $secret = $arg{secret}; |
143 | |
141 | |
144 | if ($secret =~ /-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY-----.*-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----/s) { |
142 | if ($secret =~ /-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY-----.*-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----/s) { |
145 | # assume TLS mode |
143 | # assume TLS mode |
… | |
… | |
170 | $self->{local_node} = $AnyEvent::MP::Base::NODE; |
168 | $self->{local_node} = $AnyEvent::MP::Base::NODE; |
171 | |
169 | |
172 | $greeting_kv->{"tls"} = "1.0" if $arg{tls_ctx}; |
170 | $greeting_kv->{"tls"} = "1.0" if $arg{tls_ctx}; |
173 | $greeting_kv->{provider} = "AE-$VERSION"; |
171 | $greeting_kv->{provider} = "AE-$VERSION"; |
174 | $greeting_kv->{peeraddr} = AnyEvent::Socket::format_hostport $self->{peerhost}, $self->{peerport}; |
172 | $greeting_kv->{peeraddr} = AnyEvent::Socket::format_hostport $self->{peerhost}, $self->{peerport}; |
175 | $greeting_kv->{maxidle} = $keepalive; |
173 | $greeting_kv->{timeout} = $arg{timeout}; |
176 | |
174 | |
177 | # send greeting |
175 | # send greeting |
178 | my $lgreeting1 = "aemp;$PROTOCOL_VERSION" |
176 | my $lgreeting1 = "aemp;$PROTOCOL_VERSION" |
179 | . ";$AnyEvent::MP::Base::UNIQ" |
|
|
180 | . ";$self->{local_node}" |
177 | . ";$self->{local_node}" |
181 | . ";" . (join ",", @AUTH_RCV) |
178 | . ";" . (join ",", @AUTH_RCV) |
182 | . ";" . (join ",", @FRAMINGS) |
179 | . ";" . (join ",", @FRAMINGS) |
183 | . (join "", map ";$_=$greeting_kv->{$_}", keys %$greeting_kv); |
180 | . (join "", map ";$_=$greeting_kv->{$_}", keys %$greeting_kv); |
184 | |
181 | |
… | |
… | |
189 | # expect greeting |
186 | # expect greeting |
190 | $self->{hdl}->rbuf_max (4 * 1024); |
187 | $self->{hdl}->rbuf_max (4 * 1024); |
191 | $self->{hdl}->push_read (line => sub { |
188 | $self->{hdl}->push_read (line => sub { |
192 | my $rgreeting1 = $_[1]; |
189 | my $rgreeting1 = $_[1]; |
193 | |
190 | |
194 | my ($aemp, $version, $uniq, $rnode, $auths, $framings, @kv) = split /;/, $rgreeting1; |
191 | my ($aemp, $version, $rnode, $auths, $framings, @kv) = split /;/, $rgreeting1; |
195 | |
192 | |
196 | if ($aemp ne "aemp") { |
193 | if ($aemp ne "aemp") { |
197 | return $self->error ("unparsable greeting"); |
194 | return $self->error ("unparsable greeting"); |
198 | } elsif ($version != $PROTOCOL_VERSION) { |
195 | } elsif ($version != $PROTOCOL_VERSION) { |
199 | return $self->error ("version mismatch (we: $PROTOCOL_VERSION, they: $version)"); |
196 | return $self->error ("version mismatch (we: $PROTOCOL_VERSION, they: $version)"); |
… | |
… | |
221 | } |
218 | } |
222 | |
219 | |
223 | defined $s_framing |
220 | defined $s_framing |
224 | or return $self->error ("$framings: no common framing method supported"); |
221 | or return $self->error ("$framings: no common framing method supported"); |
225 | |
222 | |
226 | $self->{remote_uniq} = $uniq; |
|
|
227 | $self->{remote_node} = $rnode; |
223 | $self->{remote_node} = $rnode; |
228 | |
224 | |
229 | $self->{remote_greeting} = { |
225 | $self->{remote_greeting} = { |
230 | map /^([^=]+)(?:=(.*))?/ ? ($1 => $2) : (), |
226 | map /^([^=]+)(?:=(.*))?/ ? ($1 => $2) : (), |
231 | @kv |
227 | @kv |
… | |
… | |
272 | $self->{s_framing} = $s_framing; |
268 | $self->{s_framing} = $s_framing; |
273 | |
269 | |
274 | $hdl->rbuf_max (undef); |
270 | $hdl->rbuf_max (undef); |
275 | my $queue = delete $self->{queue}; # we are connected |
271 | my $queue = delete $self->{queue}; # we are connected |
276 | |
272 | |
277 | $self->{hdl}->timeout ($self->{remote_greeting}{keepalive} + 5) |
273 | $self->{hdl}->timeout ($self->{remote_greeting}{timeout}); |
278 | if $self->{remote_greeting}{keepalive}; |
|
|
279 | |
274 | |
280 | $self->connected; |
275 | $self->connected; |
281 | |
276 | |
282 | my $src_node = $self->{node}; |
277 | my $src_node = $self->{node}; |
283 | |
278 | |
… | |
… | |
392 | |
387 | |
393 | The protocol version supported by this end, currently C<0>. If the |
388 | The protocol version supported by this end, currently C<0>. If the |
394 | versions don't match then no communication is possible. Minor extensions |
389 | versions don't match then no communication is possible. Minor extensions |
395 | are supposed to be handled through additional key-value pairs. |
390 | are supposed to be handled through additional key-value pairs. |
396 | |
391 | |
397 | =item a token uniquely identifying the current node instance |
|
|
398 | |
|
|
399 | This is a string that must change between restarts. It usually contains |
|
|
400 | things like the current time, the (OS) process id or similar values, but |
|
|
401 | no meaning of the contents are assumed. |
|
|
402 | |
|
|
403 | =item the node endpoint descriptors |
392 | =item the node endpoint descriptors |
404 | |
393 | |
405 | for public nodes, this is a comma-separated list of protocol endpoints, |
394 | for public nodes, this is a comma-separated list of protocol endpoints, |
406 | i.e., the noderef. For slave nodes, this is a unique identifier. |
395 | i.e., the noderef. For slave nodes, this is a unique identifier of the |
|
|
396 | form C<slave/nonce>. |
407 | |
397 | |
408 | =item the acceptable authentication methods |
398 | =item the acceptable authentication methods |
409 | |
399 | |
410 | A comma-separated list of authentication methods supported by the |
400 | A comma-separated list of authentication methods supported by the |
411 | node. Note that AnyEvent::MP supports a C<hex_secret> authentication |
401 | node. Note that AnyEvent::MP supports a C<hex_secret> authentication |
… | |
… | |
440 | =item tls=<major>.<minor> |
430 | =item tls=<major>.<minor> |
441 | |
431 | |
442 | Indicates that the other side supports TLS (version should be 1.0) and |
432 | Indicates that the other side supports TLS (version should be 1.0) and |
443 | wishes to do a TLS handshake. |
433 | wishes to do a TLS handshake. |
444 | |
434 | |
445 | =item maxidle=<seconds> |
435 | =item timeout=<seconds> |
446 | |
436 | |
447 | The maximum amount of time the node will not sent data, i.e., idle. This |
437 | The amount of time after which this node should be detected as dead unless |
448 | can be used to close the conenction when no data has been received for a |
438 | some data has been received. The node is responsible to send traffic |
449 | too-long time (say, maxidle + 5 seconds). |
439 | reasonably more often than this interval (such as every timeout minus five |
|
|
440 | seconds). |
450 | |
441 | |
451 | =back |
442 | =back |
452 | |
443 | |
453 | =head3 Second Greeting Line |
444 | =head3 Second Greeting Line |
454 | |
445 | |