mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 15:43:50 +02:00
Add initial seq number to handshake
This commit is contained in:
parent
a7bb47fbcc
commit
b442075205
3 changed files with 26 additions and 12 deletions
|
@ -731,15 +731,20 @@ void Connection::processNAK(std::unique_ptr<ControlPacket> controlPacket) {
|
|||
}
|
||||
|
||||
void Connection::processHandshake(std::unique_ptr<ControlPacket> controlPacket) {
|
||||
SequenceNumber initialSequenceNumber;
|
||||
controlPacket->readPrimitive(&initialSequenceNumber);
|
||||
|
||||
if (!_hasReceivedHandshake || _hasReceivedData) {
|
||||
if (!_hasReceivedHandshake || initialSequenceNumber != _initialReceiveSequenceNumber) {
|
||||
// server sent us a handshake - we need to assume this means state should be reset
|
||||
// as long as we haven't received a handshake yet or we have and we've received some data
|
||||
resetReceiveState();
|
||||
_initialReceiveSequenceNumber = initialSequenceNumber;
|
||||
}
|
||||
|
||||
// immediately respond with a handshake ACK
|
||||
static auto handshakeACK = ControlPacket::create(ControlPacket::HandshakeACK, 0);
|
||||
static auto handshakeACK = ControlPacket::create(ControlPacket::HandshakeACK, sizeof(SequenceNumber));
|
||||
handshakeACK->seek(0);
|
||||
handshakeACK->writePrimitive(initialSequenceNumber);
|
||||
_parentSocket->writeBasePacket(*handshakeACK, _destination);
|
||||
|
||||
// indicate that handshake has been received
|
||||
|
@ -749,8 +754,11 @@ void Connection::processHandshake(std::unique_ptr<ControlPacket> controlPacket)
|
|||
void Connection::processHandshakeACK(std::unique_ptr<ControlPacket> controlPacket) {
|
||||
// if we've decided to clean up the send queue then this handshake ACK should be ignored, it's useless
|
||||
if (_sendQueue) {
|
||||
SequenceNumber initialSequenceNumber;
|
||||
controlPacket->readPrimitive(&initialSequenceNumber);
|
||||
|
||||
// hand off this handshake ACK to the send queue so it knows it can start sending
|
||||
getSendQueue().handshakeACK();
|
||||
getSendQueue().handshakeACK(initialSequenceNumber);
|
||||
|
||||
// indicate that handshake ACK was received
|
||||
_hasReceivedHandshakeACK = true;
|
||||
|
|
|
@ -202,7 +202,11 @@ void SendQueue::sendHandshake() {
|
|||
std::unique_lock<std::mutex> handshakeLock { _handshakeMutex };
|
||||
if (!_hasReceivedHandshakeACK) {
|
||||
// we haven't received a handshake ACK from the client, send another now
|
||||
static const auto handshakePacket = ControlPacket::create(ControlPacket::Handshake, 0);
|
||||
static const auto handshakePacket = ControlPacket::create(ControlPacket::Handshake, sizeof(SequenceNumber));
|
||||
|
||||
handshakePacket->seek(0);
|
||||
|
||||
handshakePacket->writePrimitive(_initialSequenceNumber);
|
||||
_socket->writeBasePacket(*handshakePacket, _destination);
|
||||
|
||||
// we wait for the ACK or the re-send interval to expire
|
||||
|
@ -211,14 +215,16 @@ void SendQueue::sendHandshake() {
|
|||
}
|
||||
}
|
||||
|
||||
void SendQueue::handshakeACK() {
|
||||
{
|
||||
std::lock_guard<std::mutex> locker { _handshakeMutex };
|
||||
_hasReceivedHandshakeACK = true;
|
||||
void SendQueue::handshakeACK(SequenceNumber initialSequenceNumber) {
|
||||
if (initialSequenceNumber == _initialSequenceNumber) {
|
||||
{
|
||||
std::lock_guard<std::mutex> locker { _handshakeMutex };
|
||||
_hasReceivedHandshakeACK = true;
|
||||
}
|
||||
|
||||
// Notify on the handshake ACK condition
|
||||
_handshakeACKCondition.notify_one();
|
||||
}
|
||||
|
||||
// Notify on the handshake ACK condition
|
||||
_handshakeACKCondition.notify_one();
|
||||
}
|
||||
|
||||
SequenceNumber SendQueue::getNextSequenceNumber() {
|
||||
|
|
|
@ -71,7 +71,7 @@ public slots:
|
|||
void ack(SequenceNumber ack);
|
||||
void nak(SequenceNumber start, SequenceNumber end);
|
||||
void overrideNAKListFromPacket(ControlPacket& packet);
|
||||
void handshakeACK();
|
||||
void handshakeACK(SequenceNumber initialSequenceNumber);
|
||||
|
||||
signals:
|
||||
void packetSent(int dataSize, int payloadSize);
|
||||
|
|
Loading…
Reference in a new issue