twisted binmaps
authorvictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Sat, 7 Nov 2009 11:50:50 +0000 (11:50 +0000)
committervictor <victor@e16421f0-f15b-0410-abcd-98678b794739>
Sat, 7 Nov 2009 11:50:50 +0000 (11:50 +0000)
git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@508 e16421f0-f15b-0410-abcd-98678b794739

BUGS
bins.cpp
bins.h
ext/send_control.cpp
ext/send_control.h
tests/binstest2.cpp
tests/ledbattest2.cpp
tests/pex_test.sh

diff --git a/BUGS b/BUGS
index 610a7fa..b86f30f 100644 (file)
--- a/BUGS
+++ b/BUGS
     * git
     * check hints agains ack_out?_
     * check data against ack_in
-    * channel suspend/wake. 3 cong modes state machine - ???
+    v channel suspend/wake. 3 cong modes state machine - ???
     * minimize the number of template instantiations
     * Channel thinks how much it HINTs a second,
       picker thinks which HINTs are snubbed
     * dead Channels are not killed => cannot open a new one
         (have a channel already)
+    * peers don't cooperate
index cf53054..3be3d68 100644 (file)
--- a/bins.cpp
+++ b/bins.cpp
@@ -31,11 +31,16 @@ void bins::extend () {
 }
 
 bins::bins() :  height(4), blocks_allocated(0), cells(NULL), 
-                ap(0), cells_allocated(0) {
+                ap(0), cells_allocated(0), twist_mask(0) {
     extend();
     assert(!alloc_cell());
 }
 
+void bins::twist (uint64_t mask) {
+    assert( (1<<height) > mask );
+    twist_mask = mask;
+}
+
 bins::bins (const bins& b) : height(b.height), ap(b.ap),
 blocks_allocated(b.blocks_allocated), cells_allocated(b.cells_allocated) {
     size_t memsz = blocks_allocated*16*32;
@@ -185,8 +190,9 @@ void iterator::to (bool right) {
         host->split(half);
     history[pos.layer()] = half; // FIXME
     pos = pos.to(right);
+    if ( (host->twist_mask >> pos.layer()) & 1 )
+        right = !right; // twist it!
     half = (host->halves[half]<<1) + right;
-    //host->dump("/\\ ");
 }
 
 
diff --git a/bins.h b/bins.h
index 2f613cc..8fa3f9b 100644 (file)
--- a/bins.h
+++ b/bins.h
@@ -50,6 +50,8 @@ public:
     void        clear ();
     
     static bool is_mixed (uint16_t val) { return val!=EMPTY && val!=FILLED; }
+
+    void        twist (uint64_t mask);
     
 private:
     
@@ -67,6 +69,7 @@ private:
     uint32_t    cells_allocated;
     int         height;
     uint32_t    ap;
+    uint64_t    twist_mask;
     
     void extend();
     
index 470119d..829bc96 100644 (file)
@@ -49,10 +49,15 @@ bool    KeepAliveController::MaySendData() {
 }
     
 tint    KeepAliveController::NextSendTime () {
-    return ch_->last_send_time_ + TINT_SEC*58;
+    if (!delay_)
+        delay_ = ch_->rtt_avg_;
+    return ch_->last_send_time_ + delay_;
 }
     
 void    KeepAliveController::OnDataSent(bin64_t b) {
+    delay_ *= 2;
+    if (delay_>TINT_SEC*58)
+        delay_ = TINT_SEC*58;
     if (b!=bin64_t::ALL)
         Swap(new PingPongController(this));
 }
index 6544215..1f31aaa 100644 (file)
@@ -63,8 +63,11 @@ struct PingPongController : public SendController {
 
 
 struct KeepAliveController : public SendController {
+
+    tint delay_;
     
-    KeepAliveController(SendController* prev) : SendController(prev){}
+    KeepAliveController(SendController* prev) : SendController(prev),
+    delay_(0) {}
     const char* type() const { return "KeepAlive"; }
     bool    MaySendData();
     tint    NextSendTime () ;
index 9496e8b..d3f7a81 100755 (executable)
@@ -287,6 +287,19 @@ TEST(BinsTest, Mass) {
     EXPECT_EQ(50<<4,b50.mass());
 }
 
+TEST(BinsTest,Twist) {
+    bins b;
+    b.set(bin64_t(3,2));
+    EXPECT_EQ(bins::FILLED,b.get(bin64_t(3,2)));
+    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(3,3)));
+    b.twist(1<<3);
+    EXPECT_EQ(bins::FILLED,b.get(bin64_t(3,3)));
+    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(3,2)));
+    b.twist(0);
+    EXPECT_EQ(bins::FILLED,b.get(bin64_t(3,2)));
+    EXPECT_EQ(bins::EMPTY,b.get(bin64_t(3,3)));
+}
+
 TEST(BinheapTest,Eat) {
     
     binheap b;
index 2dc8b3a..3b97d22 100644 (file)
@@ -13,7 +13,6 @@
 #include "datagram.h"
 #include "p2tp.h"
 #include <gtest/gtest.h>
-#include <glog/logging.h>
 
 using namespace p2tp;
 using namespace std;
index 89767ad..ff65406 100755 (executable)
@@ -13,7 +13,7 @@ for i in `seq 1 $PEERCOUNT`; do
     ( $EXEC/leecher 282a863d5567695161721686a59f0c667250a35d \
         $STORE/sofi$i.jpg 7001 710$i > $STORE/leecher$i.log ) &
     TOKILL="$TOKILL $!"
-    sleep 1;
+    sleep 4;
 done
 
 sleep 10