mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 02:52:57 +02:00
domain server accepts custom public address from node
This commit is contained in:
parent
f581d4d976
commit
224b0d9671
3 changed files with 31 additions and 27 deletions
|
@ -480,7 +480,8 @@ int DomainServer::run() {
|
||||||
unsigned char* currentBufferPos;
|
unsigned char* currentBufferPos;
|
||||||
unsigned char* startPointer;
|
unsigned char* startPointer;
|
||||||
|
|
||||||
sockaddr_in nodePublicAddress, nodeLocalAddress, replyDestinationSocket;
|
sockaddr_in senderAddress, nodePublicAddress, nodeLocalAddress;
|
||||||
|
nodePublicAddress.sin_family = AF_INET;
|
||||||
nodeLocalAddress.sin_family = AF_INET;
|
nodeLocalAddress.sin_family = AF_INET;
|
||||||
|
|
||||||
in_addr_t serverLocalAddress = getLocalAddress();
|
in_addr_t serverLocalAddress = getLocalAddress();
|
||||||
|
@ -507,7 +508,7 @@ int DomainServer::run() {
|
||||||
gettimeofday(&startTime, NULL);
|
gettimeofday(&startTime, NULL);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
while (nodeList->getNodeSocket()->receive((sockaddr *)&nodePublicAddress, packetData, &receivedBytes) &&
|
while (nodeList->getNodeSocket()->receive((sockaddr *)&senderAddress, packetData, &receivedBytes) &&
|
||||||
packetVersionMatch(packetData)) {
|
packetVersionMatch(packetData)) {
|
||||||
if (packetData[0] == PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY || packetData[0] == PACKET_TYPE_DOMAIN_LIST_REQUEST) {
|
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
|
// 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);
|
int numBytesSenderHeader = numBytesForPacketHeader(packetData);
|
||||||
|
|
||||||
nodeType = *(packetData + numBytesSenderHeader);
|
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
|
int numBytesPrivateSocket = unpackSocket(packetData + packetIndex, (sockaddr*) &nodePublicAddress);
|
||||||
// if it matches our local address
|
packetIndex += numBytesPrivateSocket;
|
||||||
// or if it's the loopback address we're on the same box
|
|
||||||
if (nodePublicAddress.sin_addr.s_addr == serverLocalAddress ||
|
int numBytesPublicSocket = unpackSocket(packetData + packetIndex, (sockaddr*) &nodeLocalAddress);
|
||||||
nodePublicAddress.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) {
|
packetIndex += numBytesPublicSocket;
|
||||||
|
|
||||||
nodePublicAddress.sin_addr.s_addr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char STATICALLY_ASSIGNED_NODES[3] = {
|
const char STATICALLY_ASSIGNED_NODES[3] = {
|
||||||
NODE_TYPE_AUDIO_MIXER,
|
NODE_TYPE_AUDIO_MIXER,
|
||||||
|
@ -568,12 +564,7 @@ int DomainServer::run() {
|
||||||
currentBufferPos = broadcastPacket + numHeaderBytes;
|
currentBufferPos = broadcastPacket + numHeaderBytes;
|
||||||
startPointer = currentBufferPos;
|
startPointer = currentBufferPos;
|
||||||
|
|
||||||
int numBytesUUID = (nodeType == NODE_TYPE_AUDIO_MIXER || nodeType == NODE_TYPE_AVATAR_MIXER)
|
unsigned char* nodeTypesOfInterest = packetData + packetIndex + sizeof(unsigned char);
|
||||||
? NUM_BYTES_RFC4122_UUID
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
unsigned char* nodeTypesOfInterest = packetData + numBytesSenderHeader + numBytesUUID +
|
|
||||||
sizeof(NODE_TYPE) + numBytesSocket + sizeof(unsigned char);
|
|
||||||
int numInterestTypes = *(nodeTypesOfInterest - 1);
|
int numInterestTypes = *(nodeTypesOfInterest - 1);
|
||||||
|
|
||||||
if (numInterestTypes > 0) {
|
if (numInterestTypes > 0) {
|
||||||
|
@ -599,7 +590,7 @@ int DomainServer::run() {
|
||||||
currentBufferPos += packNodeId(currentBufferPos, checkInNode->getNodeID());
|
currentBufferPos += packNodeId(currentBufferPos, checkInNode->getNodeID());
|
||||||
|
|
||||||
// send the constructed list back to this node
|
// send the constructed list back to this node
|
||||||
nodeList->getNodeSocket()->send((sockaddr*)&replyDestinationSocket,
|
nodeList->getNodeSocket()->send((sockaddr*)&senderAddress,
|
||||||
broadcastPacket,
|
broadcastPacket,
|
||||||
(currentBufferPos - startPointer) + numHeaderBytes);
|
(currentBufferPos - startPointer) + numHeaderBytes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
// 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) +
|
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];
|
_checkInPacket = new unsigned char[numPacketBytes];
|
||||||
unsigned char* packetPosition = _checkInPacket;
|
unsigned char* packetPosition = _checkInPacket;
|
||||||
|
@ -453,17 +454,24 @@ void NodeList::sendDomainServerCheckIn(const char* assignmentUUID) {
|
||||||
? PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY
|
? PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY
|
||||||
: PACKET_TYPE_DOMAIN_LIST_REQUEST;
|
: PACKET_TYPE_DOMAIN_LIST_REQUEST;
|
||||||
|
|
||||||
int numHeaderBytes = populateTypeAndVersion(packetPosition, nodePacketType);
|
packetPosition += populateTypeAndVersion(packetPosition, nodePacketType);
|
||||||
packetPosition += numHeaderBytes;
|
|
||||||
|
|
||||||
*(packetPosition++) = _ownerType;
|
*(packetPosition++) = _ownerType;
|
||||||
|
|
||||||
if (assignmentUUID) {
|
if (!assignmentUUID) {
|
||||||
// if we've got an assignment UUID to send add that here
|
// if we don't have an assignment UUID just send the null one
|
||||||
memcpy(packetPosition, assignmentUUID, NUM_BYTES_RFC4122_UUID);
|
assignmentUUID = QUuid().toRfc4122().constData();
|
||||||
packetPosition += NUM_BYTES_RFC4122_UUID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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),
|
packetPosition += packSocket(_checkInPacket + (packetPosition - _checkInPacket),
|
||||||
getLocalAddress(),
|
getLocalAddress(),
|
||||||
htons(_nodeSocket.getListeningPort()));
|
htons(_nodeSocket.getListeningPort()));
|
||||||
|
|
|
@ -30,6 +30,11 @@ PACKET_VERSION versionForPacketType(PACKET_TYPE type) {
|
||||||
|
|
||||||
case PACKET_TYPE_VOXEL_STATS:
|
case PACKET_TYPE_VOXEL_STATS:
|
||||||
return 2;
|
return 2;
|
||||||
|
|
||||||
|
case PACKET_TYPE_DOMAIN_LIST_REQUEST:
|
||||||
|
case PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY:
|
||||||
|
return 1;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue