mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-04-10 10:34:56 +02:00
handle case where AC is on same network as DS but not AS
This commit is contained in:
parent
e53807ca82
commit
fa521a5dc9
5 changed files with 41 additions and 15 deletions
|
@ -68,6 +68,15 @@ int main(int argc, const char* argv[]) {
|
|||
&& strcmp((*assignment)->getPool(), requestAssignment.getPool()) == 0)
|
||||
|| !eitherHasPool) {
|
||||
|
||||
// check if the requestor is on the same network as the destination for the assignment
|
||||
if (senderSocket.sin_addr.s_addr ==
|
||||
((sockaddr_in*) (*assignment)->getAttachedPublicSocket())->sin_addr.s_addr) {
|
||||
// if this is the case we remove the public socket on the assignment by setting it to NULL
|
||||
// this ensures the local IP and port sent to the requestor is the local address of destination
|
||||
(*assignment)->setAttachedPublicSocket(NULL);
|
||||
}
|
||||
|
||||
|
||||
int numAssignmentBytes = (*assignment)->packToBuffer(assignmentPacket + numSendHeaderBytes);
|
||||
|
||||
// send the assignment
|
||||
|
|
|
@ -106,6 +106,12 @@ int main(int argc, const char* argv[]) {
|
|||
Assignment* audioAssignment = NULL;
|
||||
Assignment* avatarAssignment = NULL;
|
||||
|
||||
// construct a local socket to send with our created assignments
|
||||
sockaddr_in localSocket = {};
|
||||
localSocket.sin_family = AF_INET;
|
||||
localSocket.sin_port = htons(nodeList->getInstance()->getNodeSocket()->getListeningPort());
|
||||
localSocket.sin_addr.s_addr = serverLocalAddress;
|
||||
|
||||
while (true) {
|
||||
if (!nodeList->soloNodeOfType(NODE_TYPE_AUDIO_MIXER)) {
|
||||
if (!audioAssignment
|
||||
|
@ -113,6 +119,7 @@ int main(int argc, const char* argv[]) {
|
|||
|
||||
if (!audioAssignment) {
|
||||
audioAssignment = new Assignment(Assignment::Create, Assignment::AudioMixer, assignmentPool);
|
||||
audioAssignment->setAttachedLocalSocket((sockaddr*) &localSocket);
|
||||
}
|
||||
|
||||
nodeList->sendAssignment(*audioAssignment);
|
||||
|
@ -125,6 +132,7 @@ int main(int argc, const char* argv[]) {
|
|||
|| usecTimestampNow() - usecTimestamp(&avatarAssignment->getTime()) >= ASSIGNMENT_SILENCE_MAX_USECS) {
|
||||
if (!avatarAssignment) {
|
||||
avatarAssignment = new Assignment(Assignment::Create, Assignment::AvatarMixer, assignmentPool);
|
||||
avatarAssignment->setAttachedLocalSocket((sockaddr*) &localSocket);
|
||||
}
|
||||
|
||||
nodeList->sendAssignment(*avatarAssignment);
|
||||
|
|
|
@ -67,19 +67,24 @@ Assignment::Assignment(const unsigned char* dataBuffer, int numBytes) :
|
|||
|
||||
if (numBytes > numBytesRead) {
|
||||
|
||||
sockaddr* socketDestination = (_direction == Assignment::Create)
|
||||
? _attachedLocalSocket
|
||||
: _attachedPublicSocket;
|
||||
sockaddr* newSocket = NULL;
|
||||
|
||||
if (dataBuffer[numBytesRead++] == IPv4_ADDRESS_DESIGNATOR) {
|
||||
// IPv4 address
|
||||
delete socketDestination;
|
||||
socketDestination = (sockaddr*) new sockaddr_in;
|
||||
unpackSocket(dataBuffer + numBytesRead, socketDestination);
|
||||
newSocket = (sockaddr*) new sockaddr_in;
|
||||
unpackSocket(dataBuffer + numBytesRead, newSocket);
|
||||
} else {
|
||||
// IPv6 address, or bad designator
|
||||
qDebug("Received a socket that cannot be unpacked!\n");
|
||||
}
|
||||
|
||||
if (_direction == Assignment::Create) {
|
||||
delete _attachedLocalSocket;
|
||||
_attachedLocalSocket = newSocket;
|
||||
} else {
|
||||
delete _attachedPublicSocket;
|
||||
_attachedPublicSocket = newSocket;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,14 +95,15 @@ Assignment::~Assignment() {
|
|||
}
|
||||
|
||||
void Assignment::setAttachedPublicSocket(const sockaddr* attachedPublicSocket) {
|
||||
|
||||
if (_attachedPublicSocket) {
|
||||
// delete the old socket if it exists
|
||||
delete _attachedPublicSocket;
|
||||
_attachedPublicSocket = NULL;
|
||||
}
|
||||
|
||||
copySocketToEmptySocketPointer(_attachedPublicSocket, attachedPublicSocket);
|
||||
if (attachedPublicSocket) {
|
||||
copySocketToEmptySocketPointer(&_attachedPublicSocket, attachedPublicSocket);
|
||||
}
|
||||
}
|
||||
|
||||
void Assignment::setAttachedLocalSocket(const sockaddr* attachedLocalSocket) {
|
||||
|
@ -107,7 +113,9 @@ void Assignment::setAttachedLocalSocket(const sockaddr* attachedLocalSocket) {
|
|||
_attachedLocalSocket = NULL;
|
||||
}
|
||||
|
||||
copySocketToEmptySocketPointer(_attachedLocalSocket, attachedLocalSocket);
|
||||
if (attachedLocalSocket) {
|
||||
copySocketToEmptySocketPointer(&_attachedLocalSocket, attachedLocalSocket);
|
||||
}
|
||||
}
|
||||
|
||||
int Assignment::packToBuffer(unsigned char* buffer) {
|
||||
|
|
|
@ -70,19 +70,20 @@ int packSocket(unsigned char* packStore, sockaddr* socketToPack) {
|
|||
|
||||
int unpackSocket(const unsigned char* packedData, sockaddr* unpackDestSocket) {
|
||||
sockaddr_in* destinationSocket = (sockaddr_in*) unpackDestSocket;
|
||||
destinationSocket->sin_family = AF_INET;
|
||||
destinationSocket->sin_addr.s_addr = (packedData[0] << 24) + (packedData[1] << 16) + (packedData[2] << 8) + packedData[3];
|
||||
destinationSocket->sin_port = (packedData[4] << 8) + packedData[5];
|
||||
return 6; // this could be more if we ever need IPv6
|
||||
}
|
||||
|
||||
void copySocketToEmptySocketPointer(sockaddr* destination, const sockaddr* source) {
|
||||
void copySocketToEmptySocketPointer(sockaddr** destination, const sockaddr* source) {
|
||||
// create a new sockaddr or sockaddr_in depending on what type of address this is
|
||||
if (source->sa_family == AF_INET) {
|
||||
destination = (sockaddr*) new sockaddr_in;
|
||||
memcpy(destination, source, sizeof(sockaddr_in));
|
||||
*destination = (sockaddr*) new sockaddr_in;
|
||||
memcpy(*destination, source, sizeof(sockaddr_in));
|
||||
} else {
|
||||
destination = (sockaddr*) new sockaddr_in6;
|
||||
memcpy(destination, source, sizeof(sockaddr_in6));
|
||||
*destination = (sockaddr*) new sockaddr_in6;
|
||||
memcpy(*destination, source, sizeof(sockaddr_in6));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ bool socketMatch(const sockaddr* first, const sockaddr* second);
|
|||
int packSocket(unsigned char* packStore, in_addr_t inAddress, in_port_t networkOrderPort);
|
||||
int packSocket(unsigned char* packStore, sockaddr* socketToPack);
|
||||
int unpackSocket(const unsigned char* packedData, sockaddr* unpackDestSocket);
|
||||
void copySocketToEmptySocketPointer(sockaddr* destination, const sockaddr* source);
|
||||
void copySocketToEmptySocketPointer(sockaddr** destination, const sockaddr* source);
|
||||
int getLocalAddress();
|
||||
unsigned short loadBufferWithSocketInfo(char* addressBuffer, sockaddr* socket);
|
||||
sockaddr_in socketForHostnameAndHostOrderPort(const char* hostname, unsigned short port = 0);
|
||||
|
|
Loading…
Reference in a new issue