AnyEvent-BitTorrent
view release on metacpan or search on metacpan
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
1337;
=pod
=head1 NAME
AnyEvent::BitTorrent - Yet Another BitTorrent Client Module
=head1 Synopsis
use AnyEvent::BitTorrent;
my $client = AnyEvent::BitTorrent->new( path => 'some.torrent' );
AE::cv->recv;
=head1 Description
This is a painfully simple BitTorrent client written on a whim that implements
the absolute basics. For a full list of what's currently supported, what you
will likely find in a future version, and what you'll never get from this, see
the section entitled "L<This Module is Lame!|/"This Module is Lame!">"
=head1 Methods
The API, much like the module itself, is simple.
Anything you find by skimming the source is likely not ready for public use
and will be subject to change before C<v1.0.0>. Here's the public interface as
of this version:
=head2 C<new( ... )>
my $c = AnyEvent::BitTorrent->new(
path => 'some/legal.torrent',
basedir => './storage/',
port => 6881,
on_hash_pass => sub { ... },
on_hash_fail => sub { ... },
state => 'stopped',
piece_cache => $quick_restore
);
This constructor understands the following arguments:
=over
=item C<path>
This is the only required parameter. It's the path to a valid .torrent file.
=item C<basedir>
This is the base directory all data will be stored in and/or read from.
Multifile torrents will create another directory below this to store all
files.
By default, this is the current working directory when
L<C<new( ... )>|/"new( ... )"> is called.
=item C<port>
This is the preferred port local host binds and expects incoming peers to
connect to.
By default, this is a zero; the system will pick a port number randomly.
=item C<on_hash_fail>
This is a subroutine called whenever a piece fails to pass
L<hashcheck|/"hashcheck( [...] )">. The callback is handed the piece's index.
=item C<on_hash_pass>
This is a subroutine called whenever a piece passes its
L<hashcheck|/"hashcheck( [...] )">. The callback is handed the piece's index.
=item C<state>
This must be one of the following:
=over
=item C<started>
This is the default. The client will attempt to create new connections, make
and fill requests, etc. This is normal client behavior.
=item C<paused>
In this state, connections will be made and accepted but no piece requests
will be made or filled. To resume full, normal behavior, you must call
L<C<start( )>|/"start( )">.
=item C<stopped>
Everything is put on hold. No new outgoing connections are attempted and
incoming connections are rejected. To resume full, normal behavior, you must
call L<C<start( )>|/"start( )">.
=back
=item C<piece_cache>
This is the index list returned by L<C<piece_cache( )>|/"piece_cache( )"> in a
previous instance. Using this should make a complete resume system a trivial
task.
=back
=head2 C<hashcheck( [...] )>
This method expects...
=over
=item ...a list of integers. You could use this to check a range of pieces (a
single file, for example).
$client->hashcheck( 1 .. 5, 34 .. 56 );
=item ...a single integer. Only that specific piece is checked.
( run in 1.211 second using v1.01-cache-2.11-cpan-2398b32b56e )