… | |
… | |
18 | =head1 DESCRIPTION |
18 | =head1 DESCRIPTION |
19 | |
19 | |
20 | This module implements the freenet client protocol version 2.0, as used by |
20 | This module implements the freenet client protocol version 2.0, as used by |
21 | freenet 0.7. See L<Net::FCP> for the earlier freenet 0.5 version. |
21 | freenet 0.7. See L<Net::FCP> for the earlier freenet 0.5 version. |
22 | |
22 | |
23 | See L<http://wiki.freenetproject.org/FreenetFCPSpec2Point0> for a |
23 | See L<https://wiki.freenetproject.org/FCP> for a description of what the |
24 | description of what the messages do. |
24 | messages do. |
25 | |
25 | |
26 | The module uses L<AnyEvent> to find a suitable event module. |
26 | The module uses L<AnyEvent> to find a suitable event module. |
27 | |
27 | |
28 | Only very little is implemented, ask if you need more, and look at the |
28 | Only very little is implemented, ask if you need more, and look at the |
29 | example program later in this section. |
29 | example program later in this section. |
… | |
… | |
265 | } |
265 | } |
266 | |
266 | |
267 | sub fatal { |
267 | sub fatal { |
268 | my ($self, $msg) = @_; |
268 | my ($self, $msg) = @_; |
269 | |
269 | |
270 | $self->{hdl}->shutdown; |
270 | $self->{hdl}->push_shutdown if $self->{hdl}; |
271 | delete $self->{kw}; |
271 | delete $self->{kw}; |
272 | |
272 | |
273 | if ($self->{on_error}) { |
273 | if ($self->{on_error}) { |
274 | $self->{on_error}->($self, $msg); |
274 | $self->{on_error}->($self, $msg); |
275 | } else { |
275 | } else { |
276 | die $msg; |
276 | die "AnyEvent::FCP($self->{host}:$self->{port}): $msg"; |
277 | } |
277 | } |
278 | } |
278 | } |
279 | |
279 | |
280 | sub identifier { |
280 | sub identifier { |
281 | $_[0]{prefix} . ++$_[0]{idseq} |
281 | $_[0]{prefix} . ++$_[0]{idseq} |
… | |
… | |
291 | $self->{id}{$id} = delete $kv{id_cb}; |
291 | $self->{id}{$id} = delete $kv{id_cb}; |
292 | } |
292 | } |
293 | |
293 | |
294 | my $msg = (touc $type) . "\012" |
294 | my $msg = (touc $type) . "\012" |
295 | . join "", map +(touc $_) . "=$kv{$_}\012", keys %kv; |
295 | . join "", map +(touc $_) . "=$kv{$_}\012", keys %kv; |
296 | |
|
|
297 | sub id { |
|
|
298 | my ($self) = @_; |
|
|
299 | |
|
|
300 | |
|
|
301 | } |
|
|
302 | |
296 | |
303 | if (defined $data) { |
297 | if (defined $data) { |
304 | $msg .= "DataLength=" . (length $data) . "\012" |
298 | $msg .= "DataLength=" . (length $data) . "\012" |
305 | . "Data\012$data"; |
299 | . "Data\012$data"; |
306 | } else { |
300 | } else { |