diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 270608d07c..9e375e7d87 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -480,7 +480,8 @@ int DomainServer::run() { unsigned char* currentBufferPos; unsigned char* startPointer; - sockaddr_in nodePublicAddress, nodeLocalAddress, replyDestinationSocket; + sockaddr_in senderAddress, nodePublicAddress, nodeLocalAddress; + nodePublicAddress.sin_family = AF_INET; nodeLocalAddress.sin_family = AF_INET; in_addr_t serverLocalAddress = getLocalAddress(); @@ -507,7 +508,7 @@ int DomainServer::run() { gettimeofday(&startTime, NULL); while (true) { - while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) && + while (nodeList->getNodeSocket()->receive((sockaddr *)&senderAddress, packetData, &receivedBytes) && packetVersionMatch(packetData)) { if (packetData[0] == PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY || packetData[0] == PACKET_TYPE_DOMAIN_LIST_REQUEST) { // this is an RFD or domain list request packet, and there is a version match @@ -515,19 +516,14 @@ int DomainServer::run() { int numBytesSenderHeader = numBytesForPacketHeader(packetData); nodeType = *(packetData + numBytesSenderHeader); - int numBytesSocket = unpackSocket(packetData + numBytesSenderHeader + sizeof(NODE_TYPE), - (sockaddr*) &nodeLocalAddress); - replyDestinationSocket = nodePublicAddress; + int packetIndex = numBytesSenderHeader + sizeof(NODE_TYPE) + NUM_BYTES_RFC4122_UUID; - // check the node public address - // if it matches our local address - // or if it's the loopback address we're on the same box - if (nodePublicAddress.sin_addr.s_addr == serverLocalAddress || - nodePublicAddress.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) { - - nodePublicAddress.sin_addr.s_addr = 0; - } + int numBytesPrivateSocket = unpackSocket(packetData + packetIndex, (sockaddr*) &nodePublicAddress); + packetIndex += numBytesPrivateSocket; + + int numBytesPublicSocket = unpackSocket(packetData + packetIndex, (sockaddr*) &nodeLocalAddress); + packetIndex += numBytesPublicSocket; const char STATICALLY_ASSIGNED_NODES[3] = { NODE_TYPE_AUDIO_MIXER, @@ -568,12 +564,7 @@ int DomainServer::run() { currentBufferPos = broadcastPacket + numHeaderBytes; startPointer = currentBufferPos; - int numBytesUUID = (nodeType == NODE_TYPE_AUDIO_MIXER || nodeType == NODE_TYPE_AVATAR_MIXER) - ? NUM_BYTES_RFC4122_UUID - : 0; - - unsigned char* nodeTypesOfInterest = packetData + numBytesSenderHeader + numBytesUUID + - sizeof(NODE_TYPE) + numBytesSocket + sizeof(unsigned char); + unsigned char* nodeTypesOfInterest = packetData + packetIndex + sizeof(unsigned char); int numInterestTypes = *(nodeTypesOfInterest - 1); if (numInterestTypes > 0) { @@ -599,7 +590,7 @@ int DomainServer::run() { currentBufferPos += packNodeId(currentBufferPos, checkInNode->getNodeID()); // send the constructed list back to this node - nodeList->getNodeSocket()->send((sockaddr*)&replyDestinationSocket, + nodeList->getNodeSocket()->send((sockaddr*)&senderAddress, broadcastPacket, (currentBufferPos - startPointer) + numHeaderBytes); } diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index 0ab4e7ab00..1a0167ee59 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -444,7 +444,8 @@ void NodeList::sendDomainServerCheckIn(const char* assignmentUUID) { // check in packet has header, optional UUID, node type, port, IP, node types of interest, null termination int numPacketBytes = sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION) + sizeof(NODE_TYPE) + - NUM_BYTES_RFC4122_UUID + sizeof(uint16_t) + IP_ADDRESS_BYTES + numBytesNodesOfInterest + sizeof(unsigned char); + NUM_BYTES_RFC4122_UUID + (2 * (sizeof(uint16_t) + IP_ADDRESS_BYTES)) + + numBytesNodesOfInterest + sizeof(unsigned char); _checkInPacket = new unsigned char[numPacketBytes]; unsigned char* packetPosition = _checkInPacket; @@ -453,17 +454,24 @@ void NodeList::sendDomainServerCheckIn(const char* assignmentUUID) { ? PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY : PACKET_TYPE_DOMAIN_LIST_REQUEST; - int numHeaderBytes = populateTypeAndVersion(packetPosition, nodePacketType); - packetPosition += numHeaderBytes; + packetPosition += populateTypeAndVersion(packetPosition, nodePacketType); *(packetPosition++) = _ownerType; - if (assignmentUUID) { - // if we've got an assignment UUID to send add that here - memcpy(packetPosition, assignmentUUID, NUM_BYTES_RFC4122_UUID); - packetPosition += NUM_BYTES_RFC4122_UUID; + if (!assignmentUUID) { + // if we don't have an assignment UUID just send the null one + assignmentUUID = QUuid().toRfc4122().constData(); } + // send our assignment UUID or the null one + memcpy(packetPosition, assignmentUUID, NUM_BYTES_RFC4122_UUID); + packetPosition += NUM_BYTES_RFC4122_UUID; + + // pack our public address to send to domain-server + packetPosition += packSocket(_checkInPacket + (packetPosition - _checkInPacket), + htonl(_publicAddress.toIPv4Address()), htons(_publicPort)); + + // pack our local address to send to domain-server packetPosition += packSocket(_checkInPacket + (packetPosition - _checkInPacket), getLocalAddress(), htons(_nodeSocket.getListeningPort())); diff --git a/libraries/shared/src/PacketHeaders.cpp b/libraries/shared/src/PacketHeaders.cpp index a1320e84b8..8075099164 100644 --- a/libraries/shared/src/PacketHeaders.cpp +++ b/libraries/shared/src/PacketHeaders.cpp @@ -30,6 +30,11 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) { case PACKET_TYPE_VOXEL_STATS: return 2; + + case PACKET_TYPE_DOMAIN_LIST_REQUEST: + case PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY: + return 1; + default: return 0; }