From e58865d4e84de78a65281f72e198bc0d56a44104 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 5 Nov 2009 10:51:15 +0000 Subject: [PATCH] cong ctrl in progress git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@499 e16421f0-f15b-0410-abcd-98678b794739 --- datagram.cpp | 4 +++- ext/send_control.cpp | 13 +++++++++---- ext/send_control.h | 2 +- sendrecv.cpp | 15 +++++++++------ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/datagram.cpp b/datagram.cpp index 50ef4d8..3a50a98 100644 --- a/datagram.cpp +++ b/datagram.cpp @@ -26,12 +26,14 @@ uint64_t Datagram::dgrams_up=0, Datagram::dgrams_down=0, Datagram::bytes_up=0, Datagram::bytes_down=0; char* Datagram::TimeStr (tint time) { - static char ret_str[32][4]; // wow + assert(!time || time>=epoch); + static char ret_str[4][32]; // wow static int i; i = (i+1) & 3; if (time==0) time = now; time -= epoch; + assert(time>=0); int hours = time/TINT_HOUR; time %= TINT_HOUR; int mins = time/TINT_MIN; diff --git a/ext/send_control.cpp b/ext/send_control.cpp index 50d569e..62c0f24 100644 --- a/ext/send_control.cpp +++ b/ext/send_control.cpp @@ -38,8 +38,8 @@ void PingPongController::OnDataRecvd(bin64_t b) { } void PingPongController::OnAckRcvd(bin64_t ackd) { - if (ch_->data_out_.empty()) - Swap(new SlowStartController(this)); + //if (ch_->data_out_.empty()) + Swap(new SlowStartController(this)); } @@ -66,14 +66,19 @@ void KeepAliveController::OnAckRcvd(bin64_t ackd) { bool CwndController::MaySendData() { + dprintf("%s #%i maysend %i < %f & %s (rtt %lli)\n",Datagram::TimeStr(), + ch_->id,(int)ch_->data_out_.size(),cwnd_,Datagram::TimeStr(NextSendTime()), + ch_->rtt_avg_); return ch_->data_out_.size() < cwnd_ && Datagram::now >= NextSendTime(); } tint CwndController::NextSendTime () { + tint sendtime; if (ch_->data_out_.size() < cwnd_) - return ch_->last_send_time_ + ch_->rtt_avg_ / cwnd_; + sendtime = ch_->last_send_time_ + (ch_->rtt_avg_ / cwnd_); else - return ch_->last_send_time_ + ch_->rtt_avg_ + ch_->dev_avg_ * 4 ; + sendtime = ch_->last_send_time_ + ch_->rtt_avg_ + ch_->dev_avg_ * 4 ; + return sendtime; } void CwndController::OnDataSent(bin64_t b) { diff --git a/ext/send_control.h b/ext/send_control.h index b8d4a77..f21560f 100644 --- a/ext/send_control.h +++ b/ext/send_control.h @@ -77,7 +77,7 @@ struct KeepAliveController : public SendController { struct CwndController : public SendController { - float cwnd_; + double cwnd_; CwndController(SendController* orig, int cwnd=1) : SendController(orig), cwnd_(cwnd) { } diff --git a/sendrecv.cpp b/sendrecv.cpp index dc17aa9..be91314 100644 --- a/sendrecv.cpp +++ b/sendrecv.cpp @@ -227,6 +227,11 @@ void Channel::AddAck (Datagram& dgram) { 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_; + dprintf("%s #%i rtt init %lli\n",Datagram::TimeStr(),id,rtt_avg_); + } bin64_t data = dgram.size() ? bin64_t::NONE : bin64_t::ALL; while (dgram.size()) { uint8_t type = dgram.Pull8(); @@ -284,18 +289,16 @@ void Channel::OnAck (Datagram& dgram) { dprintf("%s #%i -ack (%i,%lli)\n",Datagram::TimeStr(),id,ackd_pos.layer(),ackd_pos.offset()); for (int i=0; i<8 && i> 2; dev_avg_ = ( dev_avg_*3 + abs(rtt-rtt_avg_) ) >> 2; dprintf("%s #%i rtt %lli dev %lli\n", Datagram::TimeStr(),id,rtt_avg_,dev_avg_); - cc_->OnAckRcvd(x.bin); + cc_->OnAckRcvd(data_out_[i].bin); } - while (data_out_.size() && data_out_.front().bin==bin64_t::ALL) - data_out_.pop_front(); ack_in_.set(ackd_pos); + while (data_out_.size() && ack_in_.get(data_out_.front().bin)==bins::FILLED) + data_out_.pop_front(); } -- 2.20.1