From: victor Date: Thu, 12 Nov 2009 15:39:16 +0000 (+0000) Subject: fixed dip_avg_ and rtt_avg_ miscalculation X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=57f62422a249e1240caa427901c46f55ece310c5;p=swift-upb.git fixed dip_avg_ and rtt_avg_ miscalculation git-svn-id: https://ttuki.vtt.fi/svn/p2p-next/TUD/p2tp/trunk@543 e16421f0-f15b-0410-abcd-98678b794739 --- diff --git a/exec/leecher.cpp b/exec/leecher.cpp index dbbe1a4..036479f 100644 --- a/exec/leecher.cpp +++ b/exec/leecher.cpp @@ -17,7 +17,6 @@ using namespace p2tp; int main (int argn, char** args) { srand(time(NULL)); - FileTransfer::instance = rand(); if (argn<4) { fprintf(stderr,"parameters: root_hash filename tracker_ip:port [own_ip:port]\n"); diff --git a/ext/send_control.cpp b/ext/send_control.cpp index ffa8d4a..f4484cf 100644 --- a/ext/send_control.cpp +++ b/ext/send_control.cpp @@ -63,8 +63,8 @@ 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)); + if (b!=bin64_t::ALL && b!=bin64_t::NONE) + Swap(new SlowStartController(this)); } void KeepAliveController::OnDataRecvd(bin64_t b) { @@ -74,6 +74,11 @@ void KeepAliveController::OnAckRcvd(bin64_t ackd) { } +CwndController::CwndController(SendController* orig, int cwnd) : +SendController(orig), cwnd_(cwnd), last_change_(0) { + ch_->rtt_avg_ = TINT_SEC; // cannot trust the past value + ch_->dev_avg_ = 0; +} bool CwndController::MaySendData() { dprintf("%s #%i sendctrl may send %i < %f & %s (rtt %lli)\n",tintstr(), @@ -94,7 +99,7 @@ tint CwndController::NextSendTime () { void CwndController::OnDataSent(bin64_t b) { if (b==bin64_t::ALL || b==bin64_t::NONE) { if (MaySendData()) - Swap(new PingPongController(this)); + Swap(new KeepAliveController(this)); } } diff --git a/ext/send_control.h b/ext/send_control.h index 4fa9205..baf12cd 100644 --- a/ext/send_control.h +++ b/ext/send_control.h @@ -85,8 +85,7 @@ struct CwndController : public SendController { double cwnd_; tint last_change_; - CwndController(SendController* orig, int cwnd=1) : - SendController(orig), cwnd_(cwnd), last_change_(0) { } + CwndController(SendController* orig, int cwnd=1) ; bool MaySendData() ; tint NextSendTime () ; diff --git a/p2tp.cpp b/p2tp.cpp index bf0115e..9211b67 100644 --- a/p2tp.cpp +++ b/p2tp.cpp @@ -40,7 +40,7 @@ PeerSelector* Channel::peer_selector = new SimpleSelector(); Channel::Channel (FileTransfer* transfer, int socket, Address peer_addr) : transfer_(transfer), peer_(peer_addr), peer_channel_id_(0), pex_out_(0), socket_(socket==-1?sockets[0]:socket), // FIXME - data_out_cap_(bin64_t::ALL), + data_out_cap_(bin64_t::ALL), last_data_time_(0), own_id_mentioned_(false), next_send_time_(0), last_send_time_(0), last_recv_time_(0), rtt_avg_(TINT_SEC), dev_avg_(0), dip_avg_(TINT_SEC) { diff --git a/p2tp.h b/p2tp.h index d18b325..6f7a6fc 100644 --- a/p2tp.h +++ b/p2tp.h @@ -265,6 +265,7 @@ namespace p2tp { /** Smoothed averages for RTT, RTT deviation and data interarrival periods. */ tint rtt_avg_, dev_avg_, dip_avg_; tint last_send_time_; + tint last_data_time_; tint last_recv_time_; tint next_send_time_; tint peer_send_time_; diff --git a/sendrecv.cpp b/sendrecv.cpp index cb0e2d5..e56deb5 100644 --- a/sendrecv.cpp +++ b/sendrecv.cpp @@ -313,10 +313,11 @@ bin64_t Channel::OnData (Datagram& dgram) { dprintf("%s #%i %cdata (%lli)\n",tintstr(),id,ok?'-':'!',pos.offset()); if (ok) { data_in_ = tintbin(NOW,pos); - if (last_recv_time_) { - tint dip = NOW - last_recv_time_; // FIXME: was it an ACK? + if (last_data_time_) { + tint dip = NOW - last_data_time_; dip_avg_ = ( dip_avg_*3 + dip ) >> 2; } + last_data_time_ = NOW; transfer().picker().Received(pos); // so dirty; FIXME FIXME FIXME return pos; } else diff --git a/tests/connecttest.cpp b/tests/connecttest.cpp index 113a2e2..11a63a3 100644 --- a/tests/connecttest.cpp +++ b/tests/connecttest.cpp @@ -30,7 +30,7 @@ TEST(P2TP,CwndTest) { int file = p2tp::Open("doc/sofi.jpg"); FileTransfer* fileobj = FileTransfer::file(file); - FileTransfer::instance++; + //FileTransfer::instance++; p2tp::SetTracker(Address("127.0.0.1",7001)); diff --git a/tests/transfertest.cpp b/tests/transfertest.cpp index 4aea0f4..1c04c46 100644 --- a/tests/transfertest.cpp +++ b/tests/transfertest.cpp @@ -52,7 +52,6 @@ TEST(TransferTest,TransferFile) { // retrieve it unlink("copy"); - FileTransfer::instance = 1; FileTransfer* leech_transfer = new FileTransfer("copy",seed->root_hash()); HashTree* leech = & leech_transfer->file(); leech_transfer->picker().Randomize(0); @@ -72,7 +71,6 @@ TEST(TransferTest,TransferFile) { for (int i=0; i<5; i++) { if (i==2) { // now: stop, save, start delete leech_transfer; - FileTransfer::instance = 1; leech_transfer = new FileTransfer("copy",seed->root_hash()); leech = & leech_transfer->file(); leech_transfer->picker().Randomize(0);