… | |
… | |
99 | $_; |
99 | $_; |
100 | } |
100 | } |
101 | |
101 | |
102 | sub tolc($) { |
102 | sub tolc($) { |
103 | local $_ = shift; |
103 | local $_ = shift; |
104 | 1 while s/(SVK|CHK|URI)/\L$1\_/; |
104 | 1 while s/(SVK|CHK|URI)([^_])/$1\_$2/i; |
|
|
105 | 1 while s/([^_])(SVK|CHK|URI)/$1\_$2/i; |
105 | s/(?<=[a-z])(?=[A-Z])/_/g; |
106 | s/(?<=[a-z])(?=[A-Z])/_/g; |
106 | lc $_; |
107 | lc $_; |
107 | } |
108 | } |
108 | |
109 | |
109 | # the opposite of hex |
110 | # the opposite of hex |
… | |
… | |
181 | #$meta->{tail} = substr $data, pos $data; |
182 | #$meta->{tail} = substr $data, pos $data; |
182 | |
183 | |
183 | $meta; |
184 | $meta; |
184 | } |
185 | } |
185 | |
186 | |
186 | =item $fcp = new Net::FCP [host => $host][, port => $port] |
187 | =item $fcp = new Net::FCP [host => $host][, port => $port][, progress => \&cb] |
187 | |
188 | |
188 | Create a new virtual FCP connection to the given host and port (default |
189 | Create a new virtual FCP connection to the given host and port (default |
189 | 127.0.0.1:8481, or the environment variables C<FREDHOST> and C<FREDPORT>). |
190 | 127.0.0.1:8481, or the environment variables C<FREDHOST> and C<FREDPORT>). |
190 | |
191 | |
191 | Connections are virtual because no persistent physical connection is |
192 | Connections are virtual because no persistent physical connection is |
192 | established. |
193 | established. |
|
|
194 | |
|
|
195 | You can install a progress callback that is being called with the Net::FCP |
|
|
196 | object, a txn object, the type of the transaction and the attributes. Use |
|
|
197 | it like this: |
|
|
198 | |
|
|
199 | sub progress_cb { |
|
|
200 | my ($self, $txn, $type, $attr) = @_; |
|
|
201 | |
|
|
202 | warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
|
|
203 | } |
193 | |
204 | |
194 | =begin comment |
205 | =begin comment |
195 | |
206 | |
196 | However, the existance of the node is checked by executing a |
207 | However, the existance of the node is checked by executing a |
197 | C<ClientHello> transaction. |
208 | C<ClientHello> transaction. |
… | |
… | |
213 | $self; |
224 | $self; |
214 | } |
225 | } |
215 | |
226 | |
216 | sub progress { |
227 | sub progress { |
217 | my ($self, $txn, $type, $attr) = @_; |
228 | my ($self, $txn, $type, $attr) = @_; |
|
|
229 | |
|
|
230 | $self->{progress}->($self, $txn, $type, $attr) |
|
|
231 | if $self->{progress}; |
218 | #warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
232 | #warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
219 | } |
233 | } |
220 | |
234 | |
221 | =item $txn = $fcp->txn(type => attr => val,...) |
235 | =item $txn = $fcp->txn(type => attr => val,...) |
222 | |
236 | |
… | |
… | |
324 | |
338 | |
325 | =item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) |
339 | =item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) |
326 | |
340 | |
327 | =item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
341 | =item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
328 | |
342 | |
329 | Calculcates a CHK, given the metadata and data. C<$cipher> is either |
343 | Calculates a CHK, given the metadata and data. C<$cipher> is either |
330 | C<Rijndael> or C<Twofish>, with the latter being the default. |
344 | C<Rijndael> or C<Twofish>, with the latter being the default. |
331 | |
345 | |
332 | =cut |
346 | =cut |
333 | |
347 | |
334 | $txn->(generate_chk => sub { |
348 | $txn->(generate_chk => sub { |
… | |
… | |
401 | =item ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
415 | =item ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
402 | |
416 | |
403 | Fetches a (small, as it should fit into memory) file from |
417 | Fetches a (small, as it should fit into memory) file from |
404 | freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or |
418 | freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or |
405 | C<undef>). |
419 | C<undef>). |
|
|
420 | |
|
|
421 | The C<$uri> should begin with C<freenet:>, but the scheme is currently |
|
|
422 | added, if missing. |
406 | |
423 | |
407 | Due to the overhead, a better method to download big files should be used. |
424 | Due to the overhead, a better method to download big files should be used. |
408 | |
425 | |
409 | my ($meta, $data) = @{ |
426 | my ($meta, $data) = @{ |
410 | $fcp->client_get ( |
427 | $fcp->client_get ( |
… | |
… | |
610 | } |
627 | } |
611 | } elsif ($self->{buf} =~ s/^DataChunk\015?\012Length=([0-9a-fA-F]+)\015?\012Data\015?\012//) { |
628 | } elsif ($self->{buf} =~ s/^DataChunk\015?\012Length=([0-9a-fA-F]+)\015?\012Data\015?\012//) { |
612 | $self->{datalen} = hex $1; |
629 | $self->{datalen} = hex $1; |
613 | #warn "expecting new datachunk $self->{datalen}\n";#d# |
630 | #warn "expecting new datachunk $self->{datalen}\n";#d# |
614 | } elsif ($self->{buf} =~ s/^([a-zA-Z]+)\015?\012(?:(.+?)\015?\012)?EndMessage\015?\012//s) { |
631 | } elsif ($self->{buf} =~ s/^([a-zA-Z]+)\015?\012(?:(.+?)\015?\012)?EndMessage\015?\012//s) { |
|
|
632 | print "RECV<$1>\n"; |
615 | $self->rcv ($1, { |
633 | $self->rcv ($1, { |
616 | map { my ($a, $b) = split /=/, $_, 2; ((Net::FCP::tolc $a), $b) } |
634 | map { my ($a, $b) = split /=/, $_, 2; ((Net::FCP::tolc $a), $b) } |
617 | split /\015?\012/, $2 |
635 | split /\015?\012/, $2 |
618 | }); |
636 | }); |
619 | } else { |
637 | } else { |
… | |
… | |
681 | } |
699 | } |
682 | } |
700 | } |
683 | |
701 | |
684 | sub progress { |
702 | sub progress { |
685 | my ($self, $type, $attr) = @_; |
703 | my ($self, $type, $attr) = @_; |
|
|
704 | |
686 | $self->{fcp}->progress ($self, $type, $attr); |
705 | $self->{fcp}->progress ($self, $type, $attr); |
687 | } |
706 | } |
688 | |
707 | |
689 | =item $result = $txn->result |
708 | =item $result = $txn->result |
690 | |
709 | |
… | |
… | |
769 | |
788 | |
770 | # base class for get and put |
789 | # base class for get and put |
771 | |
790 | |
772 | use base Net::FCP::Txn; |
791 | use base Net::FCP::Txn; |
773 | |
792 | |
774 | *rcv_uri_error = \&Net::FCP::Txn::rcv_throw_exception; |
793 | *rcv_uri_error = \&Net::FCP::Txn::rcv_throw_exception; |
775 | *rcv_route_not_found = \&Net::FCP::Txn::rcv_throw_exception; |
794 | *rcv_route_not_found = \&Net::FCP::Txn::rcv_throw_exception; |
776 | |
795 | |
777 | sub rcv_restarted { |
796 | sub rcv_restarted { |
778 | my ($self, $attr, $type) = @_; |
797 | my ($self, $attr, $type) = @_; |
779 | |
798 | |
780 | delete $self->{datalength}; |
799 | delete $self->{datalength}; |
… | |
… | |
913 | =cut |
932 | =cut |
914 | |
933 | |
915 | package Net::FCP::Event::Auto; |
934 | package Net::FCP::Event::Auto; |
916 | |
935 | |
917 | my @models = ( |
936 | my @models = ( |
918 | [Coro => Coro::Event:: ], |
937 | [Coro => Coro::Event::], |
919 | [Event => Event::], |
938 | [Event => Event::], |
920 | [Glib => Glib:: ], |
939 | [Glib => Glib::], |
921 | [Tk => Tk::], |
940 | [Tk => Tk::], |
922 | ); |
941 | ); |
923 | |
942 | |
924 | sub AUTOLOAD { |
943 | sub AUTOLOAD { |
925 | $AUTOLOAD =~ s/.*://; |
944 | $AUTOLOAD =~ s/.*://; |