From: victor Date: Sat, 7 Nov 2009 11:50:50 +0000 (+0000) Subject: twisted binmaps X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=a57eee002038ff62fb75ae33819dcbe50f672a6b;p=swift-upb.git twisted binmaps git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@508 e16421f0-f15b-0410-abcd-98678b794739 --- diff --git a/BUGS b/BUGS index 610a7fa..b86f30f 100644 --- a/BUGS +++ b/BUGS @@ -10,9 +10,10 @@ * 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 diff --git a/bins.cpp b/bins.cpp index cf53054..3be3d68 100644 --- 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< 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 --- 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(); diff --git a/ext/send_control.cpp b/ext/send_control.cpp index 470119d..829bc96 100644 --- a/ext/send_control.cpp +++ b/ext/send_control.cpp @@ -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)); } diff --git a/ext/send_control.h b/ext/send_control.h index 6544215..1f31aaa 100644 --- a/ext/send_control.h +++ b/ext/send_control.h @@ -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 () ; diff --git a/tests/binstest2.cpp b/tests/binstest2.cpp index 9496e8b..d3f7a81 100755 --- a/tests/binstest2.cpp +++ b/tests/binstest2.cpp @@ -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; diff --git a/tests/ledbattest2.cpp b/tests/ledbattest2.cpp index 2dc8b3a..3b97d22 100644 --- a/tests/ledbattest2.cpp +++ b/tests/ledbattest2.cpp @@ -13,7 +13,6 @@ #include "datagram.h" #include "p2tp.h" #include -#include using namespace p2tp; using namespace std; diff --git a/tests/pex_test.sh b/tests/pex_test.sh index 89767ad..ff65406 100755 --- a/tests/pex_test.sh +++ b/tests/pex_test.sh @@ -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