Merge branch 'atp' of https://github.com/birarda/hifi into protocol

This commit is contained in:
Atlante45 2015-07-29 15:45:24 -07:00
commit 8a3c51ef61
10 changed files with 51 additions and 40 deletions

View file

@ -33,8 +33,6 @@
#include "UUID.h" #include "UUID.h"
#include "NetworkLogging.h" #include "NetworkLogging.h"
#include "udt/udt.h"
const char SOLO_NODE_TYPES[2] = { const char SOLO_NODE_TYPES[2] = {
NodeType::AvatarMixer, NodeType::AvatarMixer,
NodeType::AudioMixer NodeType::AudioMixer
@ -81,9 +79,6 @@ LimitedNodeList::LimitedNodeList(unsigned short socketListenPort, unsigned short
qCDebug(networking) << "NodeList DTLS socket is listening on" << _dtlsSocket->localPort(); 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 // check for local socket updates every so often
const int LOCAL_SOCKET_UPDATE_INTERVAL_MSECS = 5 * 1000; const int LOCAL_SOCKET_UPDATE_INTERVAL_MSECS = 5 * 1000;
QTimer* localSocketUpdate = new QTimer(this); QTimer* localSocketUpdate = new QTimer(this);

View file

@ -17,11 +17,10 @@
#include <QtCore/QIODevice> #include <QtCore/QIODevice>
#include "../HifiSockAddr.h" #include "../HifiSockAddr.h"
#include "Constants.h"
namespace udt { namespace udt {
static const int MAX_PACKET_SIZE = 1450;
class BasePacket : public QIODevice { class BasePacket : public QIODevice {
Q_OBJECT Q_OBJECT
public: public:

View file

@ -10,6 +10,7 @@
// //
#include "CongestionControl.h" #include "CongestionControl.h"
#include "Packet.h"
using namespace udt; using namespace udt;
using namespace std::chrono; using namespace std::chrono;
@ -19,6 +20,8 @@ static const double USECS_PER_SECOND = 1000000.0;
void DefaultCC::init() { void DefaultCC::init() {
_lastRCTime = high_resolution_clock::now(); _lastRCTime = high_resolution_clock::now();
_mss = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER;
_slowStartLastAck = _sendCurrSeqNum; _slowStartLastAck = _sendCurrSeqNum;
_lastDecreaseMaxSeq = SequenceNumber { SequenceNumber::MAX }; _lastDecreaseMaxSeq = SequenceNumber { SequenceNumber::MAX };

View file

@ -30,6 +30,10 @@ Connection::Connection(Socket* parentSocket, HifiSockAddr destination, unique_pt
_destination(destination), _destination(destination),
_congestionControl(move(congestionControl)) _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() { Connection::~Connection() {
@ -114,7 +118,9 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) {
// pack in the RTT and variance // pack in the RTT and variance
ackPacket->writePrimitive(_rtt); 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) { if (wasCausedBySyncTimeout) {
// pack in the receive speed and estimatedBandwidth // pack in the receive speed and estimatedBandwidth

View file

@ -16,6 +16,7 @@
#include <memory> #include <memory>
#include "ConnectionStats.h" #include "ConnectionStats.h"
#include "Constants.h"
#include "LossList.h" #include "LossList.h"
#include "PacketTimeWindow.h" #include "PacketTimeWindow.h"
#include "SendQueue.h" #include "SendQueue.h"
@ -65,7 +66,7 @@ private:
int estimatedTimeout() const; 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 _nakInterval; // NAK timeout interval, in microseconds
int _minNAKInterval { 100000 }; // NAK timeout interval lower bound, default of 100ms int _minNAKInterval { 100000 }; // NAK timeout interval lower bound, default of 100ms
@ -83,7 +84,7 @@ private:
int32_t _rtt; // RTT, in microseconds int32_t _rtt; // RTT, in microseconds
int32_t _rttVariance; // RTT variance 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 _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 int _deliveryRate { 16 }; // Exponential moving average for receiver's receive rate, in packets per second

View file

@ -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

View file

@ -22,6 +22,8 @@ using namespace udt;
Socket::Socket(QObject* parent) : Socket::Socket(QObject* parent) :
QObject(parent) QObject(parent)
{ {
setSystemBufferSizes();
connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams); connect(&_udpSocket, &QUdpSocket::readyRead, this, &Socket::readPendingDatagrams);
// make sure our synchronization method is called every SYN interval // make sure our synchronization method is called every SYN interval
@ -38,17 +40,21 @@ void Socket::rebind() {
_udpSocket.bind(QHostAddress::AnyIPv4, oldPort); _udpSocket.bind(QHostAddress::AnyIPv4, oldPort);
} }
void Socket::setBufferSizes(int numBytes) { void Socket::setSystemBufferSizes() {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
QAbstractSocket::SocketOption bufferOpt; QAbstractSocket::SocketOption bufferOpt;
QString bufferTypeString; QString bufferTypeString;
int numBytes = 0;
if (i == 0) { if (i == 0) {
bufferOpt = QAbstractSocket::SendBufferSizeSocketOption; bufferOpt = QAbstractSocket::SendBufferSizeSocketOption;
numBytes = udt::UDP_SEND_BUFFER_SIZE_BYTES;
bufferTypeString = "send"; bufferTypeString = "send";
} else { } else {
bufferOpt = QAbstractSocket::ReceiveBufferSizeSocketOption; bufferOpt = QAbstractSocket::ReceiveBufferSizeSocketOption;
numBytes = udt::UDP_RECEIVE_BUFFER_SIZE_BYTES;
bufferTypeString = "receive"; bufferTypeString = "receive";
} }

View file

@ -56,8 +56,6 @@ public:
void setPacketFilterOperator(PacketFilterOperator filterOperator) { _packetFilterOperator = filterOperator; } void setPacketFilterOperator(PacketFilterOperator filterOperator) { _packetFilterOperator = filterOperator; }
void setPacketHandler(PacketHandler handler) { _packetHandler = handler; } void setPacketHandler(PacketHandler handler) { _packetHandler = handler; }
void setBufferSizes(int numBytes);
void addUnfilteredHandler(const HifiSockAddr& senderSockAddr, BasePacketHandler handler) void addUnfilteredHandler(const HifiSockAddr& senderSockAddr, BasePacketHandler handler)
{ _unfilteredHandlers[senderSockAddr] = handler; } { _unfilteredHandlers[senderSockAddr] = handler; }
@ -68,6 +66,8 @@ private slots:
void rateControlSync(); void rateControlSync();
private: private:
void setSystemBufferSizes();
QUdpSocket _udpSocket { this }; QUdpSocket _udpSocket { this };
PacketFilterOperator _packetFilterOperator; PacketFilterOperator _packetFilterOperator;
PacketHandler _packetHandler; PacketHandler _packetHandler;

View file

@ -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"

View file

@ -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