Skip to content

Commit

Permalink
Handle incoming unchoke packets
Browse files Browse the repository at this point in the history
  • Loading branch information
sanko committed Aug 27, 2010
1 parent e1d0694 commit cdbd46a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/Net/BitTorrent/Protocol/BEP03/Peer.pm
Expand Up @@ -32,6 +32,29 @@
sub _handle_packet_choke { shift->_set_remote_choked }
sub _handle_packet_unchoke { shift->_unset_remote_choked }
sub _handle_packet_interested { shift->_set_remote_interested }
around '_unset_remote_choked' => sub {
my ($c, $s) = @_;
return if $s->_has_quest('request_block');
require Scalar::Util;
Scalar::Util::weaken $s;
my $max_requests = 4; # XXX - max_requests attribute
$s->_add_quest(
'request_block',
AE::timer(
0, 3,
sub {
return if !defined $s;
for (0 .. $max_requests) {
my $piece = $s->torrent->select_piece($s);
next if !$piece;
my $b = $piece->_first_unassigned_block();
next if !$b;
$s->_add_request($b);
}
}
)
);
};

sub _handle_packet_have {
my ($s, $i) = @_;
Expand Down

0 comments on commit cdbd46a

Please sign in to comment.