From f197b4cd6243eff01569768d394abdcf6c361af6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 12 Jun 2013 14:20:28 -0700 Subject: [PATCH 1/5] Some debugging to use on the other machine. --- interface/src/Application.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3121ed36e0..4079e920b1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -826,6 +826,9 @@ void Application::terminate() { static void sendAvatarVoxelURLMessage(const QUrl& url) { uint16_t ownerID = AgentList::getInstance()->getOwnerID(); + + qDebug() << "me" << ownerID << url; + if (ownerID == UNKNOWN_AGENT_ID) { return; // we don't yet know who we are } @@ -847,6 +850,8 @@ static void processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataB packetData += sizeof(agentID); dataBytes -= sizeof(agentID); + qDebug() << "them" << agentID << QUrl::fromEncoded(QByteArray((char*)packetData, dataBytes)); + // make sure the agent exists Agent* agent = AgentList::getInstance()->agentWithID(agentID); if (!agent || !agent->getLinkedData()) { From e4ed9162b981d206adc148499cd78b681a47ba24 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 12 Jun 2013 15:52:29 -0700 Subject: [PATCH 2/5] This should help, as well as fix another annoyance: bind to an ephemeral port, rather than a fixed one. --- interface/src/Application.cpp | 6 +----- libraries/shared/src/AgentList.cpp | 3 +-- libraries/shared/src/AgentList.h | 2 +- libraries/shared/src/UDPSocket.cpp | 9 ++++++++- libraries/shared/src/UDPSocket.h | 4 +++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4079e920b1..d864fb86dd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -169,7 +169,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) : _window->setWindowTitle("Interface"); printLog("Interface Startup:\n"); - unsigned int listenPort = AGENT_SOCKET_LISTEN_PORT; + unsigned int listenPort = 0; // bind to an ephemeral port by default const char** constArgv = const_cast(argv); const char* portStr = getCmdOption(argc, constArgv, "--listenPort"); if (portStr) { @@ -827,8 +827,6 @@ void Application::terminate() { static void sendAvatarVoxelURLMessage(const QUrl& url) { uint16_t ownerID = AgentList::getInstance()->getOwnerID(); - qDebug() << "me" << ownerID << url; - if (ownerID == UNKNOWN_AGENT_ID) { return; // we don't yet know who we are } @@ -850,8 +848,6 @@ static void processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataB packetData += sizeof(agentID); dataBytes -= sizeof(agentID); - qDebug() << "them" << agentID << QUrl::fromEncoded(QByteArray((char*)packetData, dataBytes)); - // make sure the agent exists Agent* agent = AgentList::getInstance()->agentWithID(agentID); if (!agent || !agent->getLinkedData()) { diff --git a/libraries/shared/src/AgentList.cpp b/libraries/shared/src/AgentList.cpp index 9c309bb23f..56641bd2a0 100644 --- a/libraries/shared/src/AgentList.cpp +++ b/libraries/shared/src/AgentList.cpp @@ -62,7 +62,6 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) : _agentSocket(newSocketListenPort), _ownerType(newOwnerType), _agentTypesOfInterest(NULL), - _socketListenPort(newSocketListenPort), _ownerID(UNKNOWN_AGENT_ID), _lastAgentID(0) { pthread_mutex_init(&mutex, 0); @@ -224,7 +223,7 @@ void AgentList::sendDomainServerCheckIn() { packetPosition += packSocket(checkInPacket + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE), getLocalAddress(), - htons(_socketListenPort)); + htons(_agentSocket.getListeningPort())); // add the number of bytes for agent types of interest *(packetPosition++) = numBytesAgentsOfInterest; diff --git a/libraries/shared/src/AgentList.h b/libraries/shared/src/AgentList.h index 3007dbc8e3..1b51913928 100644 --- a/libraries/shared/src/AgentList.h +++ b/libraries/shared/src/AgentList.h @@ -58,7 +58,7 @@ public: UDPSocket* getAgentSocket() { return &_agentSocket; } - unsigned int getSocketListenPort() const { return _socketListenPort; }; + unsigned int getSocketListenPort() const { return _agentSocket.getListeningPort(); }; void(*linkedDataCreateCallback)(Agent *); diff --git a/libraries/shared/src/UDPSocket.cpp b/libraries/shared/src/UDPSocket.cpp index b7c2275635..8cd58a20bc 100644 --- a/libraries/shared/src/UDPSocket.cpp +++ b/libraries/shared/src/UDPSocket.cpp @@ -117,7 +117,7 @@ unsigned short loadBufferWithSocketInfo(char* addressBuffer, sockaddr* socket) { } } -UDPSocket::UDPSocket(int listeningPort) : blocking(true) { +UDPSocket::UDPSocket(int listeningPort) : blocking(true), listeningPort(listeningPort) { init(); // create the socket handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); @@ -140,6 +140,13 @@ UDPSocket::UDPSocket(int listeningPort) : blocking(true) { return; } + // if we requested an ephemeral port, get the actual port + if (listeningPort == 0) { + socklen_t addressLength = sizeof(sockaddr_in); + getsockname(handle, (sockaddr*) &bind_address, &addressLength); + listeningPort = ntohs(bind_address.sin_port); + } + // set timeout on socket recieve to 0.5 seconds struct timeval tv; tv.tv_sec = 0; diff --git a/libraries/shared/src/UDPSocket.h b/libraries/shared/src/UDPSocket.h index b56a1cc0cf..8539ff93c2 100644 --- a/libraries/shared/src/UDPSocket.h +++ b/libraries/shared/src/UDPSocket.h @@ -23,14 +23,16 @@ public: UDPSocket(int listening_port); ~UDPSocket(); bool init(); + int getListeningPort() const { return listeningPort; } void setBlocking(bool blocking); - bool isBlocking() { return blocking; } + bool isBlocking() const { return blocking; } int send(sockaddr* destAddress, const void* data, size_t byteLength) const; int send(char* destAddress, int destPort, const void* data, size_t byteLength) const; bool receive(void* receivedData, ssize_t* receivedBytes) const; bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const; private: int handle; + int listeningPort; bool blocking; }; From 6dae9db01de45a04e6487f20076a30c27232c88d Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 12 Jun 2013 15:54:13 -0700 Subject: [PATCH 3/5] Initialize members in the right order. --- libraries/shared/src/UDPSocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/UDPSocket.cpp b/libraries/shared/src/UDPSocket.cpp index 8cd58a20bc..69cf0cfebe 100644 --- a/libraries/shared/src/UDPSocket.cpp +++ b/libraries/shared/src/UDPSocket.cpp @@ -117,7 +117,7 @@ unsigned short loadBufferWithSocketInfo(char* addressBuffer, sockaddr* socket) { } } -UDPSocket::UDPSocket(int listeningPort) : blocking(true), listeningPort(listeningPort) { +UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking(true) { init(); // create the socket handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); From 19180ad9006667f7b0ea1b8ee2ea905f4b029d82 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 12 Jun 2013 15:56:28 -0700 Subject: [PATCH 4/5] Put the debugging back in. --- interface/src/Application.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d864fb86dd..b02afe2b0e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -827,6 +827,8 @@ void Application::terminate() { static void sendAvatarVoxelURLMessage(const QUrl& url) { uint16_t ownerID = AgentList::getInstance()->getOwnerID(); + qDebug() << "me" << ownerID << url; + if (ownerID == UNKNOWN_AGENT_ID) { return; // we don't yet know who we are } @@ -848,6 +850,8 @@ static void processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataB packetData += sizeof(agentID); dataBytes -= sizeof(agentID); + qDebug() << "them" << agentID << QUrl::fromEncoded(QByteArray((char*)packetData, dataBytes)); + // make sure the agent exists Agent* agent = AgentList::getInstance()->agentWithID(agentID); if (!agent || !agent->getLinkedData()) { From ccd61ee5a2d4aaac9623382baaf9e0568885947f Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 12 Jun 2013 16:13:44 -0700 Subject: [PATCH 5/5] Found the problem we were having: the domain server was reporting back all kinds of things as our ID. --- domain-server/src/main.cpp | 35 ++++++++++++++++++----------------- interface/src/Application.cpp | 4 ---- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/domain-server/src/main.cpp b/domain-server/src/main.cpp index b1e2117db3..b8f66b0641 100644 --- a/domain-server/src/main.cpp +++ b/domain-server/src/main.cpp @@ -135,25 +135,26 @@ int main(int argc, const char * argv[]) if (numInterestTypes > 0) { // if the agent has sent no types of interest, assume they want nothing but their own ID back for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { - if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType) - && memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) { - // this is not the agent themselves - // and this is an agent of a type in the passed agent types of interest - // or the agent did not pass us any specific types they are interested in + if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)) { + if (memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) { + // this is not the agent themselves + // and this is an agent of a type in the passed agent types of interest + // or the agent did not pass us any specific types they are interested in - if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { - // this is an agent of which there can be multiple, just add them to the packet - // don't send avatar agents to other avatars, that will come from avatar mixer - if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { - currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); - } + if (memchr(SOLO_AGENT_TYPES, agent->getType(), sizeof(SOLO_AGENT_TYPES)) == NULL) { + // this is an agent of which there can be multiple, just add them to the packet + // don't send avatar agents to other avatars, that will come from avatar mixer + if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) { + currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent)); + } - } else { - // solo agent, we need to only send newest - if (newestSoloAgents[agent->getType()] == NULL || - newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) { - // we have to set the newer solo agent to add it to the broadcast later - newestSoloAgents[agent->getType()] = &(*agent); + } else { + // solo agent, we need to only send newest + if (newestSoloAgents[agent->getType()] == NULL || + newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) { + // we have to set the newer solo agent to add it to the broadcast later + newestSoloAgents[agent->getType()] = &(*agent); + } } } } else { diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b02afe2b0e..d864fb86dd 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -827,8 +827,6 @@ void Application::terminate() { static void sendAvatarVoxelURLMessage(const QUrl& url) { uint16_t ownerID = AgentList::getInstance()->getOwnerID(); - qDebug() << "me" << ownerID << url; - if (ownerID == UNKNOWN_AGENT_ID) { return; // we don't yet know who we are } @@ -850,8 +848,6 @@ static void processAvatarVoxelURLMessage(unsigned char *packetData, size_t dataB packetData += sizeof(agentID); dataBytes -= sizeof(agentID); - qDebug() << "them" << agentID << QUrl::fromEncoded(QByteArray((char*)packetData, dataBytes)); - // make sure the agent exists Agent* agent = AgentList::getInstance()->agentWithID(agentID); if (!agent || !agent->getLinkedData()) {