AnyEvent-FCP

 view release on metacpan or  search on metacpan

FCP.pm  view on Meta::CPAN


=head2 EXAMPLE

This example fetches the download list and sets the priority of all files
with "a" in their name to "emergency":

   use AnyEvent::FCP;

   my $fcp = new AnyEvent::FCP;

   $fcp->watch_global (1, 0);
   my $req = $fcp->list_persistent_requests;

TODO
   for my $req (values %$req) {
      if ($req->{filename} =~ /a/) {
         $fcp->modify_persistent_request (1, $req->{identifier}, undef, 0);
      }
   }

=head2 IMPORT TAGS

FCP.pm  view on Meta::CPAN

      node_identifier => $node_identifier,
      id_cb           => sub {
         my ($self, $type, $kv, $rdata) = @_;

         $ok->($kv);
         1
      },
   );
};

=item $fcp->watch_global ($enabled[, $verbosity_mask])

=cut

_txn watch_global => sub {
   my ($self, $ok, $err, $enabled, $verbosity_mask) = @_;

   $self->send_msg (watch_global =>
      enabled        => $enabled ? "true" : "false",
      defined $verbosity_mask ? (verbosity_mask => $verbosity_mask+0) : (),
   );

   $ok->();
};

=item $reqs = $fcp->list_persistent_requests

=cut

FCP.pm  view on Meta::CPAN

            if ($type =~ /^persistent_(get|put|put_dir)$/) {
               push @res, [$type, $kv];
            }
         }

         1
      });
   });
};

=item $sync = $fcp->modify_persistent_request ($global, $identifier[, $client_token[, $priority_class]])

Update either the C<client_token> or C<priority_class> of a request
identified by C<$global> and C<$identifier>, depending on which of
C<$client_token> and C<$priority_class> are not C<undef>.

=cut

_txn modify_persistent_request => sub {
   my ($self, $ok, $err, $global, $identifier, $client_token, $priority_class) = @_;

   $self->serialise ($identifier => sub {
      my ($self, $guard) = @_;

      $self->send_msg (modify_persistent_request =>
         global     => $global ? "true" : "false",
         identifier => $identifier,
         defined $client_token   ? (client_token   => $client_token  ) : (),
         defined $priority_class ? (priority_class => $priority_class) : (),
      );

      $self->on (sub {
         my ($self, $type, $kv, @extra) = @_;

         $guard if 0;

FCP.pm  view on Meta::CPAN


      1
   });
};

=item $status = $fcp->client_get ($uri, $identifier, %kv)

%kv can contain (L<http://wiki.freenetproject.org/FCP2p0ClientGet>).

ignore_ds, ds_only, verbosity, max_size, max_temp_size, max_retries,
priority_class, persistence, client_token, global, return_type,
binary_blob, allowed_mime_types, filename, temp_filename

=cut

_txn client_get => sub {
   my ($self, $ok, $err, $uri, $identifier, %kv) = @_;

   $self->serialise ($identifier => sub {
      my ($self, $guard) = @_;

FCP.pm  view on Meta::CPAN

               $err->($kv);
               return;
            }
         }

         1
      });
   });
};

=item $status = $fcp->remove_request ($identifier[, $global])

Remove the request with the given isdentifier. Returns true if successful,
false on error.

=cut

_txn remove_request => sub {
   my ($self, $ok, $err, $identifier, $global) = @_;

   $self->serialise ($identifier => sub {
      my ($self, $guard) = @_;

      $self->send_msg (remove_request =>
         identifier => $identifier,
         global     => $global ? "true" : "false",
      );
      $self->on (sub {
         my ($self, $type, $kv, @extra) = @_;

         $guard if 0;

         if ($kv->{identifier} eq $identifier) {
            if ($type eq "persistent_request_removed") {
               $ok->(1);
               return;

FCP.pm  view on Meta::CPAN

   expected_mime          # get
   expected_data_length   # get
   get_failed             # get
   data_found             # get
   enter_finite_cooldown  # get

In addition, an event (basically a fake message) of type C<request_changed> is generated
on every change, which will be called as C<< $cb->($fcp, $kv, $type) >>, where C<$type>
is the type of the original message triggering the change,

To fill this cache with the global queue and keep it updated,
call C<watch_global> to subscribe to updates, followed by
C<list_persistent_requests_sync>.

   $fcp->watch_global_sync_; # do not wait
   $fcp->list_persistent_requests; # wait

To get a better idea of what is stored in the cache, here is an example of
what might be stored in C<< $fcp->{req}{"Frost-gpl.txt"} >>:

   {
      identifier     => "Frost-gpl.txt",
      uri            => 'CHK@Fnx5kzdrfE,EImdzaVyEWl,AAIC--8/gpl.txt',
      binary_blob    => "false",
      global         => "true",
      max_retries    => -1,
      max_size       => 9223372036854775807,
      persistence    => "forever",
      priority_class => 3,
      real_time      => "false",
      return_type    => "direct",
      started        => "true",
      type           => "persistent_get",
      verbosity      => 2147483647,
      sending_to_network => {
         identifier => "Frost-gpl.txt",
         global     => "true",
      },
      compatibility_mode => {
         identifier    => "Frost-gpl.txt",
         definitive    => "true",
         dont_compress => "false",
         global        => "true",
         max           => "COMPAT_1255",
         min           => "COMPAT_1255",
      },
      expected_hashes    => {
         identifier => "Frost-gpl.txt",
         global     => "true",
         hashes     => {
            ed2k   => "d83596f5ee3b7...",
            md5    => "e0894e4a2a6...",
            sha1   => "...",
            sha256 => "...",
            sha512 => "...",
            tth    => "...",
         },
      },
      expected_mime      => {
         identifier      => "Frost-gpl.txt",
         global          => "true",
         metadata        => { content_type => "application/rar" },
      },
      expected_data_length => {
         identifier      => "Frost-gpl.txt",
         data_length     => 37576,
         global          => "true",
      },
      simple_progress    => {
         identifier      => "Frost-gpl.txt",
         failed          => 0,
         fatally_failed  => 0,
         finalized_total => "true",
         global          => "true",
         last_progress   => 1438639282628,
         required        => 372,
         succeeded       => 102,
         total           => 747,
      },
      data_found           => {
         identifier      => "Frost-gpl.txt",
         completion_time => 1438663354026,
         data_length     => 37576,
         global          => "true",
         metadata        => { content_type => "image/jpeg" },
         startup_time    => 1438657196167,
      },
   }

=head1 EXAMPLE PROGRAM

   use AnyEvent::FCP;

   my $fcp = new AnyEvent::FCP;

   # let us look at the global request list
   $fcp->watch_global_ (1);

   # list them, synchronously
   my $req = $fcp->list_persistent_requests;

   # go through all requests
TODO
   for my $req (values %$req) {
      # skip jobs not directly-to-disk
      next unless $req->{return_type} eq "disk";
      # skip jobs not issued by FProxy

README  view on Meta::CPAN

    example program later in this section.

  EXAMPLE
    This example fetches the download list and sets the priority of all
    files with "a" in their name to "emergency":

       use AnyEvent::FCP;

       my $fcp = new AnyEvent::FCP;

       $fcp->watch_global (1, 0);
       my $req = $fcp->list_persistent_requests;

    TODO for my $req (values %$req) { if ($req->{filename} =~ /a/) {
    $fcp->modify_persistent_request (1, $req->{identifier}, undef, 0); } }

  IMPORT TAGS
    Nothing much can be "imported" from this module right now.

THE AnyEvent::FCP CLASS
    $fcp = new AnyEvent::FCP key => value...;

README  view on Meta::CPAN

    "undef"
        This is the same thing as specifying "sub { }" as callback, i.e. on
        success, the results are ignored, while on failure, the "on_failure"
        hook is invoked or the module dies with a backtrace.

        This is good for quick scripts, or when you really aren't interested
        in the results.

    $peers = $fcp->list_peers ([$with_metdata[, $with_volatile]])
    $notes = $fcp->list_peer_notes ($node_identifier)
    $fcp->watch_global ($enabled[, $verbosity_mask])
    $reqs = $fcp->list_persistent_requests
    $sync = $fcp->modify_persistent_request ($global, $identifier[,
    $client_token[, $priority_class]])
        Update either the "client_token" or "priority_class" of a request
        identified by $global and $identifier, depending on which of
        $client_token and $priority_class are not "undef".

    $info = $fcp->get_plugin_info ($name, $detailed)
    $status = $fcp->client_get ($uri, $identifier, %kv)
        %kv can contain (<http://wiki.freenetproject.org/FCP2p0ClientGet>).

        ignore_ds, ds_only, verbosity, max_size, max_temp_size, max_retries,
        priority_class, persistence, client_token, global, return_type,
        binary_blob, allowed_mime_types, filename, temp_filename

    $status = $fcp->remove_request ($identifier[, $global])
        Remove the request with the given isdentifier. Returns true if
        successful, false on error.

    ($can_read, $can_write) = $fcp->test_dda ($local_directory,
    $remote_directory, $want_read, $want_write))
        The DDA test in FCP is probably the single most broken protocol -
        only one directory test can be outstanding at any time, and some
        guessing and heuristics are involved in mangling the paths.

        This function combines "TestDDARequest" and "TestDDAResponse" in one

README  view on Meta::CPAN

       expected_data_length   # get
       get_failed             # get
       data_found             # get
       enter_finite_cooldown  # get

    In addition, an event (basically a fake message) of type
    "request_changed" is generated on every change, which will be called as
    "$cb->($fcp, $kv, $type)", where $type is the type of the original
    message triggering the change,

    To fill this cache with the global queue and keep it updated, call
    "watch_global" to subscribe to updates, followed by
    "list_persistent_requests_sync".

       $fcp->watch_global_sync_; # do not wait
       $fcp->list_persistent_requests; # wait

    To get a better idea of what is stored in the cache, here is an example
    of what might be stored in "$fcp->{req}{"Frost-gpl.txt"}":

       {
          identifier     => "Frost-gpl.txt",
          uri            => 'CHK@Fnx5kzdrfE,EImdzaVyEWl,AAIC--8/gpl.txt',
          binary_blob    => "false",
          global         => "true",
          max_retries    => -1,
          max_size       => 9223372036854775807,
          persistence    => "forever",
          priority_class => 3,
          real_time      => "false",
          return_type    => "direct",
          started        => "true",
          type           => "persistent_get",
          verbosity      => 2147483647,
          sending_to_network => {
             identifier => "Frost-gpl.txt",
             global     => "true",
          },
          compatibility_mode => {
             identifier    => "Frost-gpl.txt",
             definitive    => "true",
             dont_compress => "false",
             global        => "true",
             max           => "COMPAT_1255",
             min           => "COMPAT_1255",
          },
          expected_hashes    => {
             identifier => "Frost-gpl.txt",
             global     => "true",
             hashes     => {
                ed2k   => "d83596f5ee3b7...",
                md5    => "e0894e4a2a6...",
                sha1   => "...",
                sha256 => "...",
                sha512 => "...",
                tth    => "...",
             },
          },
          expected_mime      => {
             identifier      => "Frost-gpl.txt",
             global          => "true",
             metadata        => { content_type => "application/rar" },
          },
          expected_data_length => {
             identifier      => "Frost-gpl.txt",
             data_length     => 37576,
             global          => "true",
          },
          simple_progress    => {
             identifier      => "Frost-gpl.txt",
             failed          => 0,
             fatally_failed  => 0,
             finalized_total => "true",
             global          => "true",
             last_progress   => 1438639282628,
             required        => 372,
             succeeded       => 102,
             total           => 747,
          },
          data_found           => {
             identifier      => "Frost-gpl.txt",
             completion_time => 1438663354026,
             data_length     => 37576,
             global          => "true",
             metadata        => { content_type => "image/jpeg" },
             startup_time    => 1438657196167,
          },
       }

EXAMPLE PROGRAM
       use AnyEvent::FCP;

       my $fcp = new AnyEvent::FCP;

       # let us look at the global request list
       $fcp->watch_global_ (1);

       # list them, synchronously
       my $req = $fcp->list_persistent_requests;

       # go through all requests
    TODO
       for my $req (values %$req) {
          # skip jobs not directly-to-disk
          next unless $req->{return_type} eq "disk";
          # skip jobs not issued by FProxy

eg/f7progress  view on Meta::CPAN

      $updater ||= AE::idle \&updater;
   } elsif ($type !~ /^(?:sending_to_network|persistent_get|persistent_request_modified)$/) {
      my $line = sprintf "%s %-25.25s %-40.40s %-80.80s",
                         (POSIX::strftime "%H:%M:%S", localtime AE::now),
                         $type, $id, join " ", %$kv;
      push @log, $line;
      $updater ||= AE::idle \&updater;
   }
};

$fcp->watch_global (1, 0);

AE::cv->recv;



( run in 0.662 second using v1.01-cache-2.11-cpan-49f99fa48dc )