From 9a20d7c5e03bb59ecfaf3a980de39a7d4a88b2a4 Mon Sep 17 00:00:00 2001 From: Joshua Roys Date: Mon, 18 Aug 2008 11:11:19 -0400 Subject: [PATCH] The 'Blocks' message now saves the commit bits, does not immediately reply --- lib/VCS/Git/Torrent/PWP/Message/Blocks.pm | 25 ++++++++++++++++++++----- t/55-pwp-reels.t | 5 ++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/VCS/Git/Torrent/PWP/Message/Blocks.pm b/lib/VCS/Git/Torrent/PWP/Message/Blocks.pm index 5f1feeb..580ae19 100644 --- a/lib/VCS/Git/Torrent/PWP/Message/Blocks.pm +++ b/lib/VCS/Git/Torrent/PWP/Message/Blocks.pm @@ -94,13 +94,28 @@ sub action { my ($start, $end) = @{ $self->reel_sha1_pair }; if ( $self->bits ) { - # HACK - for(my $i = 0; $i < $self->num_bits; $i++) { - $local_peer->send_message( - $connection->remote, GTP_PWP_PLAY, - $start, $end, $i + my $reel; + + foreach( @{ $connection->remote->reels } ) { + $reel = $_; + + last if ( + $reel->reel_id->[0] eq $start && + $reel->reel_id->[1] eq $end ); } + + if ( $reel ) { + my @commit_info = (); + + for(my $i = 0; $i < $self->num_bits; $i++) { + push @commit_info, { + in_repo => vec($self->bits, $i, 1), + }; + } + + $reel->commit_info(\@commit_info); + } } else { my $reel; diff --git a/t/55-pwp-reels.t b/t/55-pwp-reels.t index 0c54dbc..d3fa231 100644 --- a/t/55-pwp-reels.t +++ b/t/55-pwp-reels.t @@ -93,5 +93,8 @@ my $reel_2 = $peer_2->torrent->reels->[0]; $peer_2->send_message($victim, GTP_PWP_BLOCKS, $reel_2); -Coro::Event::loop(10); +Coro::Event::loop(1); + +my $bits = @{ $peer_2->connections->[0]->remote->reels->[0]->commit_info }; +is($bits, 71, 'received 71 commit bits'); -- 2.11.4.GIT