From a1b0c1b49422300c2aca47dae6347caf2301aa3c Mon Sep 17 00:00:00 2001 From: Joshua Roys Date: Mon, 18 Aug 2008 10:52:56 -0400 Subject: [PATCH] Save and read packs based on offset in the commit reel Peers without an index can now send packs they have received so far. --- lib/VCS/Git/Torrent/PWP/Message/Play.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/VCS/Git/Torrent/PWP/Message/Play.pm b/lib/VCS/Git/Torrent/PWP/Message/Play.pm index 0bd20d8..5c8e75e 100644 --- a/lib/VCS/Git/Torrent/PWP/Message/Play.pm +++ b/lib/VCS/Git/Torrent/PWP/Message/Play.pm @@ -113,6 +113,13 @@ sub action { $unpack->execute(); $unpack->wait(); + + my $pack_name = $local_peer->torrent->state_dir . + '/commit-' . $self->offset . '.pack'; + open(PACK, '>', $pack_name) + || die 'failed to save pack file'; + syswrite PACK, $self->data, $self->data_len; + close(PACK); } else { # it was a request for data my $reel; @@ -132,12 +139,19 @@ sub action { my $pack; my $pack_name = $local_peer->torrent->state_dir . '/commit-' . $commit->{'objectid'} . '.pack'; + my $alt_pack_name = $local_peer->torrent->state_dir . + '/commit-' . $self->offset . '.pack'; if ( -e $pack_name ) { open(PACK, '<', $pack_name) || die 'failed to open pack file'; read PACK, $pack, -s $pack_name; close(PACK); + } elsif ( -e $alt_pack_name ) { + open(PACK, '<', $alt_pack_name) + || die 'failed to open pack file'; + read PACK, $pack, -s $alt_pack_name; + close(PACK); } else { my @parents = ( $commit->{'parents'} && -- 2.11.4.GIT