mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-25 23:49:35 -05:00
a bit of a hack to increase the accuracy of LocalNet accuracy.
* periodically query Rnd DhtSpace Peer with APP flag for closest peers. (i.e like own search). git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3810 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d30d6a0444
commit
285e020f13
@ -330,10 +330,18 @@ void bdNodeManager::iteration()
|
||||
updateStore();
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::iteration(): REFRESH ";
|
||||
std::cerr << "bdNodeManager::iteration(): Do App Search";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
/* run a random search for ourselves, from own App DHT peer */
|
||||
QueryRandomLocalNet();
|
||||
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::iteration(): REFRESH ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
status();
|
||||
}
|
||||
@ -374,6 +382,43 @@ void bdNodeManager::iteration()
|
||||
}
|
||||
}
|
||||
|
||||
/* NB: This is a bit of a hack, the code is duplicated from bdnode & bdquery.
|
||||
* should use fn calls into their functions for good generality
|
||||
*/
|
||||
void bdNodeManager::QueryRandomLocalNet()
|
||||
{
|
||||
bdId id;
|
||||
bdNodeId targetNodeId;
|
||||
|
||||
uint32_t withFlag = BITDHT_PEER_STATUS_DHT_APPL;
|
||||
if (mNodeSpace.findRandomPeerWithFlag(id, withFlag))
|
||||
{
|
||||
/* calculate mid point */
|
||||
mFns->bdRandomMidId(&mOwnId, &(id.id), &targetNodeId);
|
||||
|
||||
/* do standard find_peer message */
|
||||
|
||||
bdToken transId;
|
||||
genNewTransId(&transId);
|
||||
msgout_find_node(&id, &transId, &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
|
||||
}
|
||||
else
|
||||
{
|
||||
//#ifdef DEBUG_NODE_MSGS
|
||||
std::cerr << "bdNodeManager::QueryRandomLocalNet() No LocalNet Peer Found";
|
||||
std::cerr << std::endl;
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int bdNodeManager::status()
|
||||
{
|
||||
|
@ -139,6 +139,7 @@ int checkStatus();
|
||||
int checkPingStatus();
|
||||
int SearchOutOfDate();
|
||||
void startQueries();
|
||||
void QueryRandomLocalNet();
|
||||
|
||||
std::map<bdNodeId, bdQueryPeer> mActivePeers;
|
||||
std::list<BitDhtCallback *> mCallbacks;
|
||||
|
@ -945,3 +945,76 @@ uint32_t bdSpace::calcSpaceSize()
|
||||
return totalcount;
|
||||
}
|
||||
|
||||
uint32_t bdSpace::calcSpaceSizeWithFlag(uint32_t withFlag)
|
||||
{
|
||||
std::vector<bdBucket>::iterator it;
|
||||
|
||||
/* little summary */
|
||||
uint32_t totalcount = 0;
|
||||
|
||||
it = buckets.begin();
|
||||
if (it != buckets.end())
|
||||
{
|
||||
it++; /* skip own bucket! */
|
||||
}
|
||||
for(; it != buckets.end(); it++)
|
||||
{
|
||||
int size = 0;
|
||||
std::list<bdPeer>::iterator lit;
|
||||
for(lit = it->entries.begin(); lit != it->entries.end(); lit++)
|
||||
{
|
||||
if (withFlag & lit->mPeerFlags)
|
||||
{
|
||||
size++;
|
||||
}
|
||||
}
|
||||
totalcount += size;
|
||||
}
|
||||
return totalcount;
|
||||
}
|
||||
|
||||
/* special function to enable DHT localisation (i.e find peers from own network) */
|
||||
bool bdSpace::findRandomPeerWithFlag(bdId &id, uint32_t withFlag)
|
||||
{
|
||||
std::vector<bdBucket>::iterator it;
|
||||
uint32_t totalcount = calcSpaceSizeWithFlag(withFlag);
|
||||
uint32_t rnd = rand() % totalcount;
|
||||
uint32_t i = 0;
|
||||
uint32_t buck = 0;
|
||||
|
||||
std::cerr << "bdSpace::findRandomPeerWithFlag()";
|
||||
std::cerr << std::endl;
|
||||
|
||||
it = buckets.begin();
|
||||
if (it != buckets.end())
|
||||
{
|
||||
it++; /* skip own bucket! */
|
||||
}
|
||||
for(; it != buckets.end(); it++, buck++)
|
||||
{
|
||||
int size = 0;
|
||||
std::list<bdPeer>::iterator lit;
|
||||
for(lit = it->entries.begin(); lit != it->entries.end(); lit++)
|
||||
{
|
||||
if (withFlag & lit->mPeerFlags)
|
||||
{
|
||||
if (i == rnd)
|
||||
{
|
||||
std::cerr << "bdSpace::findRandomPeerWithFlag() found #" << i;
|
||||
std::cerr << " in bucket #" << buck;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* found */
|
||||
id = lit->mPeerId;
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cerr << "bdSpace::findRandomPeerWithFlag() failed to find " << rnd << " / " << totalcount;
|
||||
std::cerr << std::endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -159,6 +159,10 @@ int printDHT();
|
||||
uint32_t calcNetworkSize();
|
||||
uint32_t calcNetworkSizeWithFlag(uint32_t withFlag);
|
||||
uint32_t calcSpaceSize();
|
||||
uint32_t calcSpaceSizeWithFlag(uint32_t withFlag);
|
||||
|
||||
/* special function to enable DHT localisation (i.e find peers from own network) */
|
||||
bool findRandomPeerWithFlag(bdId &id, uint32_t withFlag);
|
||||
|
||||
/* to add later */
|
||||
int updateOwnId(bdNodeId *newOwnId);
|
||||
|
Loading…
Reference in New Issue
Block a user