… | |
… | |
40 | ); |
40 | ); |
41 | |
41 | |
42 | our $DEFAULT_SECRET; |
42 | our $DEFAULT_SECRET; |
43 | our $DEFAULT_PORT = "4040"; |
43 | our $DEFAULT_PORT = "4040"; |
44 | |
44 | |
45 | our $CONNECT_INTERVAL = 5; # new connect every 5s, at least |
45 | our $CONNECT_INTERVAL = 2; # new connect every 2s, at least |
46 | our $CONNECT_TIMEOUT = 30; # includes handshake |
46 | our $CONNECT_TIMEOUT = 5; # includes handshake |
|
|
47 | our $CONNECT_TIMEOUT_MAX = 90; # never retry less often |
47 | |
48 | |
48 | =item $AnyEvent::MP::Base::WARN |
49 | =item $AnyEvent::MP::Base::WARN |
49 | |
50 | |
50 | This value is called with an error or warning message, when e.g. a connection |
51 | This value is called with an error or warning message, when e.g. a connection |
51 | could not be created, authorisation failed and so on. |
52 | could not be created, authorisation failed and so on. |
… | |
… | |
123 | our %NODE; # node id to transport mapping, or "undef", for local node |
124 | our %NODE; # node id to transport mapping, or "undef", for local node |
124 | our (%PORT, %PORT_DATA); # local ports |
125 | our (%PORT, %PORT_DATA); # local ports |
125 | |
126 | |
126 | our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb) |
127 | our %RMON; # local ports monitored by remote nodes ($RMON{noderef}{portid} == cb) |
127 | our %LMON; # monitored _local_ ports |
128 | our %LMON; # monitored _local_ ports |
128 | |
|
|
129 | our %REG; # registered port names |
|
|
130 | |
129 | |
131 | our %LISTENER; |
130 | our %LISTENER; |
132 | |
131 | |
133 | our $SRCNODE; # holds the sending node during _inject |
132 | our $SRCNODE; # holds the sending node during _inject |
134 | |
133 | |
… | |
… | |
317 | } |
316 | } |
318 | |
317 | |
319 | (add_node $_)->connect for @others; |
318 | (add_node $_)->connect for @others; |
320 | |
319 | |
321 | if ($SLAVE) { |
320 | if ($SLAVE) { |
|
|
321 | my $timeout = AE::timer $CONNECT_TIMEOUT, 0, sub { $SLAVE->() }; |
322 | $SLAVE->recv; |
322 | $SLAVE->recv |
|
|
323 | or Carp::croak "AnyEvent::MP: unable to enter slave mode, unable to connect to a seednode.\n"; |
323 | $SLAVE = 1; |
324 | $SLAVE = 1; |
324 | } |
325 | } |
325 | } |
326 | } |
326 | |
327 | |
327 | ############################################################################# |
328 | ############################################################################# |
… | |
… | |
332 | |
333 | |
333 | unless (defined &$func) { |
334 | unless (defined &$func) { |
334 | my $pkg = $func; |
335 | my $pkg = $func; |
335 | do { |
336 | do { |
336 | $pkg =~ s/::[^:]+$// |
337 | $pkg =~ s/::[^:]+$// |
337 | or return sub { die "unable to resolve $func" }; |
338 | or return sub { die "unable to resolve '$func'" }; |
338 | eval "require $pkg"; |
339 | eval "require $pkg"; |
339 | } until defined &$func; |
340 | } until defined &$func; |
340 | } |
341 | } |
341 | |
342 | |
342 | \&$func |
343 | \&$func |
… | |
… | |
370 | $NODE{$_[0]} = $SRCNODE; |
371 | $NODE{$_[0]} = $SRCNODE; |
371 | }, |
372 | }, |
372 | |
373 | |
373 | # public services |
374 | # public services |
374 | |
375 | |
375 | # well-known-port lookup |
|
|
376 | lookup => sub { |
|
|
377 | my $name = shift; |
|
|
378 | my $port = $REG{$name}; |
|
|
379 | #TODO: check validity |
|
|
380 | snd @_, $port; |
|
|
381 | }, |
|
|
382 | |
|
|
383 | # relay message to another node / generic echo |
376 | # relay message to another node / generic echo |
384 | relay => sub { |
377 | relay => sub { |
385 | &snd; |
378 | &snd; |
386 | }, |
379 | }, |
387 | relay_multiple => sub { |
380 | relay_multiple => sub { |