remove ping unknown thread, version for ping reply

This commit is contained in:
Stephen Birarda 2013-07-08 11:58:19 -07:00
parent 9b1fefe671
commit 5faad80e12
4 changed files with 1 additions and 50 deletions

View file

@ -85,9 +85,6 @@ int main(int argc, const char* argv[]) {
// start the node list thread that will kill off nodes when they stop talking
nodeList->startSilentNodeRemovalThread();
// start the ping thread that hole punches to create an active connection to other nodes
nodeList->startPingUnknownNodesThread();
pthread_t receiveNodeDataThread;
pthread_create(&receiveNodeDataThread, NULL, receiveNodeData, NULL);
@ -210,6 +207,5 @@ int main(int argc, const char* argv[]) {
pthread_join(receiveNodeDataThread, NULL);
// stop the node list's threads
nodeList->stopPingUnknownNodesThread();
nodeList->stopSilentNodeRemovalThread();
}

View file

@ -248,7 +248,6 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
// start the nodeList threads
NodeList::getInstance()->startSilentNodeRemovalThread();
NodeList::getInstance()->startPingUnknownNodesThread();
_window->setCentralWidget(_glWidget);

View file

@ -72,7 +72,6 @@ NodeList::~NodeList() {
// stop the spawned threads, if they were started
stopSilentNodeRemovalThread();
stopPingUnknownNodesThread();
pthread_mutex_destroy(&mutex);
}
@ -81,7 +80,7 @@ void NodeList::timePingReply(sockaddr *nodeAddress, unsigned char *packetData) {
for(NodeList::iterator node = begin(); node != end(); node++) {
if (socketMatch(node->getPublicSocket(), nodeAddress) ||
socketMatch(node->getLocalSocket(), nodeAddress)) {
int pingTime = usecTimestampNow() - *(long long *)(packetData + 1);
int pingTime = usecTimestampNow() - *(long long *)(packetData + sizeof(PACKET_TYPE) + sizeof(PACKET_VERSION));
node->setPingMs(pingTime / 1000);
break;
}
@ -405,46 +404,6 @@ Node* NodeList::soloNodeOfType(char nodeType) {
return NULL;
}
void *pingUnknownNodes(void *args) {
NodeList* nodeList = (NodeList*) args;
const int PING_INTERVAL_USECS = 1 * 1000000;
timeval lastSend;
while (!pingUnknownNodeThreadStopFlag) {
gettimeofday(&lastSend, NULL);
for(NodeList::iterator node = nodeList->begin();
node != nodeList->end();
node++) {
if (!node->getActiveSocket() && node->getPublicSocket() && node->getLocalSocket()) {
// ping both of the sockets for the node so we can figure out
// which socket we can use
nodeList->getNodeSocket()->send(node->getPublicSocket(), &PACKET_TYPE_PING, 1);
nodeList->getNodeSocket()->send(node->getLocalSocket(), &PACKET_TYPE_PING, 1);
}
}
long long usecToSleep = PING_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&lastSend));
if (usecToSleep > 0) {
usleep(usecToSleep);
}
}
return NULL;
}
void NodeList::startPingUnknownNodesThread() {
pthread_create(&pingUnknownNodesThread, NULL, pingUnknownNodes, (void *)this);
}
void NodeList::stopPingUnknownNodesThread() {
pingUnknownNodeThreadStopFlag = true;
pthread_join(pingUnknownNodesThread, NULL);
}
void *removeSilentNodes(void *args) {
NodeList* nodeList = (NodeList*) args;
long long checkTimeUSecs, sleepTime;

View file

@ -89,8 +89,6 @@ public:
void startSilentNodeRemovalThread();
void stopSilentNodeRemovalThread();
void startPingUnknownNodesThread();
void stopPingUnknownNodesThread();
friend class NodeListIterator;
private:
@ -113,7 +111,6 @@ private:
uint16_t _lastNodeID;
pthread_t removeSilentNodesThread;
pthread_t checkInWithDomainServerThread;
pthread_t pingUnknownNodesThread;
pthread_mutex_t mutex;
void handlePingReply(sockaddr *nodeAddress);