ACK/HAVE works locally
authorVictor Grishchenko <victor.grishchenko@gmail.com>
Fri, 26 Feb 2010 15:52:16 +0000 (16:52 +0100)
committerVictor Grishchenko <victor.grishchenko@gmail.com>
Fri, 26 Feb 2010 15:52:16 +0000 (16:52 +0100)
sendrecv.cpp
swift.h
tests/connecttest.cpp

index e357a02..bfe1ee7 100644 (file)
@@ -102,8 +102,8 @@ void    Channel::AddHandshake (Datagram& dgram) {
     int encoded = EncodeID(id_);
     dgram.Push32(encoded);
     dprintf("%s #%u +hs %x\n",tintstr(),id_,encoded);
-    ack_out_.clear();
-    AddAck(dgram);
+    have_out_.clear();
+    AddHave(dgram);
 }
 
 
@@ -224,9 +224,9 @@ void    Channel::AddAck (Datagram& dgram) {
     if (data_in_==tintbin())
         return;
     dgram.Push8(SWIFT_ACK);
-    dgram.Push32(data_in_.bin.to32());
-    dgram.Push32(data_in_.time);
-    ack_out_.set(data_in_.bin);
+    dgram.Push32(data_in_.bin.to32()); // FIXME not cover
+    dgram.Push64(data_in_.time); // FIXME 32
+    have_out_.set(data_in_.bin);
     dprintf("%s #%u +ack %s %s\n",
         tintstr(),id_,data_in_.bin.str(),tintstr(data_in_.time));
     if (data_in_.bin.layer()>2)
@@ -243,11 +243,11 @@ void    Channel::AddHave (Datagram& dgram) {
     }
     for(int count=0; count<4; count++) {
         bin64_t ack = file().ack_out().find_filtered // FIXME: do rotating queue
-            (ack_out_, bin64_t::ALL, binmap_t::FILLED);
+            (have_out_, bin64_t::ALL, binmap_t::FILLED);
         if (ack==bin64_t::NONE)
             break;
         ack = file().ack_out().cover(ack);
-        ack_out_.set(ack);
+        have_out_.set(ack);
         dgram.Push8(SWIFT_HAVE);
         dgram.Push32(ack.to32());
         dprintf("%s #%u +have %s\n",tintstr(),id_,ack.str());
@@ -338,7 +338,8 @@ bin64_t Channel::OnData (Datagram& dgram) {  // TODO: HAVE NONE for corrupted da
 
 void    Channel::OnAck (Datagram& dgram) {
     bin64_t ackd_pos = dgram.Pull32();
-    tint peer_time_ = dgram.Pull64();
+    tint peer_time_ = dgram.Pull64(); // FIXME 32
+    // FIXME FIXME: wrap around here
     if (ackd_pos==bin64_t::NONE)
         return; // likely, brocken packet / insufficient hashes
     if (file().size() && ackd_pos.base_offset()>=file().packet_size()) {
@@ -355,9 +356,9 @@ void    Channel::OnAck (Datagram& dgram) {
     // rule out retransmits
     while (  ri<data_out_tmo_.size() && !data_out_tmo_[ri].bin.within(ackd_pos) )
         ri++;
-    dprintf("%s #%u %cack %s %s\n",tintstr(),id_,
-            di==data_out_.size()?'?':'-',ackd_pos.str(),tintstr(peer_time_));
-    if (ri==data_out_tmo_.size()) { // not a retransmit
+    dprintf("%s #%u %cack %s %lli\n",tintstr(),id_,
+            di==data_out_.size()?'?':'-',ackd_pos.str(),peer_time_);
+    if (di!=data_out_.size() && ri==data_out_tmo_.size()) { // not a retransmit
             // round trip time calculations
         tint rtt = NOW-data_out_[di].time;
         rtt_avg_ = (rtt_avg_*7 + rtt) >> 3;
diff --git a/swift.h b/swift.h
index df9398f..be996c7 100644 (file)
--- a/swift.h
+++ b/swift.h
@@ -342,7 +342,7 @@ namespace swift {
         tbqueue     data_out_tmo_;
         bin64_t     data_out_cap_;
         /** Index in the history array. */
-        binmap_t        ack_out_;
+        binmap_t        have_out_;
         /**    Transmit schedule: in most cases filled with the peer's hints */
         tbqueue     hint_in_;
         /** Hints sent (to detect and reschedule ignored hints). */
index e49c6c7..20482d6 100644 (file)
@@ -16,7 +16,7 @@
 using namespace swift;
 
 
-TEST(SWIFT,CwndTest) {
+TEST(Connection,CwndTest) {
 
     srand ( time(NULL) );
 
@@ -56,6 +56,7 @@ int main (int argc, char** argv) {
 
        swift::LibraryInit();
        testing::InitGoogleTest(&argc, argv);
+    Channel::debug_file = stdout;
        int ret = RUN_ALL_TESTS();
        return ret;