diff --git a/libbitdht/src/bitdht/bdconnection.cc b/libbitdht/src/bitdht/bdconnection.cc index ebce696aa..ac131b587 100644 --- a/libbitdht/src/bitdht/bdconnection.cc +++ b/libbitdht/src/bitdht/bdconnection.cc @@ -265,6 +265,8 @@ int bdConnectManager::requestConnection_direct(struct sockaddr_in *laddr, bdNode if (checkExistingConnectionAttempt(target)) { + std::cerr << "bdConnectManager::requestConnection_direct() Existing ConnectionRequest... NOOP"; + std::cerr << std::endl; return 0; } @@ -326,8 +328,15 @@ int bdConnectManager::requestConnection_proxy(struct sockaddr_in *laddr, bdNodeI std::cerr << std::endl; #endif - /* create a bdConnect, and put into the queue */ + + if (checkExistingConnectionAttempt(target)) + { + std::cerr << "bdConnectManager::requestConnection_proxy() Existing ConnectionRequest... NOOP"; + std::cerr << std::endl; + return 0; + } + /* create a bdConnect, and put into the queue */ bdConnectionRequest connreq; connreq.setupProxyConnection(laddr, target, mode); @@ -676,7 +685,7 @@ void bdConnectManager::iterateConnectionRequests() /* connection completed, doing UDP connection */ if (now - it->second.mStateTS > BITDHT_CONNREQUEST_TIMEOUT_CONNECT) { - std::cerr << "bdConnectManager::iterateConnectionAttempt() EXTCONNECT has reached timout ->????"; + std::cerr << "bdConnectManager::iterateConnectionAttempt() ERROR EXTCONNECT has reached timout -> SHOULD NEVER HAPPEN... restart this query:"; std::cerr << std::endl; std::cerr << it->second; std::cerr << std::endl; @@ -854,9 +863,29 @@ void bdConnectManager::callbackConnectRequest(bdId *srcId, bdId *proxyId, bdId * { if (it->second.mState == BITDHT_CONNREQUEST_INPROGRESS) { - std::cerr << "bdConnectManager::callbackConnectRequest() ERROR alt CR also in progress!"; + /* AT THIS POINT - WE SHOULD SWITCH IT INTO EXTCONNECT MODE????, + * which will timeout - if it fails... + * THIS is effectively the end of the connection attempt anyway. + * if UDP succeeds or fails, will Kill either way. + */ + std::cerr << "bdConnectManager::callbackConnectRequest() ERROR ALT CR also in progress!"; std::cerr << std::endl; + } + + std::cerr << "bdConnectManager::callbackConnectRequest() WARNING Switching ALT CR to EXTCONNECT Mode"; + std::cerr << std::endl; + + time_t now = time(NULL); + it->second.mState = BITDHT_CONNREQUEST_EXTCONNECT; + it->second.mStateTS = now; + + } + else + { + std::cerr << "bdConnectManager::callbackConnectRequest() No ALT CR - Good"; + std::cerr << std::endl; + } callbackConnect(srcId, proxyId, destId, mode, point, cbtype, errcode); return; @@ -2233,7 +2262,8 @@ int bdConnectManager::recvedConnectionAck(bdId *id, bdId *srcConnAddr, bdId *des // Slightly different callback, use ConnAddr for start message! // Also callback to ConnectionRequest first. // ACTUALLY we are END, so shouldn't (AT This Point do this). - callbackConnect(&(conn->mSrcConnAddr),&(conn->mProxyId),&(conn->mDestId), + // MUST callback via ConnectRequest - to prevent duplicate REQUESTS. + callbackConnectRequest(&(conn->mSrcConnAddr),&(conn->mProxyId),&(conn->mDestId), conn->mMode, conn->mPoint, BITDHT_CONNECT_CB_START, BITDHT_CONNECT_ERROR_NONE); diff --git a/libbitdht/src/bitdht/bdconnection.h b/libbitdht/src/bitdht/bdconnection.h index 10be0f655..777b08d05 100644 --- a/libbitdht/src/bitdht/bdconnection.h +++ b/libbitdht/src/bitdht/bdconnection.h @@ -42,7 +42,7 @@ class bdNodePublisher; #define BITDHT_CONNREQUEST_EXTCONNECT 4 #define BITDHT_CONNREQUEST_DONE 5 -#define BITDHT_CONNREQUEST_TIMEOUT_CONNECT 30 +#define BITDHT_CONNREQUEST_TIMEOUT_CONNECT 120 // MAKE THIS LARGE - SHOULD NEVER HAPPEN. #define BITDHT_CONNREQUEST_TIMEOUT_INPROGRESS 30 #define BITDHT_CONNREQUEST_MAX_AGE 60 diff --git a/libbitdht/src/bitdht/bdiface.h b/libbitdht/src/bitdht/bdiface.h index a9c859fd5..ad31797d3 100644 --- a/libbitdht/src/bitdht/bdiface.h +++ b/libbitdht/src/bitdht/bdiface.h @@ -317,7 +317,7 @@ virtual void removeFindNode(bdNodeId *id) = 0; virtual void findDhtValue(bdNodeId *id, std::string key, uint32_t mode) = 0; /***** Connections Requests *****/ -virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) = 0; +virtual bool ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) = 0; virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer) = 0; virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags) = 0; diff --git a/libbitdht/src/bitdht/bdmanager.cc b/libbitdht/src/bitdht/bdmanager.cc index 3a0275262..33bc7d275 100644 --- a/libbitdht/src/bitdht/bdmanager.cc +++ b/libbitdht/src/bitdht/bdmanager.cc @@ -1255,12 +1255,12 @@ int bdDebugCallback::dhtValueCallback(const bdNodeId *id, std::string key, uint3 -void bdNodeManager::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) +bool bdNodeManager::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) { std::cerr << "bdNodeManager::ConnectionRequest()"; std::cerr << std::endl; - mConnMgr->requestConnection(laddr, target, mode, start); + return mConnMgr->requestConnection(laddr, target, mode, start); } void bdNodeManager::ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer) diff --git a/libbitdht/src/bitdht/bdmanager.h b/libbitdht/src/bitdht/bdmanager.h index 1e25904b8..887e9167f 100644 --- a/libbitdht/src/bitdht/bdmanager.h +++ b/libbitdht/src/bitdht/bdmanager.h @@ -121,7 +121,7 @@ virtual int getDhtQueries(std::map &queries); virtual int getDhtQueryStatus(const bdNodeId *id, bdQuerySummary &query); /***** Connection Interface ****/ -virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start); +virtual bool ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start); virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer); virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags); diff --git a/libbitdht/src/udp/udpbitdht.cc b/libbitdht/src/udp/udpbitdht.cc index 6bfba3349..2ae81ce7d 100644 --- a/libbitdht/src/udp/udpbitdht.cc +++ b/libbitdht/src/udp/udpbitdht.cc @@ -125,11 +125,11 @@ void UdpBitDht::removeCallback(BitDhtCallback *cb) mBitDhtManager->removeCallback(cb); } -void UdpBitDht::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) +bool UdpBitDht::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) { bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/ - mBitDhtManager->ConnectionRequest(laddr, target, mode, start); + return mBitDhtManager->ConnectionRequest(laddr, target, mode, start); } diff --git a/libbitdht/src/udp/udpbitdht.h b/libbitdht/src/udp/udpbitdht.h index fd330471e..c201659b3 100644 --- a/libbitdht/src/udp/udpbitdht.h +++ b/libbitdht/src/udp/udpbitdht.h @@ -68,7 +68,7 @@ virtual void addCallback(BitDhtCallback *cb); virtual void removeCallback(BitDhtCallback *cb); /***** Connections Requests *****/ -virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start); +virtual bool ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start); virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer); virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags);