mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:09:24 +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) {
|
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
|
// 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
|
// as long as we haven't received a handshake yet or we have and we've received some data
|
||||||
resetReceiveState();
|
resetReceiveState();
|
||||||
|
_initialReceiveSequenceNumber = initialSequenceNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
// immediately respond with a handshake ACK
|
// 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);
|
_parentSocket->writeBasePacket(*handshakeACK, _destination);
|
||||||
|
|
||||||
// indicate that handshake has been received
|
// 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) {
|
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 we've decided to clean up the send queue then this handshake ACK should be ignored, it's useless
|
||||||
if (_sendQueue) {
|
if (_sendQueue) {
|
||||||
|
SequenceNumber initialSequenceNumber;
|
||||||
|
controlPacket->readPrimitive(&initialSequenceNumber);
|
||||||
|
|
||||||
// hand off this handshake ACK to the send queue so it knows it can start sending
|
// 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
|
// indicate that handshake ACK was received
|
||||||
_hasReceivedHandshakeACK = true;
|
_hasReceivedHandshakeACK = true;
|
||||||
|
|
|
@ -202,7 +202,11 @@ void SendQueue::sendHandshake() {
|
||||||
std::unique_lock<std::mutex> handshakeLock { _handshakeMutex };
|
std::unique_lock<std::mutex> handshakeLock { _handshakeMutex };
|
||||||
if (!_hasReceivedHandshakeACK) {
|
if (!_hasReceivedHandshakeACK) {
|
||||||
// we haven't received a handshake ACK from the client, send another now
|
// 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);
|
_socket->writeBasePacket(*handshakePacket, _destination);
|
||||||
|
|
||||||
// we wait for the ACK or the re-send interval to expire
|
// we wait for the ACK or the re-send interval to expire
|
||||||
|
@ -211,14 +215,16 @@ void SendQueue::sendHandshake() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendQueue::handshakeACK() {
|
void SendQueue::handshakeACK(SequenceNumber initialSequenceNumber) {
|
||||||
{
|
if (initialSequenceNumber == _initialSequenceNumber) {
|
||||||
std::lock_guard<std::mutex> locker { _handshakeMutex };
|
{
|
||||||
_hasReceivedHandshakeACK = true;
|
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() {
|
SequenceNumber SendQueue::getNextSequenceNumber() {
|
||||||
|
|
|
@ -71,7 +71,7 @@ public slots:
|
||||||
void ack(SequenceNumber ack);
|
void ack(SequenceNumber ack);
|
||||||
void nak(SequenceNumber start, SequenceNumber end);
|
void nak(SequenceNumber start, SequenceNumber end);
|
||||||
void overrideNAKListFromPacket(ControlPacket& packet);
|
void overrideNAKListFromPacket(ControlPacket& packet);
|
||||||
void handshakeACK();
|
void handshakeACK(SequenceNumber initialSequenceNumber);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void packetSent(int dataSize, int payloadSize);
|
void packetSent(int dataSize, int payloadSize);
|
||||||
|
|
Loading…
Reference in a new issue