mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:38:02 +02:00
add a domain socket to assignments
This commit is contained in:
parent
94367dd7c7
commit
fa7f183930
6 changed files with 58 additions and 12 deletions
|
@ -61,7 +61,9 @@ int main(int argc, char* const argv[]) {
|
||||||
|
|
||||||
qDebug() << "Received an assignment - " << assignmentType << "\n";
|
qDebug() << "Received an assignment - " << assignmentType << "\n";
|
||||||
|
|
||||||
AudioMixer::run();
|
// pull the creator sockaddr_in from the assignment and change our domain IP to that
|
||||||
|
|
||||||
|
// AudioMixer::run();
|
||||||
|
|
||||||
// reset our NodeList by switching back to unassigned and clearing the list
|
// reset our NodeList by switching back to unassigned and clearing the list
|
||||||
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
|
nodeList->setOwnerType(NODE_TYPE_UNASSIGNED);
|
||||||
|
|
|
@ -30,7 +30,7 @@ int main(int argc, const char* argv[]) {
|
||||||
UDPSocket serverSocket(ASSIGNMENT_SERVER_PORT);
|
UDPSocket serverSocket(ASSIGNMENT_SERVER_PORT);
|
||||||
|
|
||||||
unsigned char assignmentPacket[MAX_PACKET_SIZE_BYTES];
|
unsigned char assignmentPacket[MAX_PACKET_SIZE_BYTES];
|
||||||
int numSendHeaderBytes = populateTypeAndVersion(assignmentPacket, PACKET_TYPE_CREATE_ASSIGNMENT);
|
int numSendHeaderBytes = populateTypeAndVersion(assignmentPacket, PACKET_TYPE_DEPLOY_ASSIGNMENT);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (serverSocket.receive((sockaddr*) &senderSocket, &senderData, &receivedBytes)) {
|
if (serverSocket.receive((sockaddr*) &senderSocket, &senderData, &receivedBytes)) {
|
||||||
|
@ -42,26 +42,30 @@ int main(int argc, const char* argv[]) {
|
||||||
Assignment firstAssignment = assignmentQueue.front();
|
Assignment firstAssignment = assignmentQueue.front();
|
||||||
assignmentQueue.pop();
|
assignmentQueue.pop();
|
||||||
|
|
||||||
*(assignmentPacket + numSendHeaderBytes) = firstAssignment.getType();
|
int numAssignmentBytes = firstAssignment.packToBuffer(assignmentPacket + numSendHeaderBytes);
|
||||||
|
|
||||||
|
|
||||||
// send the assignment
|
// send the assignment
|
||||||
serverSocket.send((sockaddr*) &senderSocket, assignmentPacket, numSendHeaderBytes + sizeof(unsigned char));
|
serverSocket.send((sockaddr*) &senderSocket, assignmentPacket, numSendHeaderBytes + numAssignmentBytes);
|
||||||
}
|
}
|
||||||
} else if (senderData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(senderData)) {
|
} else if (senderData[0] == PACKET_TYPE_CREATE_ASSIGNMENT && packetVersionMatch(senderData)) {
|
||||||
// memcpy the sent assignment
|
// memcpy the sent assignment
|
||||||
Assignment createdAssignment(senderData + numBytesForPacketHeader(senderData));
|
int numHeaderBytes = numBytesForPacketHeader(senderData);
|
||||||
|
Assignment createdAssignment(senderData + numHeaderBytes, receivedBytes - numHeaderBytes);
|
||||||
|
|
||||||
qDebug() << "Received an assignment:" << createdAssignment;
|
qDebug() << "Received an assignment:" << createdAssignment;
|
||||||
|
|
||||||
// assignment server is on a public server
|
// assignment server is on a public server
|
||||||
// assume that the address we now have for the sender is the public address/port
|
// assume that the address we now have for the sender is the public address/port
|
||||||
// and store that with the assignment so it can be given to the requestor later
|
// and store that with the assignment so it can be given to the requestor later
|
||||||
|
createdAssignment.setDomainSocket((sockaddr*) &senderSocket);
|
||||||
|
|
||||||
|
// until we have a GUID setup just keep the latest assignment
|
||||||
|
if (assignmentQueue.size() > 0) {
|
||||||
|
assignmentQueue.pop();
|
||||||
|
}
|
||||||
|
|
||||||
// add this assignment to the queue
|
// add this assignment to the queue
|
||||||
// assignmentQueue.push(newAssignment);
|
assignmentQueue.push(createdAssignment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
|
|
||||||
Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool) :
|
Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool) :
|
||||||
_direction(direction),
|
_direction(direction),
|
||||||
_type(type)
|
_type(type),
|
||||||
|
_domainSocket(NULL)
|
||||||
{
|
{
|
||||||
// copy the pool, if we got one
|
// copy the pool, if we got one
|
||||||
if (pool) {
|
if (pool) {
|
||||||
|
@ -22,7 +23,9 @@ Assignment::Assignment(Assignment::Direction direction, Assignment::Type type, c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Assignment::Assignment(const unsigned char* dataBuffer) {
|
Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||||
|
_domainSocket(NULL)
|
||||||
|
{
|
||||||
int numBytesRead = 0;
|
int numBytesRead = 0;
|
||||||
|
|
||||||
memcpy(&_direction, dataBuffer, sizeof(Assignment::Direction));
|
memcpy(&_direction, dataBuffer, sizeof(Assignment::Direction));
|
||||||
|
@ -34,6 +37,11 @@ Assignment::Assignment(const unsigned char* dataBuffer) {
|
||||||
int poolLength = strlen((const char*) dataBuffer + numBytesRead);
|
int poolLength = strlen((const char*) dataBuffer + numBytesRead);
|
||||||
_pool = new char[poolLength + sizeof(char)];
|
_pool = new char[poolLength + sizeof(char)];
|
||||||
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
strcpy(_pool, (char*) dataBuffer + numBytesRead);
|
||||||
|
numBytesRead += poolLength + sizeof(char);
|
||||||
|
|
||||||
|
if (numBytes > numBytesRead) {
|
||||||
|
memcpy(_domainSocket, dataBuffer + numBytesRead, sizeof(sockaddr));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Assignment::packToBuffer(unsigned char* buffer) {
|
int Assignment::packToBuffer(unsigned char* buffer) {
|
||||||
|
@ -48,9 +56,36 @@ int Assignment::packToBuffer(unsigned char* buffer) {
|
||||||
strcpy((char*) buffer + numPackedBytes, _pool);
|
strcpy((char*) buffer + numPackedBytes, _pool);
|
||||||
numPackedBytes += strlen(_pool) + sizeof(char);
|
numPackedBytes += strlen(_pool) + sizeof(char);
|
||||||
|
|
||||||
|
if (_domainSocket) {
|
||||||
|
memcpy(buffer + numPackedBytes, _domainSocket, sizeof(sockaddr));
|
||||||
|
numPackedBytes += sizeof(sockaddr);
|
||||||
|
}
|
||||||
|
|
||||||
return numPackedBytes;
|
return numPackedBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Assignment::setDomainSocket(const sockaddr* domainSocket) {
|
||||||
|
|
||||||
|
if (_domainSocket) {
|
||||||
|
// delete the old _domainSocket if it exists
|
||||||
|
delete _domainSocket;
|
||||||
|
_domainSocket = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_domainSocket) {
|
||||||
|
// create a new sockaddr or sockaddr_in depending on what type of address this is
|
||||||
|
if (domainSocket->sa_family == AF_INET) {
|
||||||
|
sockaddr_in* newSocket = new sockaddr_in;
|
||||||
|
memcpy(newSocket, domainSocket, sizeof(sockaddr_in));
|
||||||
|
_domainSocket = (sockaddr*) newSocket;
|
||||||
|
} else {
|
||||||
|
sockaddr_in6* newSocket = new sockaddr_in6;
|
||||||
|
memcpy(newSocket, domainSocket, sizeof(sockaddr_in6));
|
||||||
|
_domainSocket = (sockaddr*) newSocket;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const Assignment &assignment) {
|
QDebug operator<<(QDebug debug, const Assignment &assignment) {
|
||||||
debug << "T:" << assignment.getType() << "P:" << assignment.getPool();
|
debug << "T:" << assignment.getType() << "P:" << assignment.getPool();
|
||||||
return debug.nospace();
|
return debug.nospace();
|
||||||
|
|
|
@ -25,18 +25,22 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool = NULL);
|
Assignment(Assignment::Direction direction, Assignment::Type type, const char* pool = NULL);
|
||||||
Assignment(const unsigned char* dataBuffer);
|
Assignment(const unsigned char* dataBuffer, int numBytes);
|
||||||
|
|
||||||
Assignment::Direction getDirection() const { return _direction; }
|
Assignment::Direction getDirection() const { return _direction; }
|
||||||
Assignment::Type getType() const { return _type; }
|
Assignment::Type getType() const { return _type; }
|
||||||
const char* getPool() const { return _pool; }
|
const char* getPool() const { return _pool; }
|
||||||
|
|
||||||
|
const sockaddr* getDomainSocket() { return _domainSocket; }
|
||||||
|
void setDomainSocket(const sockaddr* domainSocket);
|
||||||
|
|
||||||
int packToBuffer(unsigned char* buffer);
|
int packToBuffer(unsigned char* buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Assignment::Direction _direction;
|
Assignment::Direction _direction;
|
||||||
Assignment::Type _type;
|
Assignment::Type _type;
|
||||||
char* _pool;
|
char* _pool;
|
||||||
|
sockaddr* _domainSocket;
|
||||||
};
|
};
|
||||||
|
|
||||||
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
QDebug operator<<(QDebug debug, const Assignment &assignment);
|
||||||
|
|
|
@ -31,7 +31,7 @@ const char SOLO_NODE_TYPES[2] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io";
|
const char DEFAULT_DOMAIN_HOSTNAME[MAX_HOSTNAME_BYTES] = "root.highfidelity.io";
|
||||||
const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN] = "10.0.0.20"; // IP Address will be re-set by lookup on startup
|
const char DEFAULT_DOMAIN_IP[INET_ADDRSTRLEN] = ""; // IP Address will be re-set by lookup on startup
|
||||||
const int DEFAULT_DOMAINSERVER_PORT = 40102;
|
const int DEFAULT_DOMAINSERVER_PORT = 40102;
|
||||||
|
|
||||||
bool silentNodeThreadStopFlag = false;
|
bool silentNodeThreadStopFlag = false;
|
||||||
|
|
|
@ -37,6 +37,7 @@ const PACKET_TYPE PACKET_TYPE_DOMAIN_LIST_REQUEST = 'L';
|
||||||
const PACKET_TYPE PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY = 'C';
|
const PACKET_TYPE PACKET_TYPE_DOMAIN_REPORT_FOR_DUTY = 'C';
|
||||||
const PACKET_TYPE PACKET_TYPE_REQUEST_ASSIGNMENT = 'r';
|
const PACKET_TYPE PACKET_TYPE_REQUEST_ASSIGNMENT = 'r';
|
||||||
const PACKET_TYPE PACKET_TYPE_CREATE_ASSIGNMENT = 's';
|
const PACKET_TYPE PACKET_TYPE_CREATE_ASSIGNMENT = 's';
|
||||||
|
const PACKET_TYPE PACKET_TYPE_DEPLOY_ASSIGNMENT = 'd';
|
||||||
const PACKET_TYPE PACKET_TYPE_VOXEL_STATS = '#';
|
const PACKET_TYPE PACKET_TYPE_VOXEL_STATS = '#';
|
||||||
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION = 'J';
|
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION = 'J';
|
||||||
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION_REQUEST = 'j';
|
const PACKET_TYPE PACKET_TYPE_VOXEL_JURISDICTION_REQUEST = 'j';
|
||||||
|
|
Loading…
Reference in a new issue