From e9a0cb989936ff1fac2fc4f9cfa910bb0467bdc4 Mon Sep 17 00:00:00 2001 From: victor Date: Fri, 16 Oct 2009 06:43:28 +0000 Subject: [PATCH] right uncle sequence git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@425 e16421f0-f15b-0410-abcd-98678b794739 --- p2tp.h | 69 ++++++++++++++++++++++++++++++------------ tests/transfertest.cpp | 11 ++++--- transfer.cpp | 42 ++++++++++++++----------- 3 files changed, 80 insertions(+), 42 deletions(-) diff --git a/p2tp.h b/p2tp.h index 122a469..94a356c 100644 --- a/p2tp.h +++ b/p2tp.h @@ -58,7 +58,13 @@ Messages namespace p2tp { - typedef std::pair tintbin; + struct tintbin { + tint time; + bin64_t bin; + tintbin(const tintbin& b) : time(b.time), bin(b.bin) {} + tintbin() : time(0), bin(bin64_t::NONE) {} + tintbin(tint time_, bin64_t bin_) : time(time_), bin(bin_) {} + }; typedef std::deque tbqueue; typedef std::deque binqueue; @@ -67,7 +73,7 @@ namespace p2tp { P2TP_HANDSHAKE = 0, P2TP_DATA = 1, P2TP_ACK = 2, - P2TP_ACKTS = 8, + P2TP_ACK_TS = 8, P2TP_HINT = 3, P2TP_HASH = 4, P2TP_PEX_ADD = 5, @@ -99,7 +105,20 @@ namespace p2tp { bool OfferData (bin64_t bin, uint8_t* data, size_t length); static FileTransfer* Find (const Sha1Hash& hash); - static FileTransfer* file (int fd) { return fdOfferHash(bin64_t(1,0), seed->hashes[bin64_t(1,0)]); + // calculated leech->OfferHash(bin64_t(1,0), seed->hashes[bin64_t(1,0)]); leech->OfferHash(bin64_t(1,1), seed->hashes[bin64_t(1,1)]); for (int i=0; i<5; i++) { - if (i==2) { + if (i==2) { // now: stop, save, start delete leech; FileTransfer::instance = 1; leech = new FileTransfer(seed->root_hash,"copy"); EXPECT_EQ(2,leech->completek); - //leech->OfferHash(bin64_t(1,0), seed->hashes[bin64_t(1,0)]); - //leech->OfferHash(bin64_t(1,1), seed->hashes[bin64_t(1,1)]); } bin64_t next = leech->picker->Pick(seed->ack_out,0); ASSERT_NE(bin64_t::NONE,next); @@ -75,6 +73,10 @@ TEST(TransferTest,TransferFile) { size_t len = pread(seed->fd,buf,1024,next.base_offset()<<10); // FIXME TEST FOR ERROR bin64_t sibling = next.sibling(); leech->OfferHash(sibling, seed->hashes[sibling]); // i=4 => out of bounds + uint8_t memo = *buf; + *buf = 'z'; + EXPECT_FALSE(leech->OfferData(next, buf, len)); + *buf = memo; EXPECT_TRUE(leech->OfferData(next, buf, len)); } EXPECT_EQ(4100,leech->size); @@ -86,7 +88,6 @@ TEST(TransferTest,TransferFile) { /* FIXME - always rehashes (even fresh files) - - different heights => bins::remove is buggy */ int main (int argc, char** argv) { diff --git a/transfer.cpp b/transfer.cpp index a260842..8f2e9b8 100644 --- a/transfer.cpp +++ b/transfer.cpp @@ -20,6 +20,7 @@ int FileTransfer::instance = 0; #include "ext/seq_picker.cpp" +// FIXME: separate Bootstrap() and Download(), then Size(), Progress(), SeqProgress() FileTransfer::FileTransfer (const Sha1Hash& _root_hash, const char* filename) : root_hash(_root_hash), fd(0), hashfd(0), dry_run(false), @@ -150,9 +151,14 @@ void FileTransfer::Submit () { void FileTransfer::OfferHash (bin64_t pos, const Sha1Hash& hash) { if (!size) // only peak hashes are accepted at this point return OfferPeak(pos,hash); - if (pos>=sizek*2) - return; - if (ack_out.get(pos)!=bins::EMPTY) + int pi=0; + while (pi