… | |
… | |
24 | sub new { |
24 | sub new { |
25 | my ($self, $id) = @_; |
25 | my ($self, $id) = @_; |
26 | |
26 | |
27 | $self = bless { id => $id }, $self; |
27 | $self = bless { id => $id }, $self; |
28 | |
28 | |
|
|
29 | # register |
|
|
30 | $AnyEvent::MP::Kernel::NODE{$id} = $self; |
|
|
31 | |
29 | $self->init; |
32 | $self->init; |
30 | $self->transport_reset; |
33 | $self->transport_reset; |
31 | |
34 | |
32 | $self |
35 | $self |
|
|
36 | } |
|
|
37 | |
|
|
38 | sub DESTROY { |
|
|
39 | # unregister |
|
|
40 | delete $AnyEvent::MP::Kernel::NODE{$_[0]{id}}; |
33 | } |
41 | } |
34 | |
42 | |
35 | sub init { |
43 | sub init { |
36 | # |
44 | # |
37 | } |
45 | } |
… | |
… | |
77 | } |
85 | } |
78 | |
86 | |
79 | AnyEvent::MP::Kernel::_inject_nodeevent ($self, 0, @reason) |
87 | AnyEvent::MP::Kernel::_inject_nodeevent ($self, 0, @reason) |
80 | unless $no_transport; |
88 | unless $no_transport; |
81 | |
89 | |
82 | # if we are here and are idle, we nuke ourselves |
90 | # we weaken the node reference, so it can go away if unused |
83 | delete $AnyEvent::MP::Kernel::NODE{$self->{id}} |
91 | Scalar::Util::weaken $AnyEvent::MP::Kernel::NODE{$self->{id}} |
84 | unless $self->{transport} || $self->{connect_to}; |
92 | unless $self->{connect_to}; |
|
|
93 | |
|
|
94 | AE::log 9 => "@reason"; |
85 | } |
95 | } |
86 | |
96 | |
87 | # called after handshake was successful |
97 | # called after handshake was successful |
88 | sub transport_connect { |
98 | sub transport_connect { |
89 | my ($self, $transport) = @_; |
99 | my ($self, $transport) = @_; |
… | |
… | |
112 | my ($self) = @_; |
122 | my ($self) = @_; |
113 | |
123 | |
114 | return if $self->{transport}; |
124 | return if $self->{transport}; |
115 | return if $self->{connect_w}; |
125 | return if $self->{connect_w}; |
116 | |
126 | |
|
|
127 | # we unweaken the node reference, in case it was weakened before |
|
|
128 | $AnyEvent::MP::Kernel::NODE{$self->{id}} |
|
|
129 | = $AnyEvent::MP::Kernel::NODE{$self->{id}}; |
|
|
130 | |
117 | Scalar::Util::weaken $self; |
131 | Scalar::Util::weaken $self; |
118 | |
132 | |
119 | $self->{connect_to} ||= AE::timer $AnyEvent::MP::Kernel::CONFIG->{connect_interval}, 0, sub { |
133 | $self->{connect_to} ||= AE::timer $AnyEvent::MP::Kernel::CONFIG->{connect_interval}, 0, sub { |
120 | $self->transport_error (transport_error => $self->{id}, "unable to connect"); |
134 | $self->transport_error (transport_error => $self->{id}, "connect timeout"); |
121 | }; |
135 | }; |
122 | |
136 | |
123 | # maybe @$addresses? |
137 | # maybe @$addresses? |
124 | my $addresses = $AnyEvent::MP::Kernel::GLOBAL_DB{"'l"}{$self->{id}}; |
138 | my $addresses = $AnyEvent::MP::Kernel::GLOBAL_DB{"'l"}{$self->{id}}; |
125 | |
139 | |
126 | if ($addresses) { |
140 | if ($addresses) { |
127 | $self->connect_to ($addresses); |
141 | $self->connect_to ($addresses); |
128 | } else { |
142 | } else { |
129 | # on global nodes, all bets are off now - we either know the node, or we don't |
143 | # on global nodes, all bets are off now - we either know the node, or we don't |
130 | unless ($AnyEvent::MP::Kernel::GLOBAL) { |
144 | if ($AnyEvent::MP::Kernel::GLOBAL) { |
|
|
145 | $self->transport_error (transport_error => $self->{id}, "no known address"); |
|
|
146 | } else { |
131 | AnyEvent::MP::Kernel::g_find ($self->{id}); |
147 | AnyEvent::MP::Kernel::g_find ($self->{id}); |
132 | } |
148 | } |
133 | } |
149 | } |
134 | } |
150 | } |
135 | |
151 | |
… | |
… | |
137 | my ($self, $addresses) = @_; |
153 | my ($self, $addresses) = @_; |
138 | |
154 | |
139 | return if $self->{transport}; |
155 | return if $self->{transport}; |
140 | return if $self->{connect_w}; |
156 | return if $self->{connect_w}; |
141 | |
157 | |
142 | return unless @$addresses; |
158 | unless (@$addresses) { |
|
|
159 | $self->transport_error (transport_error => $self->{id}, "no known address"); |
|
|
160 | return; |
|
|
161 | } |
143 | |
162 | |
144 | AE::log 9 => "connecting to $self->{id} with [@$addresses]"; |
163 | AE::log 9 => "connecting to $self->{id} with [@$addresses]"; |
145 | |
164 | |
146 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
165 | my $monitor = $AnyEvent::MP::Kernel::CONFIG->{monitor_timeout}; |
147 | my $interval = $AnyEvent::MP::Kernel::CONFIG->{connect_interval}; |
166 | my $interval = $AnyEvent::MP::Kernel::CONFIG->{connect_interval}; |
… | |
… | |
170 | } |
189 | } |
171 | |
190 | |
172 | sub kill { |
191 | sub kill { |
173 | my ($self, $port, @reason) = @_; |
192 | my ($self, $port, @reason) = @_; |
174 | |
193 | |
175 | $self->{send} (["", kil => $port, @reason]); |
194 | $self->{send} (["", kil1 => $port, @reason]); |
176 | } |
195 | } |
177 | |
196 | |
178 | sub monitor { |
197 | sub monitor { |
179 | my ($self, $portid, $cb) = @_; |
198 | my ($self, $portid, $cb) = @_; |
180 | |
199 | |