mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 00:13:53 +02:00
Merge pull request #959 from birarda/assignment
assignment cleanup and static DS packet fix
This commit is contained in:
commit
0a762edb14
6 changed files with 23 additions and 94 deletions
|
@ -80,22 +80,11 @@ void childClient() {
|
|||
|
||||
qDebug() << "Received an assignment -" << *deployedAssignment << "\n";
|
||||
|
||||
// switch our nodelist DOMAIN_IP
|
||||
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT ||
|
||||
deployedAssignment->getAttachedPublicSocket()->sa_family == AF_INET) {
|
||||
// switch our nodelist domain IP and port to whoever sent us the assignment
|
||||
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT) {
|
||||
|
||||
|
||||
sockaddr* domainSocket = NULL;
|
||||
|
||||
if (packetData[0] == PACKET_TYPE_CREATE_ASSIGNMENT) {
|
||||
// the domain server IP address is the address we got this packet from
|
||||
domainSocket = (sockaddr*) &senderSocket;
|
||||
} else {
|
||||
// grab the domain server IP address from the packet from the AS
|
||||
domainSocket = (sockaddr*) deployedAssignment->getAttachedPublicSocket();
|
||||
}
|
||||
|
||||
nodeList->setDomainIP(QHostAddress(domainSocket));
|
||||
nodeList->setDomainIP(QHostAddress((sockaddr*) &senderSocket));
|
||||
nodeList->setDomainPort(ntohs(senderSocket.sin_port));
|
||||
|
||||
qDebug("Destination IP for assignment is %s\n", nodeList->getDomainIP().toString().toStdString().c_str());
|
||||
|
||||
|
@ -196,12 +185,19 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
// grab the overriden assignment-server hostname from argv, if it exists
|
||||
const char* customAssignmentServerHostname = getCmdOption(argc, argv, CUSTOM_ASSIGNMENT_SERVER_HOSTNAME_OPTION);
|
||||
const char* customAssignmentServerPortString = getCmdOption(argc, argv, CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION);
|
||||
|
||||
if (customAssignmentServerHostname) {
|
||||
const char* customAssignmentServerPortString = getCmdOption(argc, argv, CUSTOM_ASSIGNMENT_SERVER_PORT_OPTION);
|
||||
if (customAssignmentServerHostname || customAssignmentServerPortString) {
|
||||
|
||||
// set the custom port or default if it wasn't passed
|
||||
unsigned short assignmentServerPort = customAssignmentServerPortString
|
||||
? atoi(customAssignmentServerPortString) : DEFAULT_DOMAIN_SERVER_PORT;
|
||||
|
||||
// set the custom hostname or default if it wasn't passed
|
||||
if (!customAssignmentServerHostname) {
|
||||
customAssignmentServerHostname = LOCAL_ASSIGNMENT_SERVER_HOSTNAME;
|
||||
}
|
||||
|
||||
::customAssignmentSocket = socketForHostnameAndHostOrderPort(customAssignmentServerHostname, assignmentServerPort);
|
||||
}
|
||||
|
||||
|
|
|
@ -367,8 +367,6 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
if (requestAssignment.getType() == Assignment::AllTypes ||
|
||||
(*assignment)->getType() == requestAssignment.getType()) {
|
||||
// attach our local socket to the assignment
|
||||
(*assignment)->setAttachedLocalSocket((sockaddr*) &localSocket);
|
||||
|
||||
// give this assignment out, either the type matches or the requestor said they will take any
|
||||
int numHeaderBytes = populateTypeAndVersion(broadcastPacket, PACKET_TYPE_CREATE_ASSIGNMENT);
|
||||
|
@ -388,14 +386,15 @@ int main(int argc, const char* argv[]) {
|
|||
delete *assignment;
|
||||
}
|
||||
} else {
|
||||
Assignment *sentAssignment = *assignment;
|
||||
// remove the assignment from the queue
|
||||
::assignmentQueue.erase(assignment);
|
||||
|
||||
if ((*assignment)->getType() != Assignment::VoxelServerType) {
|
||||
if (sentAssignment->getType() != Assignment::VoxelServerType) {
|
||||
// keep audio-mixer and avatar-mixer assignments in the queue
|
||||
// until we get a check-in from that GUID
|
||||
// but stick it at the back so the others have a chance to go out
|
||||
::assignmentQueue.push_back(*assignment);
|
||||
::assignmentQueue.push_back(sentAssignment);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,8 +18,6 @@ Assignment::Assignment(Assignment::Command command, Assignment::Type type, Assig
|
|||
_command(command),
|
||||
_type(type),
|
||||
_location(location),
|
||||
_attachedPublicSocket(NULL),
|
||||
_attachedLocalSocket(NULL),
|
||||
_numberOfInstances(1),
|
||||
_payload(NULL),
|
||||
_numPayloadBytes(0)
|
||||
|
@ -35,8 +33,6 @@ Assignment::Assignment(Assignment::Command command, Assignment::Type type, Assig
|
|||
|
||||
Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
||||
_location(GlobalLocation),
|
||||
_attachedPublicSocket(NULL),
|
||||
_attachedLocalSocket(NULL),
|
||||
_numberOfInstances(1),
|
||||
_payload(NULL),
|
||||
_numPayloadBytes(0)
|
||||
|
@ -59,32 +55,11 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
|||
memcpy(&_type, dataBuffer + numBytesRead, sizeof(Assignment::Type));
|
||||
numBytesRead += sizeof(Assignment::Type);
|
||||
|
||||
if (dataBuffer[0] != PACKET_TYPE_REQUEST_ASSIGNMENT) {
|
||||
if (_command != Assignment::RequestCommand) {
|
||||
// read the GUID for this assignment
|
||||
_uuid = QUuid::fromRfc4122(QByteArray((const char*) dataBuffer + numBytesRead, NUM_BYTES_RFC4122_UUID));
|
||||
numBytesRead += NUM_BYTES_RFC4122_UUID;
|
||||
}
|
||||
|
||||
if (_command != Assignment::RequestCommand) {
|
||||
sockaddr* newSocket = NULL;
|
||||
|
||||
if (dataBuffer[numBytesRead++] == IPv4_ADDRESS_DESIGNATOR) {
|
||||
// IPv4 address
|
||||
newSocket = (sockaddr*) new sockaddr_in;
|
||||
numBytesRead += unpackSocket(dataBuffer + numBytesRead, newSocket);
|
||||
|
||||
if (_command == Assignment::CreateCommand) {
|
||||
delete _attachedLocalSocket;
|
||||
_attachedLocalSocket = newSocket;
|
||||
} else {
|
||||
delete _attachedPublicSocket;
|
||||
_attachedPublicSocket = newSocket;
|
||||
}
|
||||
} else {
|
||||
// IPv6 address, or bad designator
|
||||
qDebug("Received a socket that cannot be unpacked!\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (numBytes > numBytesRead) {
|
||||
_numPayloadBytes = numBytes - numBytesRead;
|
||||
|
@ -94,8 +69,6 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
|||
}
|
||||
|
||||
Assignment::~Assignment() {
|
||||
delete _attachedPublicSocket;
|
||||
delete _attachedLocalSocket;
|
||||
delete[] _payload;
|
||||
_numPayloadBytes = 0;
|
||||
}
|
||||
|
@ -123,30 +96,6 @@ QString Assignment::getUUIDStringWithoutCurlyBraces() const {
|
|||
return _uuid.toString().mid(1, _uuid.toString().length() - 2);
|
||||
}
|
||||
|
||||
void Assignment::setAttachedPublicSocket(const sockaddr* attachedPublicSocket) {
|
||||
if (_attachedPublicSocket) {
|
||||
// delete the old socket if it exists
|
||||
delete _attachedPublicSocket;
|
||||
_attachedPublicSocket = NULL;
|
||||
}
|
||||
|
||||
if (attachedPublicSocket) {
|
||||
copySocketToEmptySocketPointer(&_attachedPublicSocket, attachedPublicSocket);
|
||||
}
|
||||
}
|
||||
|
||||
void Assignment::setAttachedLocalSocket(const sockaddr* attachedLocalSocket) {
|
||||
if (_attachedLocalSocket) {
|
||||
// delete the old socket if it exists
|
||||
delete _attachedLocalSocket;
|
||||
_attachedLocalSocket = NULL;
|
||||
}
|
||||
|
||||
if (attachedLocalSocket) {
|
||||
copySocketToEmptySocketPointer(&_attachedLocalSocket, attachedLocalSocket);
|
||||
}
|
||||
}
|
||||
|
||||
int Assignment::packToBuffer(unsigned char* buffer) {
|
||||
int numPackedBytes = 0;
|
||||
|
||||
|
@ -159,19 +108,11 @@ int Assignment::packToBuffer(unsigned char* buffer) {
|
|||
numPackedBytes += NUM_BYTES_RFC4122_UUID;
|
||||
}
|
||||
|
||||
if (_attachedPublicSocket || _attachedLocalSocket) {
|
||||
sockaddr* socketToPack = (_attachedPublicSocket) ? _attachedPublicSocket : _attachedLocalSocket;
|
||||
|
||||
// we have a socket to pack, add the designator
|
||||
buffer[numPackedBytes++] = (socketToPack->sa_family == AF_INET)
|
||||
? IPv4_ADDRESS_DESIGNATOR : IPv6_ADDRESS_DESIGNATOR;
|
||||
|
||||
numPackedBytes += packSocket(buffer + numPackedBytes, socketToPack);
|
||||
}
|
||||
if (_numPayloadBytes) {
|
||||
memcpy(buffer + numPackedBytes, _payload, _numPayloadBytes);
|
||||
numPackedBytes += _numPayloadBytes;
|
||||
}
|
||||
|
||||
return numPackedBytes;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
|
||||
Assignment(Assignment::Command command,
|
||||
Assignment::Type type,
|
||||
Assignment::Location location = Assignment::GlobalLocation);
|
||||
Assignment::Location location = Assignment::LocalLocation);
|
||||
|
||||
/// Constructs an Assignment from the data in the buffer
|
||||
/// \param dataBuffer the source buffer to un-pack the assignment from
|
||||
|
@ -66,12 +66,6 @@ public:
|
|||
int getNumberOfInstances() const { return _numberOfInstances; }
|
||||
void setNumberOfInstances(int numberOfInstances) { _numberOfInstances = numberOfInstances; }
|
||||
void decrementNumberOfInstances() { --_numberOfInstances; }
|
||||
|
||||
const sockaddr* getAttachedPublicSocket() { return _attachedPublicSocket; }
|
||||
void setAttachedPublicSocket(const sockaddr* attachedPublicSocket);
|
||||
|
||||
const sockaddr* getAttachedLocalSocket() { return _attachedLocalSocket; }
|
||||
void setAttachedLocalSocket(const sockaddr* attachedLocalSocket);
|
||||
|
||||
/// Packs the assignment to the passed buffer
|
||||
/// \param buffer the buffer in which to pack the assignment
|
||||
|
@ -89,8 +83,6 @@ private:
|
|||
Assignment::Command _command; /// the command for this assignment (Create, Deploy, Request)
|
||||
Assignment::Type _type; /// the type of the assignment, defines what the assignee will do
|
||||
Assignment::Location _location; /// the location of the assignment, allows a domain to preferentially use local ACs
|
||||
sockaddr* _attachedPublicSocket; /// pointer to a public socket that relates to assignment, depends on direction
|
||||
sockaddr* _attachedLocalSocket; /// pointer to a local socket that relates to assignment, depends on direction
|
||||
timeval _time; /// time the assignment was created (set in constructor)
|
||||
int _numberOfInstances; /// the number of instances of this assignment
|
||||
uchar *_payload; /// an optional payload attached to this assignment, a maximum for 1024 bytes will be packed
|
||||
|
|
|
@ -304,8 +304,8 @@ void NodeList::sendDomainServerCheckIn(const char* assignmentUUID) {
|
|||
printedDomainServerIP = true;
|
||||
}
|
||||
|
||||
static unsigned char* checkInPacket = NULL;
|
||||
static int checkInPacketSize = 0;
|
||||
unsigned char* checkInPacket = NULL;
|
||||
int checkInPacketSize = 0;
|
||||
|
||||
// construct the DS check in packet if we need to
|
||||
if (!checkInPacket) {
|
||||
|
@ -398,7 +398,6 @@ int NodeList::processDomainServerList(unsigned char* packetData, size_t dataByte
|
|||
return readNodes;
|
||||
}
|
||||
|
||||
const char LOCAL_ASSIGNMENT_SERVER_HOSTNAME[] = "localhost";
|
||||
const sockaddr_in DEFAULT_LOCAL_ASSIGNMENT_SOCKET = socketForHostnameAndHostOrderPort(LOCAL_ASSIGNMENT_SERVER_HOSTNAME,
|
||||
DEFAULT_DOMAIN_SERVER_PORT);
|
||||
void NodeList::sendAssignment(Assignment& assignment) {
|
||||
|
|
|
@ -40,6 +40,8 @@ const int MAX_HOSTNAME_BYTES = 256;
|
|||
extern const QString DEFAULT_DOMAIN_HOSTNAME;
|
||||
extern const unsigned short DEFAULT_DOMAIN_SERVER_PORT;
|
||||
|
||||
const char LOCAL_ASSIGNMENT_SERVER_HOSTNAME[] = "localhost";
|
||||
|
||||
const int UNKNOWN_NODE_ID = 0;
|
||||
|
||||
const int MAX_SILENT_DOMAIN_SERVER_CHECK_INS = 5;
|
||||
|
|
Loading…
Reference in a new issue