Merge pull request #7398 from huffman/add-request-handshake

Add HandshakeRequest packet
This commit is contained in:
Stephen Birarda 2016-03-21 14:27:28 -07:00
commit eb5ecc84ff
4 changed files with 24 additions and 4 deletions

View file

@ -411,7 +411,15 @@ SequenceNumber Connection::nextACK() const {
bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, int packetSize, int payloadSize) { bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, int packetSize, int payloadSize) {
if (!_hasReceivedHandshake) { 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; return false;
} }
@ -537,6 +545,17 @@ void Connection::processControl(std::unique_ptr<ControlPacket> controlPacket) {
processProbeTail(move(controlPacket)); processProbeTail(move(controlPacket));
} }
break; 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;
} }
} }

View file

@ -100,7 +100,7 @@ void ControlPacket::readType() {
Q_ASSERT_X(bitAndType & CONTROL_BIT_MASK, "ControlPacket::readHeader()", "This should be a control packet"); 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)); 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 // read the type
_type = (Type) packetType; _type = (Type) packetType;

View file

@ -34,7 +34,8 @@ public:
TimeoutNAK, TimeoutNAK,
Handshake, Handshake,
HandshakeACK, HandshakeACK,
ProbeTail ProbeTail,
HandshakeRequest
}; };
static std::unique_ptr<ControlPacket> create(Type type, qint64 size = -1); static std::unique_ptr<ControlPacket> create(Type type, qint64 size = -1);

View file

@ -529,4 +529,4 @@ void SendQueue::deactivate() {
emit queueInactive(); emit queueInactive();
_state = State::Stopped; _state = State::Stopped;
} }