… | |
… | |
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)([^_])/$1\_$2/i; |
|
|
105 | 1 while s/([^_])(SVK|CHK|URI)/$1\_$2/i; |
104 | s/(?<=[a-z])(?=[A-Z])/_/g; |
106 | s/(?<=[a-z])(?=[A-Z])/_/g; |
105 | lc $_; |
107 | lc $_; |
106 | } |
108 | } |
107 | |
109 | |
108 | # the opposite of hex |
110 | # the opposite of hex |
… | |
… | |
180 | #$meta->{tail} = substr $data, pos $data; |
182 | #$meta->{tail} = substr $data, pos $data; |
181 | |
183 | |
182 | $meta; |
184 | $meta; |
183 | } |
185 | } |
184 | |
186 | |
185 | =item $fcp = new Net::FCP [host => $host][, port => $port] |
187 | =item $fcp = new Net::FCP [host => $host][, port => $port][, progress => \&cb] |
186 | |
188 | |
187 | 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 |
188 | 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>). |
189 | |
191 | |
190 | Connections are virtual because no persistent physical connection is |
192 | Connections are virtual because no persistent physical connection is |
191 | 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 | } |
192 | |
204 | |
193 | =begin comment |
205 | =begin comment |
194 | |
206 | |
195 | However, the existance of the node is checked by executing a |
207 | However, the existance of the node is checked by executing a |
196 | C<ClientHello> transaction. |
208 | C<ClientHello> transaction. |
… | |
… | |
212 | $self; |
224 | $self; |
213 | } |
225 | } |
214 | |
226 | |
215 | sub progress { |
227 | sub progress { |
216 | my ($self, $txn, $type, $attr) = @_; |
228 | my ($self, $txn, $type, $attr) = @_; |
217 | #warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
229 | |
|
|
230 | $self->{progress}->($self, $txn, $type, $attr) |
|
|
231 | if $self->{progress}; |
218 | } |
232 | } |
219 | |
233 | |
220 | =item $txn = $fcp->txn(type => attr => val,...) |
234 | =item $txn = $fcp->txn(type => attr => val,...) |
221 | |
235 | |
222 | The low-level interface to transactions. Don't use it. |
236 | The low-level interface to transactions. Don't use it. |
… | |
… | |
323 | |
337 | |
324 | =item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) |
338 | =item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) |
325 | |
339 | |
326 | =item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
340 | =item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
327 | |
341 | |
328 | Calculcates a CHK, given the metadata and data. C<$cipher> is either |
342 | Calculates a CHK, given the metadata and data. C<$cipher> is either |
329 | C<Rijndael> or C<Twofish>, with the latter being the default. |
343 | C<Rijndael> or C<Twofish>, with the latter being the default. |
330 | |
344 | |
331 | =cut |
345 | =cut |
332 | |
346 | |
333 | $txn->(generate_chk => sub { |
347 | $txn->(generate_chk => sub { |
… | |
… | |
401 | |
415 | |
402 | Fetches a (small, as it should fit into memory) file from |
416 | Fetches a (small, as it should fit into memory) file from |
403 | freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or |
417 | freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or |
404 | C<undef>). |
418 | C<undef>). |
405 | |
419 | |
|
|
420 | The C<$uri> should begin with C<freenet:>, but the scheme is currently |
|
|
421 | added, if missing. |
|
|
422 | |
406 | Due to the overhead, a better method to download big files should be used. |
423 | Due to the overhead, a better method to download big files should be used. |
407 | |
424 | |
408 | my ($meta, $data) = @{ |
425 | my ($meta, $data) = @{ |
409 | $fcp->client_get ( |
426 | $fcp->client_get ( |
410 | "freenet:CHK@hdXaxkwZ9rA8-SidT0AN-bniQlgPAwI,XdCDmBuGsd-ulqbLnZ8v~w" |
427 | "freenet:CHK@hdXaxkwZ9rA8-SidT0AN-bniQlgPAwI,XdCDmBuGsd-ulqbLnZ8v~w" |
… | |
… | |
413 | |
430 | |
414 | =cut |
431 | =cut |
415 | |
432 | |
416 | $txn->(client_get => sub { |
433 | $txn->(client_get => sub { |
417 | my ($self, $uri, $htl, $removelocal) = @_; |
434 | my ($self, $uri, $htl, $removelocal) = @_; |
|
|
435 | |
|
|
436 | $uri =~ s/^freenet://; |
|
|
437 | $uri = "freenet:$uri"; |
418 | |
438 | |
419 | $self->txn (client_get => URI => $uri, hops_to_live => xeh (defined $htl ? $htl : 15), |
439 | $self->txn (client_get => URI => $uri, hops_to_live => xeh (defined $htl ? $htl : 15), |
420 | remove_local_key => $removelocal ? "true" : "false"); |
440 | remove_local_key => $removelocal ? "true" : "false"); |
421 | }); |
441 | }); |
422 | |
442 | |
… | |
… | |
677 | } |
697 | } |
678 | } |
698 | } |
679 | |
699 | |
680 | sub progress { |
700 | sub progress { |
681 | my ($self, $type, $attr) = @_; |
701 | my ($self, $type, $attr) = @_; |
|
|
702 | |
682 | $self->{fcp}->progress ($self, $type, $attr); |
703 | $self->{fcp}->progress ($self, $type, $attr); |
683 | } |
704 | } |
684 | |
705 | |
685 | =item $result = $txn->result |
706 | =item $result = $txn->result |
686 | |
707 | |
… | |
… | |
765 | |
786 | |
766 | # base class for get and put |
787 | # base class for get and put |
767 | |
788 | |
768 | use base Net::FCP::Txn; |
789 | use base Net::FCP::Txn; |
769 | |
790 | |
770 | *rcv_uri_error = \&Net::FCP::Txn::rcv_throw_exception; |
791 | *rcv_uri_error = \&Net::FCP::Txn::rcv_throw_exception; |
771 | *rcv_route_not_found = \&Net::FCP::Txn::rcv_throw_exception; |
792 | *rcv_route_not_found = \&Net::FCP::Txn::rcv_throw_exception; |
772 | |
793 | |
773 | sub rcv_restarted { |
794 | sub rcv_restarted { |
774 | my ($self, $attr, $type) = @_; |
795 | my ($self, $attr, $type) = @_; |
775 | |
796 | |
776 | delete $self->{datalength}; |
797 | delete $self->{datalength}; |
… | |
… | |
909 | =cut |
930 | =cut |
910 | |
931 | |
911 | package Net::FCP::Event::Auto; |
932 | package Net::FCP::Event::Auto; |
912 | |
933 | |
913 | my @models = ( |
934 | my @models = ( |
914 | [Coro => Coro::Event:: ], |
935 | [Coro => Coro::Event::], |
915 | [Event => Event::], |
936 | [Event => Event::], |
916 | [Glib => Glib:: ], |
937 | [Glib => Glib::], |
917 | [Tk => Tk::], |
938 | [Tk => Tk::], |
918 | ); |
939 | ); |
919 | |
940 | |
920 | sub AUTOLOAD { |
941 | sub AUTOLOAD { |
921 | $AUTOLOAD =~ s/.*://; |
942 | $AUTOLOAD =~ s/.*://; |