From 5faad80e123abae6f918de867e2b6e98aa1e3294 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 8 Jul 2013 11:58:19 -0700 Subject: [PATCH] remove ping unknown thread, version for ping reply --- eve/src/main.cpp | 4 --- interface/src/Application.cpp | 1 - libraries/shared/src/NodeList.cpp | 43 +------------------------------ libraries/shared/src/NodeList.h | 3 --- 4 files changed, 1 insertion(+), 50 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 827bd67bc6..cae9221e1a 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -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(); } diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index fb76e0adea..2fb7cd1e93 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -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); diff --git a/libraries/shared/src/NodeList.cpp b/libraries/shared/src/NodeList.cpp index a019131ebd..b4f69c24bf 100644 --- a/libraries/shared/src/NodeList.cpp +++ b/libraries/shared/src/NodeList.cpp @@ -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; diff --git a/libraries/shared/src/NodeList.h b/libraries/shared/src/NodeList.h index b1f7acdbb3..da9c4a556a 100644 --- a/libraries/shared/src/NodeList.h +++ b/libraries/shared/src/NodeList.h @@ -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);