Merging from branches/v0.5-peernet/libbitdht (--- Merging r4354 through r4356 into '.')

* adding Bloom filter to speed up finding RS peers.
 * fixed startup bug. (loops into FAILURE)




git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4357 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-06-29 16:06:33 +00:00
parent 702ff44194
commit 79b48d5a89
15 changed files with 820 additions and 21 deletions

View file

@ -64,7 +64,7 @@ bdAccount::bdAccount()
void bdAccount::incCounter(uint32_t idx, bool out)
{
if ((idx < 0) || (idx > mNoStats-1))
if (idx > mNoStats-1)
{
std::cerr << "bdAccount::incCounter() Invalid Index";
std::cerr << std::endl;

View file

@ -74,6 +74,10 @@ bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string b
mNetworkSize = 0;
mBdNetworkSize = 0;
std::string bfilter = "15108044002028000000200040400081a20840001000010400070240220000020501196b2420105218204008000000201102802041000a000004000004002881001180068301458000180000040000010080820e0005811000220200040800210280582001118024041002200004000000c44400080485a50008011084040200";
mBloomFilter.setFilterBits(bfilter);
#ifdef DEBUG_MGR
std::cerr << "bdNodeManager::bdNodeManager() ID: ";
mFns->bdPrintNodeId(std::cerr, id);
@ -379,11 +383,19 @@ void bdNodeManager::iteration()
status(); /* calculates mNetworkSize */
#ifdef DEBUG_MGR
mAccount.printStats(std::cerr);
#endif
/* Finally, Fail, and restart if we lose all peers */
if (mNetworkSize < MIN_OP_SPACE_SIZE)
uint32_t nodeSpaceSize = mNodeSpace.calcSpaceSize();
if (nodeSpaceSize < MIN_OP_SPACE_SIZE)
{
std::cerr << "bdNodeManager::iteration(): SpaceSize to Small: " << nodeSpaceSize;
std::cerr << std::endl;
std::cerr << "bdNodeManager::iteration(): REFRESH ==> FAILED";
std::cerr << std::endl;
mMode = BITDHT_MGR_STATE_FAILED;
mModeTS = now;
}
@ -459,28 +471,30 @@ int bdNodeManager::QueryRandomLocalNet()
mQueryMgr->addWorthyPeerSource(&id); /* Tell BitDHT that we really want to ping their peers */
send_query(&id, &targetNodeId);
#ifdef DEBUG_NODE_MSGS
std::cerr << "bdNodeManager::QueryRandomLocalNet() Querying : ";
mFns->bdPrintId(std::cerr, &id);
std::cerr << " searching for : ";
mFns->bdPrintNodeId(std::cerr, &targetNodeId);
std::cerr << std::endl;
#endif
if (isRandom)
{
#ifdef DEBUG_NODE_MSGS
std::cerr << "bdNodeManager::QueryRandomLocalNet() Search is Random!";
std::cerr << std::endl;
#endif
}
#ifdef DEBUG_NODE_MSGS
#endif
return 1;
}
else
{
#ifdef DEBUG_NODE_MSGS
#endif
std::cerr << "bdNodeManager::QueryRandomLocalNet() No LocalNet Peer Found";
std::cerr << std::endl;
#endif
}
return 0;
@ -525,7 +539,38 @@ void bdNodeManager::SearchForLocalNet()
{
/* install a new query */
bdNodeId targetNodeId;
bdStdRandomNodeId(&targetNodeId);
/* get something that filter approves of */
bool filterOk = false;
int i;
#define MAX_FILTER_ATTEMPTS 3000
for(i = 0; (!filterOk) && (i < MAX_FILTER_ATTEMPTS); i++)
{
bdStdRandomNodeId(&targetNodeId);
std::ostringstream tststr;
bdStdPrintNodeId(tststr, &targetNodeId);
if (mBloomFilter.test(tststr.str()))
{
filterOk = true;
}
}
if (filterOk)
{
std::cerr << "bdNodeManager::SearchForLocalNet() " << i << " Attempts to find OkNode: ";
mFns->bdPrintNodeId(std::cerr, &targetNodeId);
std::cerr << std::endl;
}
else
{
std::cerr << "bdNodeManager::SearchForLocalNet() Failed to Find FilterOk this time: ";
mFns->bdPrintNodeId(std::cerr, &targetNodeId);
std::cerr << std::endl;
}
uint32_t qflags = BITDHT_QFLAGS_INTERNAL | BITDHT_QFLAGS_DISGUISE;
mQueryMgr->addQuery(&targetNodeId, qflags);

View file

@ -53,8 +53,9 @@
#define BITDHT_PS_STATE_ONLINE (0x00000400)
#define BITDHT_PS_STATE_CONNECTED (0x00000800)
#include "bdiface.h"
#include "bdnode.h"
#include "bitdht/bdiface.h"
#include "bitdht/bdnode.h"
#include "util/bdbloom.h"
@ -171,6 +172,8 @@ void SearchForLocalNet();
uint32_t mNetworkSize;
uint32_t mBdNetworkSize;
bdBloom mBloomFilter;
/* future node functions */
//addPeerPing(foundId);
//clearPing(it->first);

View file

@ -461,6 +461,18 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
// Finally we pass to connections for them to use.
mConnMgr->updatePotentialConnectionProxy(id, peerflags);
//#define DISPLAY_BITDHTNODES 1
#ifdef DISPLAY_BITDHTNODES
/* TEMP to extract IDS for BloomFilter */
if (peerflags & BITDHT_PEER_STATUS_DHT_ENGINE)
{
std::cerr << "bdNode::addPeer() FOUND BITDHT PEER";
std::cerr << std::endl;
mFns->bdPrintNodeId(std::cerr, &(id->id));
std::cerr << std::endl;
}
#endif
}
/************************************ Process Remote Query *************************/

View file

@ -669,6 +669,7 @@ int bdSpace::updateAttachedPeers()
}
}
}
return 1;
}
@ -1220,8 +1221,8 @@ bool bdSpace::findRandomPeerWithFlag(bdId &id, uint32_t withFlag)
uint32_t i = 0;
uint32_t buck = 0;
std::cerr << "bdSpace::findRandomPeerWithFlag()";
std::cerr << std::endl;
//std::cerr << "bdSpace::findRandomPeerWithFlag()";
//std::cerr << std::endl;
it = buckets.begin();
if (it != buckets.end())

