From c77547ac45b61f2f3cd49a7f08b9c44e6650142e Mon Sep 17 00:00:00 2001 From: drbob Date: Sun, 28 Oct 2012 14:10:56 +0000 Subject: [PATCH] Tweaks to bitdht library for standalone single search option. - Added flag to disable local Network search. - Fixed DHT Msg Rate bug (ported from trunk). git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5731 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- src/bitdht/bdmanager.cc | 47 +++++++++++++++++++++++------------------ src/bitdht/bdmanager.h | 2 ++ src/bitdht/bdnode.cc | 6 +++--- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/src/bitdht/bdmanager.cc b/src/bitdht/bdmanager.cc index 16874eb..719ade5 100644 --- a/src/bitdht/bdmanager.cc +++ b/src/bitdht/bdmanager.cc @@ -87,6 +87,8 @@ bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string b mFns->bdPrintNodeId(std::cerr, id); std::cerr << std::endl; #endif + + mLocalNetEnhancements = true; } int bdNodeManager::stopDht() @@ -400,34 +402,39 @@ void bdNodeManager::iteration() std::cerr << std::endl; #endif - /* run a random search for ourselves, from own App DHT peer */ - QueryRandomLocalNet(); + /* This stuff is only important for "LocalNet based Features */ + if (mLocalNetEnhancements) + { + /* run a random search for ourselves, from own App DHT peer */ + QueryRandomLocalNet(); + #define SEARCH_MAX_SIZE 10 - if (mBdNetworkSize < SEARCH_MAX_SIZE) - { -#ifdef DEBUG_MGR - std::cerr << "Local Netsize: " << mBdNetworkSize << " to small...searching"; - std::cerr << std::endl; -#endif - - /* if the network size is very small */ - SearchForLocalNet(); - mSearchingDone = false; - } - else - { - if (!mSearchingDone) + if (mBdNetworkSize < SEARCH_MAX_SIZE) { - mSearchingDone = true; - mSearchTS = now; #ifdef DEBUG_MGR - std::cerr << "Completed LocalNet Search in : " << mSearchTS-mStartTS; + std::cerr << "Local Netsize: " << mBdNetworkSize << " to small...searching"; std::cerr << std::endl; #endif + + /* if the network size is very small */ + SearchForLocalNet(); + mSearchingDone = false; + } + else + { + if (!mSearchingDone) + { + mSearchingDone = true; + mSearchTS = now; +#ifdef DEBUG_MGR + std::cerr << "Completed LocalNet Search in : " << mSearchTS-mStartTS; + std::cerr << std::endl; +#endif + } } } - + #ifdef DEBUG_MGR std::cerr << "bdNodeManager::iteration(): REFRESH "; std::cerr << std::endl; diff --git a/src/bitdht/bdmanager.h b/src/bitdht/bdmanager.h index 635a5eb..a43a883 100644 --- a/src/bitdht/bdmanager.h +++ b/src/bitdht/bdmanager.h @@ -187,6 +187,8 @@ void SearchForLocalNet(); bdBloom mBloomFilter; + bool mLocalNetEnhancements; + /* future node functions */ //addPeerPing(foundId); //clearPing(it->first); diff --git a/src/bitdht/bdnode.cc b/src/bitdht/bdnode.cc index 9e024b0..b16a28c 100644 --- a/src/bitdht/bdnode.cc +++ b/src/bitdht/bdnode.cc @@ -134,14 +134,14 @@ uint32_t bdNode::setNodeDhtMode(uint32_t dhtFlags) { default: case BITDHT_MODE_TRAFFIC_LOW: - mMaxAllowedMsgs = BDNODE_HIGH_MSG_RATE; - break; - case BITDHT_MODE_TRAFFIC_HIGH: mMaxAllowedMsgs = BDNODE_LOW_MSG_RATE; break; case BITDHT_MODE_TRAFFIC_MED: mMaxAllowedMsgs = BDNODE_MED_MSG_RATE; break; + case BITDHT_MODE_TRAFFIC_HIGH: + mMaxAllowedMsgs = BDNODE_HIGH_MSG_RATE; + break; case BITDHT_MODE_TRAFFIC_TRICKLE: mMaxAllowedMsgs = BDNODE_TRICKLE_MSG_RATE; break;