… | |
… | |
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) = @_; |
218 | #warn "progress<$txn,$type," . (join ":", %$attr) . ">\n"; |
229 | |
|
|
230 | $self->{progress}->($self, $txn, $type, $attr) |
|
|
231 | if $self->{progress}; |
219 | } |
232 | } |
220 | |
233 | |
221 | =item $txn = $fcp->txn(type => attr => val,...) |
234 | =item $txn = $fcp->txn(type => attr => val,...) |
222 | |
235 | |
223 | The low-level interface to transactions. Don't use it. |
236 | The low-level interface to transactions. Don't use it. |
… | |
… | |
324 | |
337 | |
325 | =item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) |
338 | =item $txn = $fcp->txn_generate_chk ($metadata, $data[, $cipher]) |
326 | |
339 | |
327 | =item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
340 | =item $uri = $fcp->generate_chk ($metadata, $data[, $cipher]) |
328 | |
341 | |
329 | 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 |
330 | C<Rijndael> or C<Twofish>, with the latter being the default. |
343 | C<Rijndael> or C<Twofish>, with the latter being the default. |
331 | |
344 | |
332 | =cut |
345 | =cut |
333 | |
346 | |
334 | $txn->(generate_chk => sub { |
347 | $txn->(generate_chk => sub { |
… | |
… | |
401 | =item ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
414 | =item ($metadata, $data) = @{ $fcp->client_get ($uri, $htl, $removelocal) |
402 | |
415 | |
403 | Fetches a (small, as it should fit into memory) file from |
416 | 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 |
417 | freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or |
405 | C<undef>). |
418 | C<undef>). |
|
|
419 | |
|
|
420 | The C<$uri> should begin with C<freenet:>, but the scheme is currently |
|
|
421 | added, if missing. |
406 | |
422 | |
407 | 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. |
408 | |
424 | |
409 | my ($meta, $data) = @{ |
425 | my ($meta, $data) = @{ |
410 | $fcp->client_get ( |
426 | $fcp->client_get ( |
… | |
… | |
681 | } |
697 | } |
682 | } |
698 | } |
683 | |
699 | |
684 | sub progress { |
700 | sub progress { |
685 | my ($self, $type, $attr) = @_; |
701 | my ($self, $type, $attr) = @_; |
|
|
702 | |
686 | $self->{fcp}->progress ($self, $type, $attr); |
703 | $self->{fcp}->progress ($self, $type, $attr); |
687 | } |
704 | } |
688 | |
705 | |
689 | =item $result = $txn->result |
706 | =item $result = $txn->result |
690 | |
707 | |
… | |
… | |
769 | |
786 | |
770 | # base class for get and put |
787 | # base class for get and put |
771 | |
788 | |
772 | use base Net::FCP::Txn; |
789 | use base Net::FCP::Txn; |
773 | |
790 | |
774 | *rcv_uri_error = \&Net::FCP::Txn::rcv_throw_exception; |
791 | *rcv_uri_error = \&Net::FCP::Txn::rcv_throw_exception; |
775 | *rcv_route_not_found = \&Net::FCP::Txn::rcv_throw_exception; |
792 | *rcv_route_not_found = \&Net::FCP::Txn::rcv_throw_exception; |
776 | |
793 | |
777 | sub rcv_restarted { |
794 | sub rcv_restarted { |
778 | my ($self, $attr, $type) = @_; |
795 | my ($self, $attr, $type) = @_; |
779 | |
796 | |
780 | delete $self->{datalength}; |
797 | delete $self->{datalength}; |
… | |
… | |
913 | =cut |
930 | =cut |
914 | |
931 | |
915 | package Net::FCP::Event::Auto; |
932 | package Net::FCP::Event::Auto; |
916 | |
933 | |
917 | my @models = ( |
934 | my @models = ( |
918 | [Coro => Coro::Event:: ], |
935 | [Coro => Coro::Event::], |
919 | [Event => Event::], |
936 | [Event => Event::], |
920 | [Glib => Glib:: ], |
937 | [Glib => Glib::], |
921 | [Tk => Tk::], |
938 | [Tk => Tk::], |
922 | ); |
939 | ); |
923 | |
940 | |
924 | sub AUTOLOAD { |
941 | sub AUTOLOAD { |
925 | $AUTOLOAD =~ s/.*://; |
942 | $AUTOLOAD =~ s/.*://; |