mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 22:16:58 +02:00
Added sequence number to packets
This commit is contained in:
parent
c6f6dbd845
commit
8424e91ae1
3 changed files with 32 additions and 25 deletions
|
@ -216,6 +216,20 @@ bool LimitedNodeList::packetSourceAndHashMatch(const NLPacket& packet, SharedNod
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qint64 LimitedNodeList::writePacket(const NLPacket& packet, const Node& destinationNode) {
|
||||||
|
if (!destinationNode.getActiveSocket()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Move to transport layer when ready
|
||||||
|
if (SEQUENCE_NUMBERED_PACKETS.contains(packet.getType())) {
|
||||||
|
PacketSequenceNumber sequenceNumber = getNextSequenceNumberForPacket(destinationNode.getUUID(), packet.getType());
|
||||||
|
const_cast<NLPacket&>(packet).writeSequenceNumber(sequenceNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return writePacket(packet, *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
|
||||||
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr,
|
qint64 LimitedNodeList::writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr,
|
||||||
const QUuid& connectionSecret) {
|
const QUuid& connectionSecret) {
|
||||||
if (!NON_SOURCED_PACKETS.contains(packet.getType())) {
|
if (!NON_SOURCED_PACKETS.contains(packet.getType())) {
|
||||||
|
@ -248,14 +262,7 @@ qint64 LimitedNodeList::writeDatagram(const QByteArray& datagram, const HifiSock
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const Node& destinationNode) {
|
||||||
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
return writePacket(packet, destinationNode);
|
||||||
if (!activeSocket) {
|
|
||||||
// we don't have a socket to send to, return 0
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// use the node's active socket as the destination socket
|
|
||||||
return sendUnreliablePacket(packet, *activeSocket, destinationNode.getConnectionSecret());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr,
|
qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiSockAddr& sockAddr,
|
||||||
|
@ -264,30 +271,29 @@ qint64 LimitedNodeList::sendUnreliablePacket(const NLPacket& packet, const HifiS
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode) {
|
||||||
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
// Keep unique_ptr alive during write
|
||||||
if (!activeSocket) {
|
auto result = writePacket(*packet, destinationNode);
|
||||||
// we don't have a socket to send to, return 0
|
return result;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// use the node's active socket as the destination socket
|
|
||||||
return sendPacket(std::move(packet), *activeSocket, destinationNode.getConnectionSecret());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr,
|
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiSockAddr& sockAddr,
|
||||||
const QUuid& connectionSecret) {
|
const QUuid& connectionSecret) {
|
||||||
return writePacket(*packet, sockAddr, connectionSecret);
|
// Keep unique_ptr alive during write
|
||||||
|
auto result = writePacket(*packet, sockAddr, connectionSecret);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
||||||
const HifiSockAddr* activeSocket = destinationNode.getActiveSocket();
|
qint64 bytesSent = 0;
|
||||||
if (!activeSocket) {
|
|
||||||
// we don't have a socket to send to, return 0
|
// close the last packet in the list
|
||||||
return 0;
|
packetList.closeCurrentPacket();
|
||||||
|
|
||||||
|
while (!packetList._packets.empty()) {
|
||||||
|
bytesSent += sendPacket(std::move(packetList.takeFront<NLPacket>()), destinationNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// use the node's active socket as the destination socket
|
return bytesSent;
|
||||||
return sendPacketList(packetList, *activeSocket, destinationNode.getConnectionSecret());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const HifiSockAddr& sockAddr,
|
||||||
|
|
|
@ -248,6 +248,7 @@ protected:
|
||||||
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
|
|
||||||
|
qint64 writePacket(const NLPacket& packet, const Node& destinationNode);
|
||||||
qint64 writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr,
|
qint64 writePacket(const NLPacket& packet, const HifiSockAddr& destinationSockAddr,
|
||||||
const QUuid& connectionSecret = QUuid());
|
const QUuid& connectionSecret = QUuid());
|
||||||
qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr);
|
qint64 writeDatagram(const QByteArray& datagram, const HifiSockAddr& destinationSockAddr);
|
||||||
|
|
|
@ -66,7 +66,8 @@ public:
|
||||||
|
|
||||||
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
|
HifiSockAddr& getSenderSockAddr() { return _senderSockAddr; }
|
||||||
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
|
const HifiSockAddr& getSenderSockAddr() const { return _senderSockAddr; }
|
||||||
|
|
||||||
|
void writeSequenceNumber(SequenceNumber seqNum);
|
||||||
SequenceNumber readSequenceNumber() const;
|
SequenceNumber readSequenceNumber() const;
|
||||||
bool readIsControlPacket() const;
|
bool readIsControlPacket() const;
|
||||||
|
|
||||||
|
@ -98,7 +99,6 @@ protected:
|
||||||
|
|
||||||
// Header writers
|
// Header writers
|
||||||
void writePacketTypeAndVersion(PacketType::Value type);
|
void writePacketTypeAndVersion(PacketType::Value type);
|
||||||
void writeSequenceNumber(SequenceNumber seqNum);
|
|
||||||
|
|
||||||
PacketType::Value _type; // Packet type
|
PacketType::Value _type; // Packet type
|
||||||
PacketVersion _version; // Packet version
|
PacketVersion _version; // Packet version
|
||||||
|
|
Loading…
Reference in a new issue