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

Comparing Net-FCP/FCP.pm (file contents):
Revision 1.26 by root, Wed Dec 10 02:36:37 2003 UTC vs.
Revision 1.27 by root, Thu May 13 15:41:01 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) = @_;
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
329Calculcates a CHK, given the metadata and data. C<$cipher> is either 343Calculates a CHK, given the metadata and data. C<$cipher> is either
330C<Rijndael> or C<Twofish>, with the latter being the default. 344C<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
403Fetches a (small, as it should fit into memory) file from 417Fetches a (small, as it should fit into memory) file from
404freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or 418freenet. C<$meta> is the metadata (as returned by C<parse_metadata> or
405C<undef>). 419C<undef>).
420
421The C<$uri> should begin with C<freenet:>, but the scheme is currently
422added, if missing.
406 423
407Due to the overhead, a better method to download big files should be used. 424Due 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
684sub progress { 702sub 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
772use base Net::FCP::Txn; 791use 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
777sub rcv_restarted { 796sub 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
915package Net::FCP::Event::Auto; 934package Net::FCP::Event::Auto;
916 935
917my @models = ( 936my @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
924sub AUTOLOAD { 943sub AUTOLOAD {
925 $AUTOLOAD =~ s/.*://; 944 $AUTOLOAD =~ s/.*://;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines