diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index fc8e6ad8fe..2ca4e89c12 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -33,8 +33,6 @@ #include "UUID.h" #include "NetworkLogging.h" -#include "udt/udt.h" - const char SOLO_NODE_TYPES[2] = { NodeType::AvatarMixer, NodeType::AudioMixer @@ -81,9 +79,6 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short qCDebug(networking) << "NodeList DTLS socket is listening on" << _dtlsSocket->localPort(); } - const int LARGER_BUFFER_SIZE = 1048576; - _nodeSocket.setBufferSizes(LARGER_BUFFER_SIZE); - // check for local socket updates every so often const int LOCAL_SOCKET_UPDATE_INTERVAL_MSECS = 5 * 1000; QTimer* localSocketUpdate = new QTimer(this); diff --git a/libraries/networking/src/udt/BasePacket.h b/libraries/networking/src/udt/BasePacket.h index d943e05204..8dcc3ab9be 100644 --- a/libraries/networking/src/udt/BasePacket.h +++ b/libraries/networking/src/udt/BasePacket.h @@ -17,11 +17,10 @@ #include #include "../HifiSockAddr.h" +#include "Constants.h" namespace udt { -static const int MAX_PACKET_SIZE = 1450; - class BasePacket : public QIODevice { Q_OBJECT public: diff --git a/libraries/networking/src/udt/CongestionControl.cpp b/libraries/networking/src/udt/CongestionControl.cpp index 14d88a4761..1450e60930 100644 --- a/libraries/networking/src/udt/CongestionControl.cpp +++ b/libraries/networking/src/udt/CongestionControl.cpp @@ -10,6 +10,7 @@ // #include "CongestionControl.h" +#include "Packet.h" using namespace udt; using namespace std::chrono; @@ -19,6 +20,8 @@ static const double USECS_PER_SECOND = 1000000.0; void DefaultCC::init() { _lastRCTime = high_resolution_clock::now(); + _mss = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER; + _slowStartLastAck = _sendCurrSeqNum; _lastDecreaseMaxSeq = SequenceNumber { SequenceNumber::MAX }; diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index bce650b85a..de675bfca8 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -30,6 +30,10 @@ Connection::Connection(Socket* parentSocket, HifiSockAddr destination, unique_pt _destination(destination), _congestionControl(move(congestionControl)) { + // setup default SYN, RTT and RTT Variance based on the SYN interval in CongestionControl object + _synInterval = _congestionControl->synInterval(); + _rtt = _synInterval * 10; + _rttVariance = _rtt / 2; } Connection::~Connection() { @@ -114,7 +118,9 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) { // pack in the RTT and variance ackPacket->writePrimitive(_rtt); - // pack the available buffer size - must be a minimum of 2 + // pack the available buffer size, in packets + // in our implementation we have no hard limit on receive buffer size, send the default value + ackPacket->writePrimitive((int32_t) udt::CONNECTION_RECEIVE_BUFFER_SIZE_PACKETS); if (wasCausedBySyncTimeout) { // pack in the receive speed and estimatedBandwidth diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index c5ff009fc9..2af89000e6 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -16,6 +16,7 @@ #include #include "ConnectionStats.h" +#include "Constants.h" #include "LossList.h" #include "PacketTimeWindow.h" #include "SendQueue.h" @@ -65,7 +66,7 @@ private: int estimatedTimeout() const; - int _synInterval; // Periodical Rate Control Interval, in microseconds, defaults to 10ms + int _synInterval; // Periodical Rate Control Interval, in microseconds int _nakInterval; // NAK timeout interval, in microseconds int _minNAKInterval { 100000 }; // NAK timeout interval lower bound, default of 100ms @@ -83,7 +84,7 @@ private: int32_t _rtt; // RTT, in microseconds int32_t _rttVariance; // RTT variance - int _flowWindowSize; // Flow control window size + int _flowWindowSize { udt::MAX_PACKETS_IN_FLIGHT }; // Flow control window size int _bandwidth { 1 }; // Exponential moving average for estimated bandwidth, in packets per second int _deliveryRate { 16 }; // Exponential moving average for receiver's receive rate, in packets per second diff --git a/libraries/networking/src/udt/Constants.h b/libraries/networking/src/udt/Constants.h new file mode 100644 index 0000000000..e8a7658bf9 --- /dev/null +++ b/libraries/networking/src/udt/Constants.h @@ -0,0 +1,28 @@ +// +// Constants.h +// libraries/networking/src/udt +// +// Created by Clement on 7/13/15. +// Copyright 2015 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#pragma once + +#ifndef hifi_udt_Constants_h +#define hifi_udt_Constants_h + +namespace udt { + static const int MAX_PACKET_SIZE_WITH_UDP_HEADER = 1500; + static const int MAX_PACKET_SIZE = MAX_PACKET_SIZE_WITH_UDP_HEADER - 28; + static const int MAX_PACKETS_IN_FLIGHT = 25600; + static const int CONNECTION_RECEIVE_BUFFER_SIZE_PACKETS = 8192; + static const int CONNECTION_SEND_BUFFER_SIZE_PACKETS = 8192; + static const int UDP_SEND_BUFFER_SIZE_BYTES = 1048576; + static const int UDP_RECEIVE_BUFFER_SIZE_BYTES = 1048576; + static const int DEFAULT_SYN_INTERVAL_USECS = 10 * 1000; +} + +#endif // hifi_udt_Constants_h diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index c7c1d90666..650bdd7906 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -22,6 +22,8 @@ using namespace udt; Socket::Socket(QObject* parent) : QObject(parent) { + setSystemBufferSizes(); + connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams); // make sure our synchronization method is called every SYN interval @@ -38,17 +40,21 @@ void Socket::rebind() { _udpSocket.bind(QHostAddress::AnyIPv4, oldPort); } -void Socket::setBufferSizes(int numBytes) { +void Socket::setSystemBufferSizes() { for (int i = 0; i < 2; i++) { QAbstractSocket::SocketOption bufferOpt; QString bufferTypeString; + int numBytes = 0; + if (i == 0) { bufferOpt = QAbstractSocket::SendBufferSizeSocketOption; + numBytes = udt::UDP_SEND_BUFFER_SIZE_BYTES; bufferTypeString = "send"; } else { bufferOpt = QAbstractSocket::ReceiveBufferSizeSocketOption; + numBytes = udt::UDP_RECEIVE_BUFFER_SIZE_BYTES; bufferTypeString = "receive"; } diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 7cf4283cf3..0bc23cdf0a 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -56,8 +56,6 @@ public: void setPacketFilterOperator(PacketFilterOperator filterOperator) { _packetFilterOperator = filterOperator; } void setPacketHandler(PacketHandler handler) { _packetHandler = handler; } - void setBufferSizes(int numBytes); - void addUnfilteredHandler(const HifiSockAddr& senderSockAddr, BasePacketHandler handler) { _unfilteredHandlers[senderSockAddr] = handler; } @@ -68,6 +66,8 @@ private slots: void rateControlSync(); private: + void setSystemBufferSizes(); + QUdpSocket _udpSocket { this }; PacketFilterOperator _packetFilterOperator; PacketHandler _packetHandler; diff --git a/libraries/networking/src/udt/udt.cpp b/libraries/networking/src/udt/udt.cpp deleted file mode 100644 index d580a9f7f8..0000000000 --- a/libraries/networking/src/udt/udt.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// -// udt.cpp -// -// -// Created by Clement on 7/13/15. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include "udt.h" diff --git a/libraries/networking/src/udt/udt.h b/libraries/networking/src/udt/udt.h deleted file mode 100644 index 74803151d1..0000000000 --- a/libraries/networking/src/udt/udt.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// udt.h -// -// -// Created by Clement on 7/13/15. -// Copyright 2015 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#ifndef hifi_udt_h -#define hifi_udt_h - -#endif // hifi_udt_h \ No newline at end of file