AnyEvent-BitTorrent
view release on metacpan or search on metacpan
## `size( )`
Returns the total size of all [files](#files) described in the torrent's
metadata.
## `name( )`
Returns the UTF-8 encoded string the metadata suggests we save the file (or
directory, in the case of multi-file torrents) under.
## `uploaded( )`
Returns the total amount uploaded to remote peers.
## `downloaded( )`
Returns the total amount downloaded from other peers.
## `left( )`
Returns the approximate amount based on the pieces we still
[want](#wanted) multiplied by the [size of pieces](#piece_length).
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
sub _left {
my $s = shift;
$s->piece_length * scalar grep {$_} split '',
substr unpack('b*', $s->wanted), 0, $s->piece_count + 1;
}
has $_ => (is => 'ro',
isa => Int,
default => sub {0},
writer => '_set_' . $_
) for qw[uploaded downloaded];
has infohash => (is => 'ro',
lazy => 1,
builder => '_build_infohash',
isa => $INFOHASH,
init_arg => undef
);
sub _build_infohash { sha1(bencode(shift->metadata->{info})) }
has metadata => (is => 'ro',
lazy_build => 1,
builder => '_build_metadata',
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
return if $tier->{urls}[0] !~ m[^https?://.+];
local $AnyEvent::HTTP::USERAGENT
= 'AnyEvent::BitTorrent/' . $AnyEvent::BitTorrent::VERSION;
my $_url = $tier->{urls}[0] . '?info_hash=' . sub {
local $_ = shift;
s/([^A-Za-z0-9])/sprintf("%%%2.2X", ord($1))/ge;
$_;
}
->($s->infohash)
. ('&peer_id=' . $s->peerid)
. ('&uploaded=' . $s->uploaded)
. ('&downloaded=' . $s->downloaded)
. ('&left=' . $s->_left)
. ('&port=' . $s->port)
. '&compact=1'
. ($e ? '&event=' . $e : '');
AE::log debug => 'Announce URL: ' . $_url;
http_get $_url, sub {
my ($body, $hdr) = @_;
AE::log trace => sub {
require Data::Dump;
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
my $s = shift;
AE::timer(
15, 45,
sub {
return if $s->state ne 'active';
AE::log trace => 'Choke timer...';
my @interested
= grep { $_->{remote_interested} && $_->{remote_choked} }
values %{$s->peers};
# XXX - Limit the number of upload slots
for my $p (@interested) {
$p->{remote_choked} = 0;
$s->_send_encrypted($p->{handle}, build_unchoke());
AE::log trace => 'Choked %s', $p->{peerid};
}
# XXX - Send choke to random peer
}
);
}
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
$s->_send_encrypted(
$p->{handle},
build_piece(
$req->[0], $req->[1],
$s->_read($req->[0], $req->[1], $req->[2])
)
);
$total_sent += $req->[2];
}
}
$s->_set_uploaded($s->uploaded + $total_sent);
}
);
}
);
has _peer_timer => (is => 'ro',
lazy => 1,
isa => Ref,
init_arg => undef,
clearer => '_clear_peer_timer',
builder => '_build_peer_timer'
lib/AnyEvent/BitTorrent.pm view on Meta::CPAN
=head2 C<size( )>
Returns the total size of all L<files|/"files( )"> described in the torrent's
metadata.
=head2 C<name( )>
Returns the UTF-8 encoded string the metadata suggests we save the file (or
directory, in the case of multi-file torrents) under.
=head2 C<uploaded( )>
Returns the total amount uploaded to remote peers.
=head2 C<downloaded( )>
Returns the total amount downloaded from other peers.
=head2 C<left( )>
Returns the approximate amount based on the pieces we still
L<want|/"wanted( )"> multiplied by the L<size of pieces|/"piece_length( )">.
name = "AnyEvent-BitTorrent"
badges = ["travis"]
module_maker="ModuleBuildTiny"
license="artistic_2"
[release]
pause_config = "C:/Strawberry/pause.upload"
[ReleaseTest]
MinimumVersion = false
t/800_utils/Tracker/HTTP.pm view on Meta::CPAN
pack('B*', $args{'peer_id'});
$s->peers->{$_id} = {
address => [$args{'ip'} // $ip, $args{'port'} // $port],
downloaded => $args{'downloaded'},
event => $event,
info_hash => $info_hash,
key => $args{'key'} // $_id,
left => $args{'left'},
peer_id => $args{'peer_id'},
tracker_id => $tracker_id,
uploaded => $args{'uploaded'},
touch => time
};
$status = '200 Alright';
my $num_peers = 0;
my @peers = grep {
$_->{'info_hash'} eq $info_hash
&& $num_peers++ < $max_peers
} values %{$s->peers};
$body = {
complete => $s->complete,
( run in 2.432 seconds using v1.01-cache-2.11-cpan-b16cb0d3907 )