From: victor Date: Thu, 5 Nov 2009 13:38:12 +0000 (+0000) Subject: +AIMD control X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=76b6ddcdad6186e4067809bbf3f3b70b68d7f588;p=swift-upb.git +AIMD control git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@500 e16421f0-f15b-0410-abcd-98678b794739 --- diff --git a/ext/send_control.cpp b/ext/send_control.cpp index 62c0f24..85d599e 100644 --- a/ext/send_control.cpp +++ b/ext/send_control.cpp @@ -104,9 +104,19 @@ void CwndController::OnAckRcvd(bin64_t ackd) { void SlowStartController::OnAckRcvd (bin64_t pos) { - if (pos!=bin64_t::NONE) + if (pos!=bin64_t::NONE) { cwnd_ += 1; + if (TINT_SEC*cwnd_/ch_->rtt_avg_>=10) + Swap(new AIMDController(this,cwnd_)); + } else + cwnd_ /= 2; +} + + +void AIMDController::OnAckRcvd (bin64_t pos) { + if (pos!=bin64_t::NONE) + cwnd_ += 1.0/cwnd_; else cwnd_ /= 2; } - \ No newline at end of file + diff --git a/ext/send_control.h b/ext/send_control.h index f21560f..6544215 100644 --- a/ext/send_control.h +++ b/ext/send_control.h @@ -99,4 +99,14 @@ struct SlowStartController : public CwndController { }; -#endif \ No newline at end of file + +struct AIMDController : public CwndController { + + AIMDController(SendController* orig, int cwnd=1) : CwndController(orig,cwnd) {} + const char* type() const { return "AIMD"; } + void OnAckRcvd(bin64_t ackd) ; + +}; + + +#endif diff --git a/sendrecv.cpp b/sendrecv.cpp index be91314..2d73dde 100644 --- a/sendrecv.cpp +++ b/sendrecv.cpp @@ -91,8 +91,8 @@ void Channel::AddHandshake (Datagram& dgram) { dgram.Push8(P2TP_HANDSHAKE); dgram.Push32(EncodeID(id)); dprintf("%s #%i +hs\n",Datagram::TimeStr(),id); - AddAck(dgram); ack_out_.clear(); + AddAck(dgram); } @@ -134,20 +134,40 @@ void Channel::Send () { void Channel::AddHint (Datagram& dgram) { - while (!hint_out_.empty() && + while (!hint_out_.empty()) { + tintbin f = hint_out_.front(); + if (f.timebin.width(); - int bps = PeerBPS(); - dprintf("%s #%i hinted %lli peer_bps %i\n",Datagram::TimeStr(),id,hinted,bps); - //float peer_cwnd = cc_->PeerBPS() * cc_->RoundTripTime() / TINT_SEC; - - if ( bps > hinted*1024 ) { //hinted*1024 < peer_cwnd*4 ) { + //int bps = PeerBPS(); + double peer_cwnd = rtt_avg_ / dip_avg_; + if (peer_cwnd<1) + peer_cwnd = 1; + dprintf("%s #%i hinted %lli peer_cwnd %lli/%lli=%f\n", + Datagram::TimeStr(),id,hinted,rtt_avg_,dip_avg_,((float)rtt_avg_/dip_avg_)); + + if ( 4*peer_cwnd > hinted ) { //hinted*1024 < peer_cwnd*4 ) { uint8_t layer = 2; // actually, enough bin64_t hint = file().picker().Pick(ack_in_,layer); @@ -170,8 +190,10 @@ bin64_t Channel::AddData (Datagram& dgram) { if (!file().size()) // know nothing return bin64_t::NONE; bin64_t tosend = DequeueHint(); - if (tosend==bin64_t::NONE) + if (tosend==bin64_t::NONE) { + dprintf("%s #%i out of hints\n",Datagram::TimeStr(),id); return bin64_t::NONE; + } if (ack_in_.is_empty() && file().size()) AddPeakHashes(dgram); AddUncleHashes(dgram,tosend); @@ -230,6 +252,7 @@ void Channel::Recv (Datagram& dgram) { if (last_send_time_ && rtt_avg_==TINT_SEC && dev_avg_==0) { rtt_avg_ = Datagram::now - last_send_time_; dev_avg_ = rtt_avg_; + dip_avg_ = rtt_avg_; dprintf("%s #%i rtt init %lli\n",Datagram::TimeStr(),id,rtt_avg_); } bin64_t data = dgram.size() ? bin64_t::NONE : bin64_t::ALL;