From 3f582afe5a5b0ddbe1fe3dcb7794bdabb68a69bd Mon Sep 17 00:00:00 2001 From: drbob Date: Mon, 11 Feb 2008 23:27:17 +0000 Subject: [PATCH] enabled dht, and tweaked some parameters. disabled notification checks if ext ports. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@347 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dht/opendhtmgr.cc | 4 +- libretroshare/src/pqi/p3connmgr.cc | 2 +- libretroshare/src/pqi/p3dhtmgr.cc | 68 ++++++++++++++------ libretroshare/src/rsserver/p3face-startup.cc | 1 + 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/libretroshare/src/dht/opendhtmgr.cc b/libretroshare/src/dht/opendhtmgr.cc index 13850873d..e5226c2d1 100644 --- a/libretroshare/src/dht/opendhtmgr.cc +++ b/libretroshare/src/dht/opendhtmgr.cc @@ -106,8 +106,8 @@ bool OpenDHTMgr::init() std::string configpath = "."; /* load up DHT gateways */ - //mClient = new OpenDHTClient(); - mClient = new DHTClientDummy(); + mClient = new OpenDHTClient(); + //mClient = new DHTClientDummy(); std::string filename = configpath; if (configpath.size() > 0) diff --git a/libretroshare/src/pqi/p3connmgr.cc b/libretroshare/src/pqi/p3connmgr.cc index 3d4df2817..cb3b9f448 100644 --- a/libretroshare/src/pqi/p3connmgr.cc +++ b/libretroshare/src/pqi/p3connmgr.cc @@ -310,7 +310,7 @@ void p3ConnectMgr::netUpnpInit() mNetStatus = RS_NET_UPNP_SETUP; iport = ntohs(ownState.localaddr.sin_port); eport = ntohs(ownState.serveraddr.sin_port); - if ((eport < 1000) || (eport > 10000)) + if ((eport < 1000) || (eport > 30000)) { eport = iport; } diff --git a/libretroshare/src/pqi/p3dhtmgr.cc b/libretroshare/src/pqi/p3dhtmgr.cc index bce8e4f48..130646268 100644 --- a/libretroshare/src/pqi/p3dhtmgr.cc +++ b/libretroshare/src/pqi/p3dhtmgr.cc @@ -24,6 +24,7 @@ */ #include "pqi/p3dhtmgr.h" +#include "pqi/p3connmgr.h" #include #include #include @@ -54,7 +55,7 @@ #define DHT_SEARCH_PERIOD 1800 /* PeerKeys: if we haven't found them: 30 min */ #define DHT_CHECK_PERIOD 3600 /* PeerKeys: re-lookup peer: 60 min */ #define DHT_PUBLISH_PERIOD 1800 /* OwnKey 30 min */ -#define DHT_NOTIFY_PERIOD 600 /* 10 min - Notify Check period */ +#define DHT_NOTIFY_PERIOD 300 /* 5 min - Notify Check period */ #define DHT_RESTART_PERIOD 300 /* 5 min */ #define DHT_DEFAULT_PERIOD 600 /* Default period if no work to do */ @@ -531,33 +532,64 @@ int p3DhtMgr::checkOwnDHTKeys() /* check for connect requests */ if ((peer.state == DHT_PEER_PUBLISHED) && - (now - peer.notifyTS >= DHT_NOTIFY_PERIOD)) + (!(peer.type & RS_NET_CONN_TCP_EXTERNAL))) { -#ifdef DHT_DEBUG - std::cerr << "p3DhtMgr::checkOwnDHTKeys() check for Notify (rep=0)"; - std::cerr << std::endl; -#endif - if (dhtSearch(peer.hash1, DHT_MODE_NOTIFY)) + if (now - peer.notifyTS >= DHT_NOTIFY_PERIOD) { - dhtMtx.lock(); /* LOCK MUTEX */ +#ifdef DHT_DEBUG + std::cerr << "p3DhtMgr::checkOwnDHTKeys() check for Notify (rep=0)"; + std::cerr << std::endl; +#endif + if (dhtSearch(peer.hash1, DHT_MODE_NOTIFY)) + { + dhtMtx.lock(); /* LOCK MUTEX */ - ownEntry.notifyTS = now; + ownEntry.notifyTS = now; - dhtMtx.unlock(); /* UNLOCK MUTEX */ + dhtMtx.unlock(); /* UNLOCK MUTEX */ + } + + /* restart immediately */ + repubPeriod = DHT_MIN_PERIOD; + return repubPeriod; + } + else + { + repubPeriod = DHT_NOTIFY_PERIOD - + (now - peer.notifyTS); + if (repubPeriod < DHT_MIN_PERIOD) + { + repubPeriod = DHT_MIN_PERIOD; + } +#ifdef DHT_DEBUG + std::cerr << "p3DhtMgr::checkOwnDHTKeys() check Notify in: "; + std::cerr << repubPeriod << std::endl; +#endif } - - /* restart immediately */ - repubPeriod = DHT_MIN_PERIOD; - return repubPeriod; } else { - repubPeriod = DHT_NOTIFY_PERIOD - - (now - peer.notifyTS); + if (peer.state != DHT_PEER_PUBLISHED) + { #ifdef DHT_DEBUG - std::cerr << "p3DhtMgr::checkOwnDHTKeys() check Notify in: "; - std::cerr << repubPeriod << std::endl; + std::cerr << "p3DhtMgr::checkOwnDHTKeys() No Notify until Published"; + std::cerr << std::endl; #endif + } + else if (peer.type & RS_NET_CONN_TCP_EXTERNAL) + { +#ifdef DHT_DEBUG + std::cerr << "p3DhtMgr::checkOwnDHTKeys() No Notify because have Ext Addr"; + std::cerr << std::endl; +#endif + } + else + { +#ifdef DHT_DEBUG + std::cerr << "p3DhtMgr::checkOwnDHTKeys() No Notify: Unknown Reason"; + std::cerr << std::endl; +#endif + } } } diff --git a/libretroshare/src/rsserver/p3face-startup.cc b/libretroshare/src/rsserver/p3face-startup.cc index cf8224e29..bac3419ad 100644 --- a/libretroshare/src/rsserver/p3face-startup.cc +++ b/libretroshare/src/rsserver/p3face-startup.cc @@ -637,6 +637,7 @@ int RsServer::StartupRetroShare(RsInit *config) server->StartupMonitor(); mUpnpMgr->start(); + mDhtMgr->start(); #ifdef PQI_USE_CHANNELS