From 5fc3e7dbf1b19a3ef518d564b29a30b411807d0c Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 Jul 2015 16:12:00 -0700 Subject: [PATCH 1/2] add an updater that takes a lambda for CC update --- libraries/networking/src/udt/Connection.cpp | 38 +++++++++++---------- libraries/networking/src/udt/Connection.h | 2 ++ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 935622f4d8..626833c5c5 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -383,15 +383,10 @@ void Connection::processACK(std::unique_ptr controlPacket) { _congestionControl->setBandwidth(_bandwidth); } - // update the last sent sequence number in congestion control - _congestionControl->setSendCurrentSequenceNumber(_sendQueue->getCurrentSequenceNumber()); - - // fire the onACK callback for congestion control - _congestionControl->onAck(ack); - - // now that we've updated the congestion control, update the packet send period and flow window size - _sendQueue->setPacketSendPeriod(_congestionControl->_packetSendPeriod); - _sendQueue->setFlowWindowSize(std::min(_flowWindowSize, (int) _congestionControl->_congestionWindowSize)); + // give this ACK to the congestion control and update the send queue parameters + updateCongestionControlAndSentQueue([this, ack](){ + _congestionControl->onAck(ack); + }); // update the total count of received ACKs _stats.recordReceivedACK(); @@ -457,15 +452,10 @@ void Connection::processNAK(std::unique_ptr controlPacket) { // send that off to the send queue so it knows there was loss _sendQueue->nak(start, end); - // update the last sent sequence number in congestion control - _congestionControl->setSendCurrentSequenceNumber(_sendQueue->getCurrentSequenceNumber()); - - // give the loss to the congestion control object - _congestionControl->onLoss(start, end); - - // now that we've updated the congestion control, update the packet send period and flow window size - _sendQueue->setPacketSendPeriod(_congestionControl->_packetSendPeriod); - _sendQueue->setFlowWindowSize(std::min(_flowWindowSize, (int) _congestionControl->_congestionWindowSize)); + // give the loss to the congestion control object and update the send queue parameters + updateCongestionControlAndSentQueue([this, start, end](){ + _congestionControl->onLoss(start, end); + }); _stats.recordReceivedNAK(); } @@ -503,3 +493,15 @@ void Connection::updateRTT(int rtt) { int Connection::estimatedTimeout() const { return _congestionControl->_userDefinedRto ? _rtt + _rttVariance * 4 : _congestionControl->_rto; } + +void Connection::updateCongestionControlAndSentQueue(std::function congestionCallback) { + // update the last sent sequence number in congestion control + _congestionControl->setSendCurrentSequenceNumber(_sendQueue->getCurrentSequenceNumber()); + + // fire congestion control callback + congestionCallback(); + + // now that we've update the congestion control, update the packet send period and flow window size + _sendQueue->setPacketSendPeriod(_congestionControl->_packetSendPeriod); + _sendQueue->setFlowWindowSize(std::min(_flowWindowSize, (int) _congestionControl->_congestionWindowSize)); +} diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index 1ce81734b2..b46d2c37cf 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -64,6 +64,8 @@ private: int estimatedTimeout() const; + void updateCongestionControlAndSentQueue(std::function congestionCallback); + int _synInterval; // Periodical Rate Control Interval, in microseconds int _nakInterval; // NAK timeout interval, in microseconds From 35f00f9ba1388f362d2c21e4bfe2e7407cfdc23a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 29 Jul 2015 16:12:50 -0700 Subject: [PATCH 2/2] rename the CC and send queue updater --- libraries/networking/src/udt/Connection.cpp | 6 +++--- libraries/networking/src/udt/Connection.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 626833c5c5..ec175d8f39 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -384,7 +384,7 @@ void Connection::processACK(std::unique_ptr controlPacket) { } // give this ACK to the congestion control and update the send queue parameters - updateCongestionControlAndSentQueue([this, ack](){ + updateCongestionControlAndSendQueue([this, ack](){ _congestionControl->onAck(ack); }); @@ -453,7 +453,7 @@ void Connection::processNAK(std::unique_ptr controlPacket) { _sendQueue->nak(start, end); // give the loss to the congestion control object and update the send queue parameters - updateCongestionControlAndSentQueue([this, start, end](){ + updateCongestionControlAndSendQueue([this, start, end](){ _congestionControl->onLoss(start, end); }); @@ -494,7 +494,7 @@ int Connection::estimatedTimeout() const { return _congestionControl->_userDefinedRto ? _rtt + _rttVariance * 4 : _congestionControl->_rto; } -void Connection::updateCongestionControlAndSentQueue(std::function congestionCallback) { +void Connection::updateCongestionControlAndSendQueue(std::function congestionCallback) { // update the last sent sequence number in congestion control _congestionControl->setSendCurrentSequenceNumber(_sendQueue->getCurrentSequenceNumber()); diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index b46d2c37cf..eaa55797d9 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -64,7 +64,7 @@ private: int estimatedTimeout() const; - void updateCongestionControlAndSentQueue(std::function congestionCallback); + void updateCongestionControlAndSendQueue(std::function congestionCallback); int _synInterval; // Periodical Rate Control Interval, in microseconds