mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-09 14:00:43 +02:00
Merge pull request #826 from birarda/master
socket changes to send proper port to pairing server
This commit is contained in:
commit
62f5bb0212
5 changed files with 21 additions and 17 deletions
|
@ -27,12 +27,14 @@ void PairingHandler::sendPairRequest() {
|
||||||
int localAddress = getLocalAddress();
|
int localAddress = getLocalAddress();
|
||||||
|
|
||||||
char pairPacket[24] = {};
|
char pairPacket[24] = {};
|
||||||
sprintf(pairPacket, "Find %d.%d.%d.%d:%d",
|
sprintf(pairPacket, "Find %d.%d.%d.%d:%hu",
|
||||||
localAddress & 0xFF,
|
localAddress & 0xFF,
|
||||||
(localAddress >> 8) & 0xFF,
|
(localAddress >> 8) & 0xFF,
|
||||||
(localAddress >> 16) & 0xFF,
|
(localAddress >> 16) & 0xFF,
|
||||||
(localAddress >> 24) & 0xFF,
|
(localAddress >> 24) & 0xFF,
|
||||||
NODE_SOCKET_LISTEN_PORT);
|
NodeList::getInstance()->getSocketListenPort());
|
||||||
|
|
||||||
|
qDebug("Sending pair packet: %s\n", pairPacket);
|
||||||
|
|
||||||
sockaddr_in pairingServerSocket;
|
sockaddr_in pairingServerSocket;
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ bool pingUnknownNodeThreadStopFlag = false;
|
||||||
|
|
||||||
NodeList* NodeList::_sharedInstance = NULL;
|
NodeList* NodeList::_sharedInstance = NULL;
|
||||||
|
|
||||||
NodeList* NodeList::createInstance(char ownerType, unsigned int socketListenPort) {
|
NodeList* NodeList::createInstance(char ownerType, unsigned short int socketListenPort) {
|
||||||
if (!_sharedInstance) {
|
if (!_sharedInstance) {
|
||||||
_sharedInstance = new NodeList(ownerType, socketListenPort);
|
_sharedInstance = new NodeList(ownerType, socketListenPort);
|
||||||
} else {
|
} else {
|
||||||
|
@ -56,7 +56,7 @@ NodeList* NodeList::getInstance() {
|
||||||
return _sharedInstance;
|
return _sharedInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeList::NodeList(char newOwnerType, unsigned int newSocketListenPort) :
|
NodeList::NodeList(char newOwnerType, unsigned short int newSocketListenPort) :
|
||||||
_nodeBuckets(),
|
_nodeBuckets(),
|
||||||
_numNodes(0),
|
_numNodes(0),
|
||||||
_nodeSocket(newSocketListenPort),
|
_nodeSocket(newSocketListenPort),
|
||||||
|
|
|
@ -28,7 +28,7 @@ const int MAX_NUM_NODES = 10000;
|
||||||
const int NODES_PER_BUCKET = 100;
|
const int NODES_PER_BUCKET = 100;
|
||||||
|
|
||||||
const int MAX_PACKET_SIZE = 1500;
|
const int MAX_PACKET_SIZE = 1500;
|
||||||
const unsigned int NODE_SOCKET_LISTEN_PORT = 40103;
|
const unsigned short int NODE_SOCKET_LISTEN_PORT = 40103;
|
||||||
|
|
||||||
const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000;
|
const int NODE_SILENCE_THRESHOLD_USECS = 2 * 1000000;
|
||||||
const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
|
const int DOMAIN_SERVER_CHECK_IN_USECS = 1 * 1000000;
|
||||||
|
@ -55,7 +55,7 @@ public:
|
||||||
|
|
||||||
class NodeList {
|
class NodeList {
|
||||||
public:
|
public:
|
||||||
static NodeList* createInstance(char ownerType, unsigned int socketListenPort = NODE_SOCKET_LISTEN_PORT);
|
static NodeList* createInstance(char ownerType, unsigned short int socketListenPort = NODE_SOCKET_LISTEN_PORT);
|
||||||
static NodeList* getInstance();
|
static NodeList* getInstance();
|
||||||
|
|
||||||
typedef NodeListIterator iterator;
|
typedef NodeListIterator iterator;
|
||||||
|
@ -81,7 +81,7 @@ public:
|
||||||
|
|
||||||
UDPSocket* getNodeSocket() { return &_nodeSocket; }
|
UDPSocket* getNodeSocket() { return &_nodeSocket; }
|
||||||
|
|
||||||
unsigned int getSocketListenPort() const { return _nodeSocket.getListeningPort(); };
|
unsigned short int getSocketListenPort() const { return _nodeSocket.getListeningPort(); };
|
||||||
|
|
||||||
void(*linkedDataCreateCallback)(Node *);
|
void(*linkedDataCreateCallback)(Node *);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ public:
|
||||||
private:
|
private:
|
||||||
static NodeList* _sharedInstance;
|
static NodeList* _sharedInstance;
|
||||||
|
|
||||||
NodeList(char ownerType, unsigned int socketListenPort);
|
NodeList(char ownerType, unsigned short int socketListenPort);
|
||||||
~NodeList();
|
~NodeList();
|
||||||
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
NodeList(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
void operator=(NodeList const&); // Don't implement, needed to avoid copies of singleton
|
||||||
|
@ -142,7 +142,6 @@ private:
|
||||||
UDPSocket _nodeSocket;
|
UDPSocket _nodeSocket;
|
||||||
char _ownerType;
|
char _ownerType;
|
||||||
char* _nodeTypesOfInterest;
|
char* _nodeTypesOfInterest;
|
||||||
unsigned int _socketListenPort;
|
|
||||||
uint16_t _ownerID;
|
uint16_t _ownerID;
|
||||||
uint16_t _lastNodeID;
|
uint16_t _lastNodeID;
|
||||||
pthread_t removeSilentNodesThread;
|
pthread_t removeSilentNodesThread;
|
||||||
|
|
|
@ -129,7 +129,10 @@ sockaddr_in socketForHostname(const char* hostname) {
|
||||||
return newSocket;
|
return newSocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking(true) {
|
UDPSocket::UDPSocket(unsigned short 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);
|
||||||
|
@ -145,10 +148,10 @@ UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking
|
||||||
sockaddr_in bind_address;
|
sockaddr_in bind_address;
|
||||||
bind_address.sin_family = AF_INET;
|
bind_address.sin_family = AF_INET;
|
||||||
bind_address.sin_addr.s_addr = INADDR_ANY;
|
bind_address.sin_addr.s_addr = INADDR_ANY;
|
||||||
bind_address.sin_port = htons((uint16_t) listeningPort);
|
bind_address.sin_port = htons((uint16_t) _listeningPort);
|
||||||
|
|
||||||
if (bind(handle, (const sockaddr*) &bind_address, sizeof(sockaddr_in)) < 0) {
|
if (bind(handle, (const sockaddr*) &bind_address, sizeof(sockaddr_in)) < 0) {
|
||||||
qDebug("Failed to bind socket to port %d.\n", listeningPort);
|
qDebug("Failed to bind socket to port %hu.\n", _listeningPort);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +159,7 @@ UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking
|
||||||
if (listeningPort == 0) {
|
if (listeningPort == 0) {
|
||||||
socklen_t addressLength = sizeof(sockaddr_in);
|
socklen_t addressLength = sizeof(sockaddr_in);
|
||||||
getsockname(handle, (sockaddr*) &bind_address, &addressLength);
|
getsockname(handle, (sockaddr*) &bind_address, &addressLength);
|
||||||
listeningPort = ntohs(bind_address.sin_port);
|
_listeningPort = ntohs(bind_address.sin_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set timeout on socket recieve to 0.5 seconds
|
// set timeout on socket recieve to 0.5 seconds
|
||||||
|
@ -165,7 +168,7 @@ UDPSocket::UDPSocket(int listeningPort) : listeningPort(listeningPort), blocking
|
||||||
tv.tv_usec = 500000;
|
tv.tv_usec = 500000;
|
||||||
setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
|
setsockopt(handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv);
|
||||||
|
|
||||||
qDebug("Created UDP socket listening on port %d.\n", listeningPort);
|
qDebug("Created UDP socket listening on port %hu.\n", _listeningPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
UDPSocket::~UDPSocket() {
|
UDPSocket::~UDPSocket() {
|
||||||
|
|
|
@ -20,10 +20,10 @@
|
||||||
|
|
||||||
class UDPSocket {
|
class UDPSocket {
|
||||||
public:
|
public:
|
||||||
UDPSocket(int listening_port);
|
UDPSocket(unsigned short int listeningPort);
|
||||||
~UDPSocket();
|
~UDPSocket();
|
||||||
bool init();
|
bool init();
|
||||||
int getListeningPort() const { return listeningPort; }
|
unsigned short int getListeningPort() const { return _listeningPort; }
|
||||||
void setBlocking(bool blocking);
|
void setBlocking(bool blocking);
|
||||||
bool isBlocking() const { 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;
|
||||||
|
@ -32,7 +32,7 @@ public:
|
||||||
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;
|
unsigned short int _listeningPort;
|
||||||
bool blocking;
|
bool blocking;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue