From 1265531f797f535e95ba18cfd696482115050673 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Thu, 27 Jun 2019 15:52:39 -0700 Subject: [PATCH] Plumb down change of destination address --- libraries/networking/src/udt/Connection.cpp | 8 ++++++++ libraries/networking/src/udt/Connection.h | 2 ++ libraries/networking/src/udt/SendQueue.cpp | 4 ++++ libraries/networking/src/udt/SendQueue.h | 1 + libraries/networking/src/udt/Socket.cpp | 8 ++++++++ 5 files changed, 23 insertions(+) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 418dc8f417..872ee4dd4c 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -114,6 +114,7 @@ SendQueue& Connection::getSendQueue() { QObject::connect(_sendQueue.get(), &SendQueue::packetRetransmitted, this, &Connection::recordRetransmission); QObject::connect(_sendQueue.get(), &SendQueue::queueInactive, this, &Connection::queueInactive); QObject::connect(_sendQueue.get(), &SendQueue::timeout, this, &Connection::queueTimeout); + QObject::connect(this, &Connection::destinationAddressChange, _sendQueue.get(), &SendQueue::updateDestinationAddress); // set defaults on the send queue from our congestion control object and estimatedTimeout() @@ -485,3 +486,10 @@ std::unique_ptr PendingReceivedMessage::removeNextPacket() { } return std::unique_ptr(); } + +void Connection::setDestinationAddress(const HifiSockAddr& destination) { + if (_destination != destination) { + _destination = destination; + emit destinationAddressChange(destination); + } +} diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index 938ec36860..47edb021c8 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -76,10 +76,12 @@ public: void recordSentUnreliablePackets(int wireSize, int payloadSize); void recordReceivedUnreliablePackets(int wireSize, int payloadSize); + void setDestinationAddress(const HifiSockAddr& destination); signals: void packetSent(); void receiverHandshakeRequestComplete(const HifiSockAddr& sockAddr); + void destinationAddressChange(HifiSockAddr currentAddress); private slots: void recordSentPackets(int wireSize, int payloadSize, SequenceNumber seqNum, p_high_resolution_clock::time_point timePoint); diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 15841b5c21..2997c272f9 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -557,3 +557,7 @@ void SendQueue::deactivate() { bool SendQueue::isFlowWindowFull() const { return seqlen(SequenceNumber { (uint32_t) _lastACKSequenceNumber }, _currentSequenceNumber) > _flowWindowSize; } + +void SendQueue::updateDestinationAddress(HifiSockAddr newAddress) { + _destination = newAddress; +} diff --git a/libraries/networking/src/udt/SendQueue.h b/libraries/networking/src/udt/SendQueue.h index c1a2b59075..2153745250 100644 --- a/libraries/networking/src/udt/SendQueue.h +++ b/libraries/networking/src/udt/SendQueue.h @@ -75,6 +75,7 @@ public slots: void ack(SequenceNumber ack); void fastRetransmit(SequenceNumber ack); void handshakeACK(); + void updateDestinationAddress(HifiSockAddr newAddress); signals: void packetSent(int wireSize, int payloadSize, SequenceNumber seqNum, p_high_resolution_clock::time_point timePoint); diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 7cc6680efd..94628aa852 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -540,7 +540,15 @@ void Socket::handleStateChanged(QAbstractSocket::SocketState socketState) { void Socket::handleRemoteAddressChange(HifiSockAddr previousAddress, HifiSockAddr currentAddress) { Lock connectionsLock(_connectionsHashMutex); + _connectionsHash.erase(currentAddress); + const auto connectionIter = _connectionsHash.find(currentAddress); + if (connectionIter != _connectionsHash.end()) { + auto connection = std::move(connectionIter->second); + _connectionsHash.erase(connectionIter); + connection->setDestinationAddress(currentAddress); + _connectionsHash[currentAddress] = std::move(connection); + } } #if (PR_BUILD || DEV_BUILD)