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.23 by root, Wed Sep 17 08:57:32 2003 UTC vs.
Revision 1.28 by root, Thu May 13 16:13:42 2004 UTC

72 72
73package Net::FCP; 73package Net::FCP;
74 74
75use Carp; 75use Carp;
76 76
77$VERSION = 0.5; 77$VERSION = 0.6;
78 78
79no warnings; 79no warnings;
80 80
81our $EVENT = Net::FCP::Event::Auto::; 81our $EVENT = Net::FCP::Event::Auto::;
82 82
99 $_; 99 $_;
100} 100}
101 101
102sub tolc($) { 102sub 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
187Create 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
188127.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>).
189 191
190Connections are virtual because no persistent physical connection is 192Connections are virtual because no persistent physical connection is
191established. 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 }
192 204
193=begin comment 205=begin comment
194 206
195However, the existance of the node is checked by executing a 207However, the existance of the node is checked by executing a
196C<ClientHello> transaction. 208C<ClientHello> transaction.
212 $self; 224 $self;
213} 225}
214 226
215sub progress { 227sub 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
222The low-level interface to transactions. Don't use it. 236The 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
328Calculcates a CHK, given the metadata and data. C<$cipher> is either 342Calculates a CHK, given the metadata and data. C<$cipher> is either
329C<Rijndael> or C<Twofish>, with the latter being the default. 343C<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
402Fetches a (small, as it should fit into memory) file from 416Fetches a (small, as it should fit into memory) file from
403freenet. 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
404C<undef>). 418C<undef>).
405 419
420The C<$uri> should begin with C<freenet:>, but the scheme is currently
421added, if missing.
422
406Due 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.
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
680sub progress { 700sub 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
768use base Net::FCP::Txn; 789use 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
773sub rcv_restarted { 794sub 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
911package Net::FCP::Event::Auto; 932package Net::FCP::Event::Auto;
912 933
913my @models = ( 934my @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
920sub AUTOLOAD { 941sub AUTOLOAD {
921 $AUTOLOAD =~ s/.*://; 942 $AUTOLOAD =~ s/.*://;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines