diff --git a/libretroshare/src/dht/connectstatebox.cc b/libretroshare/src/dht/connectstatebox.cc index 748495d6a..5c85d5fe4 100644 --- a/libretroshare/src/dht/connectstatebox.cc +++ b/libretroshare/src/dht/connectstatebox.cc @@ -29,12 +29,23 @@ #include #include -#define FAILED_WAIT_TIME (300) //(1800) // 30 minutes. -#define TCP_WAIT_TIME (60) // 1 minutes. -#define DIRECT_WAIT_TIME (60) // 1 minutes. -#define PROXY_WAIT_TIME (60) // 1 minutes. -#define RELAY_WAIT_TIME (60) // 1 minutes. -#define REVERSE_WAIT_TIME (300) // 5 minutes. +#define TESTING_PERIODS 1 + +#ifdef TESTING_PERIODS + #define FAILED_WAIT_TIME (1800) // 5 minutes. + #define TCP_WAIT_TIME (10) // 1/6 minutes. + #define DIRECT_WAIT_TIME (10) // 1/6 minutes. + #define PROXY_WAIT_TIME (30) // 1/6 minutes. + #define RELAY_WAIT_TIME (30) // 1/6 minutes. + #define REVERSE_WAIT_TIME (30) // 1/2 minutes. +#else + #define FAILED_WAIT_TIME (1800) // 30 minutes. + #define TCP_WAIT_TIME (60) // 1 minutes. + #define DIRECT_WAIT_TIME (60) // 1 minutes. + #define PROXY_WAIT_TIME (60) // 1 minutes. + #define RELAY_WAIT_TIME (60) // 1 minutes. + #define REVERSE_WAIT_TIME (300) // 5 minutes. +#endif #define MAX_DIRECT_ATTEMPTS (3) #define MAX_PROXY_ATTEMPTS (3) diff --git a/libretroshare/src/dht/p3bitdht.cc b/libretroshare/src/dht/p3bitdht.cc index 654425e1c..5ebccc4ea 100644 --- a/libretroshare/src/dht/p3bitdht.cc +++ b/libretroshare/src/dht/p3bitdht.cc @@ -124,6 +124,11 @@ p3BitDht::p3BitDht(std::string id, pqiConnectCb *cb, p3NetMgr *nm, p3BdCallback *bdcb = new p3BdCallback(this); mUdpBitDht->addCallback(bdcb); + /* enable all modes */ + mUdpBitDht->ConnectionOptions( + BITDHT_CONNECT_MODE_DIRECT | BITDHT_CONNECT_MODE_PROXY | BITDHT_CONNECT_MODE_RELAY, + BITDHT_CONNECT_OPTION_AUTOPROXY); + } p3BitDht::~p3BitDht() diff --git a/libretroshare/src/dht/p3bitdht_peernet.cc b/libretroshare/src/dht/p3bitdht_peernet.cc index 96898651e..20cd9f082 100644 --- a/libretroshare/src/dht/p3bitdht_peernet.cc +++ b/libretroshare/src/dht/p3bitdht_peernet.cc @@ -20,7 +20,7 @@ #include "pqi/p3netmgr.h" #include "pqi/pqimonitor.h" -#define PEERNET_CONNECT_TIMEOUT 45 +#define PEERNET_CONNECT_TIMEOUT 90 // Should be BIGGER than Higher level (but okay if not!) /*** * @@ -1884,49 +1884,12 @@ void p3BitDht::Feedback_ConnectionFailed(std::string pid) return; } + std::cerr << "p3BitDht::Feedback_ConnectionFailed() UDP Connection Failed: "; + bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); + std::cerr << std::endl; + return UdpConnectionFailed_locked(dpd); } - - -void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd) -{ - - /* shut id down */ - dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; - dpd->mPeerConnectMsg = "UDP Failed"; - - if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) - { - std::cerr << "p3BitDht::monitorConnections() Request Active (Paused)... restarting"; - std::cerr << std::endl; - - /* Push Back PeerAction */ - PeerAction ca; - ca.mType = PEERNET_ACTION_TYPE_RESTARTREQ; - ca.mMode = dpd->mPeerConnectMode; - //ca.mProxyId = *proxyId; - //ca.mSrcId = *srcId; - ca.mDestId = dpd->mPeerConnectPeerId; - //ca.mPoint = point; - ca.mAnswer = BITDHT_CONNECT_ERROR_NONE; - - mActions.push_back(ca); - - // What the Action should do! - // tell it to keep going. - //struct sockaddr_in tmpaddr; - //bdsockaddr_clear(&tmpaddr); - //int start = 1; - //mUdpBitDht->ConnectionRequest(&tmpaddr, &(it->second.mPeerConnectPeerId.id), it->second.mPeerConnectMode, start); - } - // only an error if we initiated the connection. - else if (dpd->mPeerConnectPoint == BD_PROXY_CONNECTION_START_POINT) - { - std::cerr << "p3BitDht::monitorConnections() ERROR Request not active, can't stop"; - std::cerr << std::endl; - } -} - void p3BitDht::Feedback_ConnectionClosed(std::string pid) { @@ -1942,18 +1905,69 @@ void p3BitDht::Feedback_ConnectionClosed(std::string pid) return; } - std::cerr << "p3BitDht::monitorConnections() Active Connection Closed: "; + std::cerr << "p3BitDht::Feedback_ConnectionClosed() Active Connection Closed: "; bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); std::cerr << std::endl; - dpd->mConnectLogic.updateCb(CSB_UPDATE_DISCONNECTED); + return UdpConnectionFailed_locked(dpd); +} - dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; - dpd->mPeerConnectClosedTS = time(NULL); - std::ostringstream msg; - msg << "Closed, Alive for: " << dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS; - msg << " secs"; - dpd->mPeerConnectMsg = msg.str(); + +void p3BitDht::UdpConnectionFailed_locked(DhtPeerDetails *dpd) +{ + if (dpd->mPeerConnectState == RSDHT_PEERCONN_UDP_STARTED) + { + std::cerr << "p3BitDht::UdpConnectionFailed_locked() UDP Connection Failed: "; + bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); + std::cerr << std::endl; + + /* shut id down */ + dpd->mConnectLogic.updateCb(CSB_UPDATE_FAILED_ATTEMPT); + dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; + dpd->mPeerConnectMsg = "UDP Failed"; + + } + else + { + std::cerr << "p3BitDht::UdpConnectionFailed_locked() Active Connection Closed: "; + bdStdPrintNodeId(std::cerr, &(dpd->mDhtId.id)); + std::cerr << std::endl; + + dpd->mConnectLogic.updateCb(CSB_UPDATE_DISCONNECTED); + + dpd->mPeerConnectState = RSDHT_PEERCONN_DISCONNECTED; + dpd->mPeerConnectClosedTS = time(NULL); + std::ostringstream msg; + msg << "Closed, Alive for: " << dpd->mPeerConnectClosedTS - dpd->mPeerConnectTS; + msg << " secs"; + dpd->mPeerConnectMsg = msg.str(); + } + + + + if (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING) + { + std::cerr << "p3BitDht::monitorConnections() Request Active (Paused)... Killing for next Attempt"; + std::cerr << std::endl; + + /* Push Back PeerAction */ + PeerAction ca; + ca.mType = PEERNET_ACTION_TYPE_KILLREQ; + ca.mMode = dpd->mPeerConnectMode; + //ca.mProxyId = *proxyId; + //ca.mSrcId = *srcId; + ca.mDestId = dpd->mPeerConnectPeerId; + //ca.mPoint = point; + ca.mAnswer = BITDHT_CONNECT_ERROR_NONE; + + mActions.push_back(ca); + } + // only an error if we initiated the connection. + else if (dpd->mPeerConnectPoint == BD_PROXY_CONNECTION_START_POINT) + { + std::cerr << "p3BitDht::monitorConnections() ERROR Request not active, can't stop"; + std::cerr << std::endl; + } } diff --git a/libretroshare/src/dht/p3bitdht_peers.cc b/libretroshare/src/dht/p3bitdht_peers.cc index 45b00300c..26e719abe 100644 --- a/libretroshare/src/dht/p3bitdht_peers.cc +++ b/libretroshare/src/dht/p3bitdht_peers.cc @@ -425,26 +425,26 @@ int p3BitDht::lookupRsId_locked(const bdNodeId *id, std::string &pid) int p3BitDht::storeTranslation_locked(const std::string pid) { -#ifdef DEBUG_BITDHT_TRANSLATE std::cerr << "p3BitDht::storeTranslation_locked(" << pid << ")"; std::cerr << std::endl; +#ifdef DEBUG_BITDHT_TRANSLATE #endif bdNodeId nid; calculateNodeId(pid, &nid); -#ifdef DEBUG_BITDHT_TRANSLATE std::cerr << "p3BitDht::storeTranslation_locked() Converts to NodeId: "; bdStdPrintNodeId(std::cerr, &(nid)); std::cerr << std::endl; +#ifdef DEBUG_BITDHT_TRANSLATE #endif mTransToNodeId[pid] = nid; mTransToRsId[nid] = pid; -#ifdef DEBUG_BITDHT_TRANSLATE std::cerr << "p3BitDht::storeTranslation_locked() Success"; std::cerr << std::endl; +#ifdef DEBUG_BITDHT_TRANSLATE #endif return 1;