mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 05:13:11 +02:00
Merge pull request #531 from ey6es/master
Fixed bug with packet type filtering, have client bind to an ephemeral port by default so that we can run multiple clients without having to manually specify ports.
This commit is contained in:
commit
26a8607334
6 changed files with 33 additions and 23 deletions
|
@ -135,25 +135,26 @@ int main(int argc, const char * argv[])
|
||||||
if (numInterestTypes > 0) {
|
if (numInterestTypes > 0) {
|
||||||
// if the agent has sent no types of interest, assume they want nothing but their own ID back
|
// 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++) {
|
for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) {
|
||||||
if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)
|
if (!agent->matches((sockaddr*) &agentPublicAddress, (sockaddr*) &agentLocalAddress, agentType)) {
|
||||||
&& memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) {
|
if (memchr(agentTypesOfInterest, agent->getType(), numInterestTypes)) {
|
||||||
// this is not the agent themselves
|
// this is not the agent themselves
|
||||||
// and this is an agent of a type in the passed agent types of interest
|
// 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
|
// 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) {
|
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
|
// 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
|
// don't send avatar agents to other avatars, that will come from avatar mixer
|
||||||
if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) {
|
if (agentType != AGENT_TYPE_AVATAR || agent->getType() != AGENT_TYPE_AVATAR) {
|
||||||
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent));
|
currentBufferPos = addAgentToBroadcastPacket(currentBufferPos, &(*agent));
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// solo agent, we need to only send newest
|
// solo agent, we need to only send newest
|
||||||
if (newestSoloAgents[agent->getType()] == NULL ||
|
if (newestSoloAgents[agent->getType()] == NULL ||
|
||||||
newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) {
|
newestSoloAgents[agent->getType()]->getWakeMicrostamp() < agent->getWakeMicrostamp()) {
|
||||||
// we have to set the newer solo agent to add it to the broadcast later
|
// we have to set the newer solo agent to add it to the broadcast later
|
||||||
newestSoloAgents[agent->getType()] = &(*agent);
|
newestSoloAgents[agent->getType()] = &(*agent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -169,7 +169,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
||||||
_window->setWindowTitle("Interface");
|
_window->setWindowTitle("Interface");
|
||||||
printLog("Interface Startup:\n");
|
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<const char**>(argv);
|
const char** constArgv = const_cast<const char**>(argv);
|
||||||
const char* portStr = getCmdOption(argc, constArgv, "--listenPort");
|
const char* portStr = getCmdOption(argc, constArgv, "--listenPort");
|
||||||
if (portStr) {
|
if (portStr) {
|
||||||
|
@ -826,6 +826,7 @@ void Application::terminate() {
|
||||||
|
|
||||||
static void sendAvatarVoxelURLMessage(const QUrl& url) {
|
static void sendAvatarVoxelURLMessage(const QUrl& url) {
|
||||||
uint16_t ownerID = AgentList::getInstance()->getOwnerID();
|
uint16_t ownerID = AgentList::getInstance()->getOwnerID();
|
||||||
|
|
||||||
if (ownerID == UNKNOWN_AGENT_ID) {
|
if (ownerID == UNKNOWN_AGENT_ID) {
|
||||||
return; // we don't yet know who we are
|
return; // we don't yet know who we are
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,6 @@ AgentList::AgentList(char newOwnerType, unsigned int newSocketListenPort) :
|
||||||
_agentSocket(newSocketListenPort),
|
_agentSocket(newSocketListenPort),
|
||||||
_ownerType(newOwnerType),
|
_ownerType(newOwnerType),
|
||||||
_agentTypesOfInterest(NULL),
|
_agentTypesOfInterest(NULL),
|
||||||
_socketListenPort(newSocketListenPort),
|
|
||||||
_ownerID(UNKNOWN_AGENT_ID),
|
_ownerID(UNKNOWN_AGENT_ID),
|
||||||
_lastAgentID(0) {
|
_lastAgentID(0) {
|
||||||
pthread_mutex_init(&mutex, 0);
|
pthread_mutex_init(&mutex, 0);
|
||||||
|
@ -224,7 +223,7 @@ void AgentList::sendDomainServerCheckIn() {
|
||||||
|
|
||||||
packetPosition += packSocket(checkInPacket + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE),
|
packetPosition += packSocket(checkInPacket + sizeof(PACKET_HEADER) + sizeof(AGENT_TYPE),
|
||||||
getLocalAddress(),
|
getLocalAddress(),
|
||||||
htons(_socketListenPort));
|
htons(_agentSocket.getListeningPort()));
|
||||||
|
|
||||||
// add the number of bytes for agent types of interest
|
// add the number of bytes for agent types of interest
|
||||||
*(packetPosition++) = numBytesAgentsOfInterest;
|
*(packetPosition++) = numBytesAgentsOfInterest;
|
||||||
|
|
|
@ -58,7 +58,7 @@ public:
|
||||||
|
|
||||||
UDPSocket* getAgentSocket() { return &_agentSocket; }
|
UDPSocket* getAgentSocket() { return &_agentSocket; }
|
||||||
|
|
||||||
unsigned int getSocketListenPort() const { return _socketListenPort; };
|
unsigned int getSocketListenPort() const { return _agentSocket.getListeningPort(); };
|
||||||
|
|
||||||
void(*linkedDataCreateCallback)(Agent *);
|
void(*linkedDataCreateCallback)(Agent *);
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ unsigned short loadBufferWithSocketInfo(char* addressBuffer, sockaddr* socket) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UDPSocket::UDPSocket(int listeningPort) : blocking(true) {
|
UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking(true) {
|
||||||
init();
|
init();
|
||||||
// create the socket
|
// create the socket
|
||||||
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
handle = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
|
@ -140,6 +140,13 @@ UDPSocket::UDPSocket(int listeningPort) : blocking(true) {
|
||||||
return;
|
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
|
// set timeout on socket recieve to 0.5 seconds
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
|
|
|
@ -23,14 +23,16 @@ public:
|
||||||
UDPSocket(int listening_port);
|
UDPSocket(int listening_port);
|
||||||
~UDPSocket();
|
~UDPSocket();
|
||||||
bool init();
|
bool init();
|
||||||
|
int getListeningPort() const { return listeningPort; }
|
||||||
void setBlocking(bool blocking);
|
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(sockaddr* destAddress, const void* data, size_t byteLength) const;
|
||||||
int send(char* destAddress, int destPort, 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(void* receivedData, ssize_t* receivedBytes) const;
|
||||||
bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const;
|
bool receive(sockaddr* recvAddress, void* receivedData, ssize_t* receivedBytes) const;
|
||||||
private:
|
private:
|
||||||
int handle;
|
int handle;
|
||||||
|
int listeningPort;
|
||||||
bool blocking;
|
bool blocking;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue