ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Net-FCP/FCP.pm
(Generate patch)

Comparing cvsroot/Net-FCP/FCP.pm (file contents):
Revision 1.26 by root, Wed Dec 10 02:36:37 2003 UTC vs.
Revision 1.28 by root, Thu May 13 16:13:42 2004 UTC

99 $_; 99 $_;
100} 100}
101 101
102sub tolc($) { 102sub 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
188Create a new virtual FCP connection to the given host and port (default 189Create a new virtual FCP connection to the given host and port (default
189127.0.0.1:8481, or the environment variables C<FREDHOST> and C<FREDPORT>). 190127.0.0.1:8481, or the environment variables C<FREDHOST> and C<FREDPORT>).
190 191
191Connections are virtual because no persistent physical connection is 192Connections are virtual because no persistent physical connection is
192established. 193established.
194
195You can install a progress callback that is being called with the Net::FCP
196object, a txn object, the type of the transaction and the attributes. Use
197it 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
196However, the existance of the node is checked by executing a 207However, the existance of the node is checked by executing a
197C<ClientHello> transaction. 208C<ClientHello> transaction.
213 $self; 224 $self;
214} 225}
215 226
216sub progress { 227sub 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
223The low-level interface to transactions. Don't use it. 236The 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
329Calculcates a CHK, given the metadata and data. C<$cipher> is either 342Calculates a CHK, given the metadata and data. C<$cipher> is either
330C<Rijndael> or C<Twofish>, with the latter being the default. 343C<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
403Fetches a (small, as it should fit into memory) file from 416Fetches a (small, as it should fit into memory) file from
404freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or 417freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or
405C<undef>). 418C<undef>).
419
420The C<$uri> should begin with C<freenet:>, but the scheme is currently
421added, if missing.
406 422
407Due to the overhead, a better method to download big files should be used. 423Due 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
684sub progress { 700sub 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
772use base Net::FCP::Txn; 789use 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
777sub rcv_restarted { 794sub 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
915package Net::FCP::Event::Auto; 932package Net::FCP::Event::Auto;
916 933
917my @models = ( 934my @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
924sub AUTOLOAD { 941sub AUTOLOAD {
925 $AUTOLOAD =~ s/.*://; 942 $AUTOLOAD =~ s/.*://;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines