From f652df939966731edcce1c8bd88fea2c3016e82e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 17 Mar 2014 09:19:05 -0700 Subject: [PATCH] break on MTU size packets from domain-list, closes #2312 --- domain-server/src/DomainServer.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index a425052970..216d249858 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -423,17 +423,25 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif QDataStream broadcastDataStream(&broadcastPacket, QIODevice::Append); broadcastDataStream << node->getUUID(); + int numBroadcastPacketLeadBytes = broadcastDataStream.device()->pos(); + DomainServerNodeData* nodeData = reinterpret_cast(node->getLinkedData()); NodeList* nodeList = NodeList::getInstance(); + if (nodeInterestList.size() > 0) { // if the node has any interest types, send back those nodes as well foreach (const SharedNodePointer& otherNode, nodeList->getNodeHash()) { + + // reset our nodeByteArray and nodeDataStream + QByteArray nodeByteArray; + QDataStream nodeDataStream(&nodeByteArray, QIODevice::Append); + if (otherNode->getUUID() != node->getUUID() && nodeInterestList.contains(otherNode->getType())) { // don't send avatar nodes to other avatars, that will come from avatar mixer - broadcastDataStream << *otherNode.data(); + nodeDataStream << *otherNode.data(); // pack the secret that these two nodes will use to communicate with each other QUuid secretUUID = nodeData->getSessionSecretHash().value(otherNode->getUUID()); @@ -450,11 +458,26 @@ void DomainServer::sendDomainListToNode(const SharedNodePointer& node, const Hif } - broadcastDataStream << secretUUID; + nodeDataStream << secretUUID; + + if (broadcastPacket.size() + nodeByteArray.size() > MAX_PACKET_SIZE) { + // we need to break here and start a new packet + // so send the current one + + nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); + + // reset the broadcastPacket structure + broadcastPacket.resize(numBroadcastPacketLeadBytes); + broadcastDataStream.device()->seek(numBroadcastPacketLeadBytes); + } + + // append the nodeByteArray to the current state of broadcastDataStream + broadcastPacket.append(nodeByteArray); } } } + // always write the last broadcastPacket nodeList->writeDatagram(broadcastPacket, node, senderSockAddr); }