mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 11:35:20 +02:00
protect LNL packet sending without active socket
This commit is contained in:
parent
2b07daa976
commit
7dfdb3c72e
1 changed files with 28 additions and 11 deletions
|
@ -299,14 +299,16 @@ 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) {
|
||||||
Q_ASSERT(!packet->isPartOfMessage());
|
Q_ASSERT(!packet->isPartOfMessage());
|
||||||
if (!destinationNode.getActiveSocket()) {
|
auto activeSocket = destinationNode.getActiveSocket();
|
||||||
|
if (!activeSocket) {
|
||||||
|
qDebug() << "LimitedNodeList::sendPacket called without active socket for node" << destinationNode << "- not sending";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit dataSent(destinationNode.getType(), packet->getDataSize());
|
emit dataSent(destinationNode.getType(), packet->getDataSize());
|
||||||
destinationNode.recordBytesSent(packet->getDataSize());
|
destinationNode.recordBytesSent(packet->getDataSize());
|
||||||
|
|
||||||
return sendPacket(std::move(packet), *destinationNode.getActiveSocket(), destinationNode.getConnectionSecret());
|
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,
|
||||||
|
@ -328,8 +330,11 @@ qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const HifiS
|
||||||
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacketList(NLPacketList& packetList, const Node& destinationNode) {
|
||||||
auto activeSocket = destinationNode.getActiveSocket();
|
auto activeSocket = destinationNode.getActiveSocket();
|
||||||
if (!activeSocket) {
|
if (!activeSocket) {
|
||||||
|
qDebug() << "LimitedNodeList::sendPacketList called without active socket for node" << destinationNode
|
||||||
|
<< " - not sending.";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 bytesSent = 0;
|
qint64 bytesSent = 0;
|
||||||
auto connectionSecret = destinationNode.getConnectionSecret();
|
auto connectionSecret = destinationNode.getConnectionSecret();
|
||||||
|
|
||||||
|
@ -372,6 +377,8 @@ qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList,
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList, const Node& destinationNode) {
|
qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList, const Node& destinationNode) {
|
||||||
|
auto activeSocket = destinationNode.getActiveSocket();
|
||||||
|
if (!activeSocket) {
|
||||||
// close the last packet in the list
|
// close the last packet in the list
|
||||||
packetList->closeCurrentPacket();
|
packetList->closeCurrentPacket();
|
||||||
|
|
||||||
|
@ -381,14 +388,24 @@ qint64 LimitedNodeList::sendPacketList(std::unique_ptr<NLPacketList> packetList,
|
||||||
fillPacketHeader(*nlPacket, destinationNode.getConnectionSecret());
|
fillPacketHeader(*nlPacket, destinationNode.getConnectionSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
return _nodeSocket.writePacketList(std::move(packetList), *destinationNode.getActiveSocket());
|
return _nodeSocket.writePacketList(std::move(packetList), *activeSocket);
|
||||||
|
} else {
|
||||||
|
qCDebug(networking) << "LimitedNodeList::sendPacketList called without active socket for node. Not sending.";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode,
|
qint64 LimitedNodeList::sendPacket(std::unique_ptr<NLPacket> packet, const Node& destinationNode,
|
||||||
const HifiSockAddr& overridenSockAddr) {
|
const HifiSockAddr& overridenSockAddr) {
|
||||||
|
if (!overridenSockAddr.isNull() && !destinationNode.getActiveSocket()) {
|
||||||
|
qCDebug(networking) << "LimitedNodeList::sendPacket called without active socket for node. Not sending.";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// use the node's active socket as the destination socket if there is no overriden socket address
|
// use the node's active socket as the destination socket if there is no overriden socket address
|
||||||
auto& destinationSockAddr = (overridenSockAddr.isNull()) ? *destinationNode.getActiveSocket()
|
auto& destinationSockAddr = (overridenSockAddr.isNull()) ? *destinationNode.getActiveSocket()
|
||||||
: overridenSockAddr;
|
: overridenSockAddr;
|
||||||
|
|
||||||
return sendPacket(std::move(packet), destinationSockAddr, destinationNode.getConnectionSecret());
|
return sendPacket(std::move(packet), destinationSockAddr, destinationNode.getConnectionSecret());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue