beautification
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Tue, 10 Nov 2009 12:09:54 +0000 (12:09 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Tue, 10 Nov 2009 12:09:54 +0000 (12:09 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@524 e16421f0-f15b-0410-abcd-98678b794739

hashtree.cpp
hashtree.h
sendrecv.cpp
tests/hashtest.cpp
tests/transfertest.cpp

index 55586ac..ca752cb 100644 (file)
@@ -148,13 +148,13 @@ void            HashTree::RecoverProgress () {
     char zeros[1<<10];
     memset(zeros, 0, 1<<10);
     Sha1Hash kilo_zero(zeros,1<<10);
-    for(int p=0; p<size_kilo(); p++) {
+    for(int p=0; p<packet_size(); p++) {
         char buf[1<<10];
         bin64_t pos(0,p);
         if (hashes_[pos]==Sha1Hash::ZERO)
             continue;
         size_t rd = read(fd_,buf,1<<10);
-        assert(rd==(1<<10) || p==size_kilo()-1);
+        assert(rd==(1<<10) || p==packet_size()-1);
         if (rd==(1<<10) && !memcmp(buf, zeros, rd) && hashes_[pos]!=kilo_zero)
             continue;
         if ( data_recheck_ && !OfferHash(pos, Sha1Hash(buf,rd)) )
index 0f97618..77f4b18 100644 (file)
@@ -88,9 +88,9 @@ public:
     const Sha1Hash& hash (bin64_t pos) const {return hashes_[pos];}
     const Sha1Hash& root_hash () const { return root_hash_; }
     uint64_t        size () const { return size_; }
-    uint64_t        size_kilo () const { return sizek_; }
+    uint64_t        packet_size () const { return sizek_; }
     uint64_t        complete () const { return complete_; }
-    uint64_t        complete_kilo () const { return completek_; }
+    uint64_t        packets_complete () const { return completek_; }
     uint64_t        seq_complete () ;
     bool            is_complete () 
         { return size_ && complete_==size_; }
index 811167c..8545074 100644 (file)
@@ -320,7 +320,7 @@ bin64_t Channel::OnData (Datagram& dgram) {
 
 void   Channel::OnAck (Datagram& dgram) {
        bin64_t ackd_pos = dgram.Pull32();
-    if (file().size() && ackd_pos.base_offset()>file().size_kilo()) {
+    if (file().size() && ackd_pos.base_offset()>=file().packet_size()) {
         eprintf("invalid ack: (%i,%lli)\n",ackd_pos.layer(),ackd_pos.offset());
         return;
     }
index d0812e6..3b24fc9 100644 (file)
@@ -30,7 +30,7 @@ TEST(Sha1HashTest,OfferDataTest) {
     EXPECT_STREQ(rooth123,roothash123.hex().c_str());
        HashTree tree("123",roothash123);
     tree.OfferHash(bin64_t(0,0),Sha1Hash(true,hash123));
-       ASSERT_EQ(1,tree.size_kilo());
+       ASSERT_EQ(1,tree.packet_size());
     ASSERT_TRUE(tree.OfferData(bin64_t(0,0), "123\n", 4));
     unlink("123");
        ASSERT_EQ(4,tree.size());
index 89ce3b4..521445e 100644 (file)
@@ -44,7 +44,7 @@ TEST(TransferTest,TransferFile) {
     EXPECT_TRUE(E==seed->peak_hash(1));
     EXPECT_TRUE(ROOT==seed->root_hash());
     EXPECT_EQ(4100,seed->size());
-    EXPECT_EQ(5,seed->size_kilo());
+    EXPECT_EQ(5,seed->packet_size());
     EXPECT_EQ(4100,seed->complete());
     EXPECT_EQ(4100,seed->seq_complete());
     EXPECT_EQ(bin64_t(2,0),seed->peak(0));
@@ -59,7 +59,7 @@ TEST(TransferTest,TransferFile) {
     for(int i=0; i<seed->peak_count(); i++)
         leech->OfferHash(seed->peak(i),seed->peak_hash(i));
     ASSERT_EQ(5<<10,leech->size());
-    ASSERT_EQ(5,leech->size_kilo());
+    ASSERT_EQ(5,leech->packet_size());
     ASSERT_EQ(0,leech->complete());
     EXPECT_EQ(bin64_t(2,0),leech->peak(0));
     // transfer data and hashes
@@ -75,7 +75,7 @@ TEST(TransferTest,TransferFile) {
             leech_transfer = new FileTransfer("copy",seed->root_hash());
             leech = & leech_transfer->file();
             leech_transfer->picker().Randomize(0);
-            EXPECT_EQ(2,leech->complete_kilo());
+            EXPECT_EQ(2,leech->packets_complete());
             EXPECT_EQ(bin64_t(2,0),leech->peak(0));
         }
         bin64_t next = leech_transfer->picker().Pick(seed->ack_out(),0);
@@ -84,7 +84,7 @@ TEST(TransferTest,TransferFile) {
         uint8_t buf[1024];         //size_t len = seed->storer->ReadData(next,&buf);
         size_t len = pread(seed->file_descriptor(),buf,1024,next.base_offset()<<10);
         bin64_t sibling = next.sibling();
-        if (sibling.base_offset()<seed->size_kilo())
+        if (sibling.base_offset()<seed->packet_size())
             leech->OfferHash(sibling, seed->hash(sibling));
         uint8_t memo = *buf;
         *buf = 'z';
@@ -93,7 +93,7 @@ TEST(TransferTest,TransferFile) {
         EXPECT_TRUE(leech->OfferData(next, (char*)buf, len));
     }
     EXPECT_EQ(4100,leech->size());
-    EXPECT_EQ(5,leech->size_kilo());
+    EXPECT_EQ(5,leech->packet_size());
     EXPECT_EQ(4100,leech->complete());
     EXPECT_EQ(4100,leech->seq_complete());