diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 95afbedb86..96d4b65aec 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -411,7 +411,15 @@ SequenceNumber Connection::nextACK() const { bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, int packetSize, int payloadSize) { if (!_hasReceivedHandshake) { - // refuse to process any packets until we've received the handshake + // Refuse to process any packets until we've received the handshake + // Send handshake request to re-request a handshake + auto handshakeRequestPacket = ControlPacket::create(ControlPacket::HandshakeRequest, 0); + _parentSocket->writeBasePacket(*handshakeRequestPacket, _destination); + +#ifdef UDT_CONNECTION_DEBUG + qCDebug(networking) << "Received packet before receiving handshake, sending HandshakeRequest"; +#endif + return false; } @@ -537,6 +545,17 @@ void Connection::processControl(std::unique_ptr controlPacket) { processProbeTail(move(controlPacket)); } break; + case ControlPacket::HandshakeRequest: + if (_hasReceivedHandshakeACK) { + // We're already in a state where we've received a handshake ack, so we are likely in a state + // where the other end expired our connection. Let's reset. + +#ifdef UDT_CONNECTION_DEBUG + qCDebug(networking) << "Got handshake request, stopping SendQueue"; +#endif + stopSendQueue(); + } + break; } } diff --git a/libraries/networking/src/udt/ControlPacket.cpp b/libraries/networking/src/udt/ControlPacket.cpp index e672ab426b..0d5d3e8c25 100644 --- a/libraries/networking/src/udt/ControlPacket.cpp +++ b/libraries/networking/src/udt/ControlPacket.cpp @@ -100,7 +100,7 @@ void ControlPacket::readType() { Q_ASSERT_X(bitAndType & CONTROL_BIT_MASK, "ControlPacket::readHeader()", "This should be a control packet"); uint16_t packetType = (bitAndType & ~CONTROL_BIT_MASK) >> (8 * sizeof(Type)); - Q_ASSERT_X(packetType <= ControlPacket::Type::ProbeTail, "ControlPacket::readType()", "Received a control packet with wrong type"); + Q_ASSERT_X(packetType <= ControlPacket::Type::HandshakeRequest, "ControlPacket::readType()", "Received a control packet with wrong type"); // read the type _type = (Type) packetType; diff --git a/libraries/networking/src/udt/ControlPacket.h b/libraries/networking/src/udt/ControlPacket.h index fea8210ba0..3c770de9bb 100644 --- a/libraries/networking/src/udt/ControlPacket.h +++ b/libraries/networking/src/udt/ControlPacket.h @@ -34,7 +34,8 @@ public: TimeoutNAK, Handshake, HandshakeACK, - ProbeTail + ProbeTail, + HandshakeRequest }; static std::unique_ptr create(Type type, qint64 size = -1); diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 8e5141b58a..8d35878b0f 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -529,4 +529,4 @@ void SendQueue::deactivate() { emit queueInactive(); _state = State::Stopped; -} +} \ No newline at end of file