View file

@ -297,6 +297,7 @@ int bdQueryManager::getResults(bdNodeId *target, std::list<bdId> &answer, int q
/* will only be one matching query.. so end loop */
return results;
}
return 0;
}
@ -328,10 +329,10 @@ void bdQueryManager::addWorthyPeerSource(bdId *src)
peer.mPeerId = *src;
peer.mFoundTime = now;
#ifdef DEBUG_NODE_ACTIONS
std::cerr << "bdQueryManager::addWorthyPeerSource(";
mFns->bdPrintId(std::cerr, src);
std::cerr << ")" << std::endl;
#ifdef DEBUG_NODE_ACTIONS
#endif
mWorthyPeerSources.push_back(peer);
@ -348,9 +349,11 @@ bool bdQueryManager::checkWorthyPeerSources(bdId *src)
{
if (now - it->mFoundTime > MAX_WORTHY_PEER_AGE)
{
#ifdef DEBUG_NODE_ACTIONS
std::cerr << "bdQueryManager::checkWorthyPeerSource() Discard old Source: ";
mFns->bdPrintId(std::cerr, &(it->mPeerId));
std::cerr << std::endl;
#endif
it = mWorthyPeerSources.erase(it);
}
@ -358,9 +361,11 @@ bool bdQueryManager::checkWorthyPeerSources(bdId *src)
{
if (it->mPeerId == *src)
{
//std::cerr << "bdQueryManager::checkWorthyPeerSource(";
//mFns->bdPrintId(std::cerr, src);
//std::cerr << ") = true" << std::endl;
#ifdef DEBUG_NODE_ACTIONS
std::cerr << "bdQueryManager::checkWorthyPeerSource(";
mFns->bdPrintId(std::cerr, src);
std::cerr << ") = true" << std::endl;
#endif
return true;
}

View file

@ -144,6 +144,7 @@ int bdStore::filterIpList(const std::list<struct sockaddr_in> &filteredIPs)
}
}
}
return 1;
}