From: victor Date: Sat, 14 Nov 2009 17:27:21 +0000 (+0000) Subject: ping-pong is back X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=9b1fc23d2460169818e12a128cce244c7f70391d;p=swift-upb.git ping-pong is back git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@554 e16421f0-f15b-0410-abcd-98678b794739 --- diff --git a/ext/send_control.cpp b/ext/send_control.cpp index 256bab9..c622f67 100644 --- a/ext/send_control.cpp +++ b/ext/send_control.cpp @@ -24,6 +24,27 @@ void SendController::Schedule (tint next_time) { ch_->Schedule(next_time); } +bool PingPongController::MaySendData() { + return ch_->data_out_.empty(); +} + +void PingPongController::OnDataSent(bin64_t b) { + Schedule(NOW+ch_->rtt_avg_+std::max(ch_->dev_avg_*4,500*TINT_MSEC)); + if (++sent_>=10) + Swap(new KeepAliveController(this)); + else if (++unanswered_>=3) + Schedule(TINT_NEVER); +} + +void PingPongController::OnDataRecvd(bin64_t b) { + unanswered_ = 0; + Schedule(NOW); // pong +} + +void PingPongController::OnAckRcvd(bin64_t ackd) { + if (ackd!=bin64_t::NONE) + Swap(new SlowStartController(this)); +} KeepAliveController::KeepAliveController (Channel* ch) : SendController(ch), delay_(ch->rtt_avg_) { @@ -60,9 +81,6 @@ void KeepAliveController::OnDataRecvd(bin64_t b) { if (b!=bin64_t::NONE && b!=bin64_t::ALL) { // channel is alive delay_ = ch_->rtt_avg_; Schedule(NOW); // schedule an ACK; TODO: aggregate - } else { - delay_ = ch_->rtt_avg_; - Schedule(NOW); } } diff --git a/ext/send_control.h b/ext/send_control.h index 91318a6..e4887e0 100644 --- a/ext/send_control.h +++ b/ext/send_control.h @@ -44,7 +44,22 @@ struct SendController { virtual ~SendController() {} }; - +struct PingPongController : public SendController { + + int sent_, unanswered_; + + PingPongController (SendController* orig) : + SendController(orig), sent_(0), unanswered_(0) {} + PingPongController (Channel* ch) : + unanswered_(0), sent_(0), SendController(ch) {} + const char* type() const { return "PingPong"; } + bool MaySendData(); + void OnDataSent(bin64_t b); + void OnDataRecvd(bin64_t b); + void OnAckRcvd(bin64_t ackd) ; + ~PingPongController() {} + +}; /** Mission of the keepalive controller to keep the channel alive as no data sending happens; If no data is transmitted in either direction, inter-packet times grow exponentially diff --git a/p2tp.cpp b/p2tp.cpp index 7fe32df..2db3de2 100644 --- a/p2tp.cpp +++ b/p2tp.cpp @@ -48,7 +48,7 @@ Channel::Channel (FileTransfer* transfer, int socket, Address peer_addr) : peer_ = tracker; this->id = channels.size(); channels.push_back(this); - cc_ = new KeepAliveController(this); + cc_ = new PingPongController(this); Schedule(NOW); // FIXME ugly }