mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-04 20:34:26 -04:00
General Bugfixes from RS integration.
* heisenbug fixed. msgout_find_node was inside debugging #defs. * fixed ReplyFindNode and ReplyQueryHash counters for stats. * added Node Space size() functions. * added FINDSELF mode. 60 secs to search for own hash. * incremental addition of search ids. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3326 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5ed26b7ccb
commit
f876dcb93b
10 changed files with 741 additions and 526 deletions
|
@ -132,16 +132,18 @@ virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a) = 0;
|
|||
|
||||
|
||||
/* Status options */
|
||||
#define BITDHT_QUERY_QUERYING 1
|
||||
#define BITDHT_QUERY_FAILURE 2
|
||||
#define BITDHT_QUERY_FOUND_CLOSEST 3
|
||||
#define BITDHT_QUERY_PEER_UNREACHABLE 4
|
||||
#define BITDHT_QUERY_SUCCESS 5
|
||||
#define BITDHT_QUERY_READY 1
|
||||
#define BITDHT_QUERY_QUERYING 2
|
||||
#define BITDHT_QUERY_FAILURE 3
|
||||
#define BITDHT_QUERY_FOUND_CLOSEST 4
|
||||
#define BITDHT_QUERY_PEER_UNREACHABLE 5
|
||||
#define BITDHT_QUERY_SUCCESS 6
|
||||
|
||||
/* Query Flags */
|
||||
#define BITDHT_QFLAGS_NONE 0
|
||||
#define BITDHT_QFLAGS_DISGUISE 1
|
||||
#define BITDHT_QFLAGS_DO_IDLE 2
|
||||
#define BITDHT_QFLAGS_INTERNAL 4 // means it runs through startup.
|
||||
|
||||
class BitDhtCallback
|
||||
{
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
* #define DEBUG_MGR_PKT 1
|
||||
***/
|
||||
|
||||
#define DEBUG_MGR 1
|
||||
//#define DEBUG_MGR 1
|
||||
|
||||
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||
:bdNode(id, dhtVersion, bootfile, fns)
|
||||
|
@ -94,14 +94,41 @@ void bdNodeManager::addFindNode(bdNodeId *id, uint32_t qflags)
|
|||
/* add to map */
|
||||
bdQueryPeer peer;
|
||||
peer.mId.id = (*id);
|
||||
peer.mStatus = BITDHT_QUERY_QUERYING;
|
||||
peer.mStatus = BITDHT_QUERY_READY; //QUERYING;
|
||||
peer.mQFlags = qflags;
|
||||
mActivePeers[*id] = peer;
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::addFindNode() Added QueryPeer....";
|
||||
std::cerr << "bdNodeManager::addFindNode() Added QueryPeer as READY....";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
addQuery(id, qflags | BITDHT_QFLAGS_DISGUISE);
|
||||
//addQuery(id, qflags | BITDHT_QFLAGS_DISGUISE);
|
||||
return;
|
||||
}
|
||||
|
||||
/* finds a queued query, and starts it */
|
||||
void bdNodeManager::startQueries()
|
||||
{
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::startQueries() ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* check if exists already */
|
||||
std::map<bdNodeId, bdQueryPeer>::iterator it;
|
||||
for(it = mActivePeers.begin(); it != mActivePeers.end(); it++)
|
||||
{
|
||||
if (it->second.mStatus == BITDHT_QUERY_READY)
|
||||
{
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::startQueries() Found READY Query.";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
it->second.mStatus == BITDHT_QUERY_QUERYING;
|
||||
|
||||
uint32_t qflags = it->second.mQFlags | BITDHT_QFLAGS_DISGUISE;
|
||||
addQuery(&(it->first), qflags);
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -138,6 +165,7 @@ void bdNodeManager::iteration()
|
|||
{
|
||||
case BITDHT_MGR_STATE_STARTUP:
|
||||
/* 10 seconds startup .... then switch to ACTIVE */
|
||||
|
||||
if (modeAge > MAX_STARTUP_TIME)
|
||||
{
|
||||
#ifdef DEBUG_MGR
|
||||
|
@ -148,10 +176,29 @@ void bdNodeManager::iteration()
|
|||
getOwnId(&id);
|
||||
addQuery(&id, BITDHT_QFLAGS_DO_IDLE | BITDHT_QFLAGS_DISGUISE);
|
||||
|
||||
mMode = BITDHT_MGR_STATE_FINDSELF;
|
||||
mModeTS = now;
|
||||
}
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_STATE_FINDSELF:
|
||||
/* 60 seconds further startup .... then switch to ACTIVE */
|
||||
#define MAX_FINDSELF_TIME 60
|
||||
#define MIN_OP_SPACE_SIZE 100
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::iteration() Finding Oneself: NodeSpace Size:" << mNodeSpace.size();
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
if ((modeAge > MAX_FINDSELF_TIME) ||
|
||||
(mNodeSpace.size() > MIN_OP_SPACE_SIZE))
|
||||
{
|
||||
//mMode = BITDHT_MGR_STATE_ACTIVE;
|
||||
mMode = BITDHT_MGR_STATE_REFRESH;
|
||||
mModeTS = now;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_STATE_ACTIVE:
|
||||
|
@ -177,6 +224,13 @@ void bdNodeManager::iteration()
|
|||
mMode = BITDHT_MGR_STATE_ACTIVE;
|
||||
mModeTS = now;
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::iteration(): Starting Query";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
startQueries();
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "bdNodeManager::iteration(): Updating Stores";
|
||||
std::cerr << std::endl;
|
||||
|
|
|
@ -70,12 +70,13 @@ class bdQueryPeer
|
|||
|
||||
|
||||
#define BITDHT_MGR_STATE_STARTUP 1
|
||||
#define BITDHT_MGR_STATE_ACTIVE 2
|
||||
#define BITDHT_MGR_STATE_REFRESH 3
|
||||
#define BITDHT_MGR_STATE_QUIET 4
|
||||
#define BITDHT_MGR_STATE_FINDSELF 2
|
||||
#define BITDHT_MGR_STATE_ACTIVE 3
|
||||
#define BITDHT_MGR_STATE_REFRESH 4
|
||||
#define BITDHT_MGR_STATE_QUIET 5
|
||||
|
||||
#define MAX_STARTUP_TIME 10
|
||||
#define MAX_REFRESH_TIME 30
|
||||
#define MAX_REFRESH_TIME 20
|
||||
|
||||
#define BITDHT_MGR_QUERY_FAILURE 1
|
||||
#define BITDHT_MGR_QUERY_PEER_OFFLINE 2
|
||||
|
@ -128,6 +129,7 @@ int status();
|
|||
int checkStatus();
|
||||
int checkPingStatus();
|
||||
int SearchOutOfDate();
|
||||
void startQueries();
|
||||
|
||||
std::map<bdNodeId, bdQueryPeer> mActivePeers;
|
||||
std::list<BitDhtCallback *> mCallbacks;
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
* #define DEBUG_NODE_MSGOUT 1
|
||||
***/
|
||||
|
||||
//#define DEBUG_NODE_MSGS 1
|
||||
|
||||
bdNode::bdNode(bdNodeId *ownId, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||
:mOwnId(*ownId), mNodeSpace(ownId, fns), mStore(bootfile, fns), mDhtVersion(dhtVersion), mFns(fns)
|
||||
|
@ -215,8 +216,9 @@ void bdNode::iteration()
|
|||
genNewTransId(&transId);
|
||||
registerOutgoingMsg(&id, &transId, BITDHT_MSG_TYPE_FIND_NODE);
|
||||
|
||||
#ifdef DEBUG_NODE_MSGS
|
||||
msgout_find_node(&id, &transId, &targetNodeId);
|
||||
|
||||
#ifdef DEBUG_NODE_MSGS
|
||||
std::cerr << "bdNode::iteration() Find Node Req for : ";
|
||||
mFns->bdPrintId(std::cerr, &id);
|
||||
std::cerr << " searching for : ";
|
||||
|
@ -391,6 +393,39 @@ void bdNode::addPeer(const bdId *id, uint32_t peerflags)
|
|||
mStore.addStore(&peer);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
// virtual so manager can do callback.
|
||||
// peer flags defined in bdiface.h
|
||||
void bdNode::PeerResponse(const bdId *id, const bdNodeId *target, uint32_t peerflags)
|
||||
{
|
||||
|
||||
#ifdef DEBUG_NODE_ACTIONS
|
||||
std::cerr << "bdNode::PeerResponse(";
|
||||
mFns->bdPrintId(std::cerr, id);
|
||||
std::cerr << ", target: ";
|
||||
mFns->bdPrintNodeId(std::cerr, target);
|
||||
fprintf(stderr, ")\n");
|
||||
#endif
|
||||
|
||||
/* iterate through queries */
|
||||
std::list<bdQuery>::iterator it;
|
||||
for(it = mLocalQueries.begin(); it != mLocalQueries.end(); it++)
|
||||
{
|
||||
it->PeerResponse(id, target, peerflags);
|
||||
}
|
||||
|
||||
mNodeSpace.add_peer(id, peerflags);
|
||||
|
||||
bdPeer peer;
|
||||
peer.mPeerId = *id;
|
||||
peer.mPeerFlags = peerflags;
|
||||
peer.mLastRecvTime = time(NULL);
|
||||
mStore.addStore(&peer);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/************************************ Query Details *************************/
|
||||
void bdNode::addQuery(const bdNodeId *id, uint32_t qflags)
|
||||
{
|
||||
|
@ -481,27 +516,27 @@ void bdNode::processRemoteQuery()
|
|||
}
|
||||
msgout_reply_find_node(&(query.mId), &(query.mTransId), nearList);
|
||||
#ifdef DEBUG_NODE_MSGS
|
||||
std::cerr << "bdNode::processRemoteQuery() Reply to Find Node: ";
|
||||
mFns->bdPrintId(std::cerr, &(query.mId));
|
||||
std::cerr << " searching for : ";
|
||||
mFns->bdPrintNodeId(std::cerr, &(query.mQuery));
|
||||
std::cerr << ", found " << nearest.size() << " nodes ";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "bdNode::processRemoteQuery() Reply to Find Node: ";
|
||||
mFns->bdPrintId(std::cerr, &(query.mId));
|
||||
std::cerr << " searching for : ";
|
||||
mFns->bdPrintNodeId(std::cerr, &(query.mQuery));
|
||||
std::cerr << ", found " << nearest.size() << " nodes ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mCounterReplyFindNode = 0;
|
||||
mCounterReplyFindNode++;
|
||||
|
||||
break;
|
||||
}
|
||||
case BD_QUERY_HASH:
|
||||
{
|
||||
#ifdef DEBUG_NODE_MSGS
|
||||
std::cerr << "bdNode::processRemoteQuery() Reply to Query Node: ";
|
||||
mFns->bdPrintId(std::cerr, &(query.mId));
|
||||
std::cerr << " TODO";
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "bdNode::processRemoteQuery() Reply to Query Node: ";
|
||||
mFns->bdPrintId(std::cerr, &(query.mId));
|
||||
std::cerr << " TODO";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
mCounterReplyQueryHash = 0;
|
||||
mCounterReplyQueryHash++;
|
||||
|
||||
|
||||
/* TODO */
|
||||
|
@ -519,6 +554,16 @@ void bdNode::processRemoteQuery()
|
|||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef DEBUG_NODE_MSGS
|
||||
std::cerr << "bdNode::processRemoteQuery() Query Too Old: Discarding: ";
|
||||
mFns->bdPrintId(std::cerr, &(query.mId));
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
mRemoteQueries.pop_front();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -176,12 +176,15 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|||
void printQueries();
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
|
||||
bdNodeId mOwnId;
|
||||
bdId mLikelyOwnId; // Try to workout own id address.
|
||||
bdSpace mNodeSpace;
|
||||
|
||||
private:
|
||||
|
||||
bdStore mStore;
|
||||
std::string mDhtVersion;
|
||||
|
||||
|
|
|
@ -734,3 +734,101 @@ int bdSpace::printDHT()
|
|||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int bdSpace::calcSizes()
|
||||
{
|
||||
std::vector<bdBucket>::iterator it;
|
||||
|
||||
/* little summary */
|
||||
unsigned long long sum = 0;
|
||||
unsigned long long no_peers = 0;
|
||||
uint32_t count = 0;
|
||||
uint32_t totalcount = 0;
|
||||
bool doPrint = false;
|
||||
bool doAvg = false;
|
||||
|
||||
int i = 0;
|
||||
for(it = buckets.begin(); it != buckets.end(); it++, i++)
|
||||
{
|
||||
int size = it->entries.size();
|
||||
totalcount += size;
|
||||
|
||||
int shift = BITDHT_KEY_BITLEN - i;
|
||||
bool toBig = false;
|
||||
|
||||
if (shift > BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1)
|
||||
{
|
||||
toBig = true;
|
||||
shift = BITDHT_ULLONG_BITS - mFns->bdBucketBitSize() - 1;
|
||||
}
|
||||
unsigned long long no_nets = ((unsigned long long) 1 << shift);
|
||||
|
||||
|
||||
/* use doPrint so it acts as a single switch */
|
||||
if (size && !doAvg && !doPrint)
|
||||
{
|
||||
doAvg = true;
|
||||
}
|
||||
|
||||
if (size && !doPrint)
|
||||
{
|
||||
doPrint = true;
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
/* reset counters - if empty slot - to discount outliers in average */
|
||||
sum = 0;
|
||||
no_peers = 0;
|
||||
count = 0;
|
||||
}
|
||||
|
||||
if (!toBig)
|
||||
{
|
||||
no_peers = no_nets * size;
|
||||
}
|
||||
|
||||
if (doPrint && doAvg && !toBig)
|
||||
{
|
||||
if (size == mFns->bdNodesPerBucket())
|
||||
{
|
||||
/* last average */
|
||||
doAvg = false;
|
||||
}
|
||||
if (no_peers != 0)
|
||||
{
|
||||
sum += no_peers;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mLastSize = totalcount;
|
||||
if (count == 0)
|
||||
{
|
||||
mLastNetSize = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
mLastNetSize = sum / count;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t bdSpace::size()
|
||||
{
|
||||
calcSizes();
|
||||
return mLastSize;
|
||||
}
|
||||
|
||||
uint32_t bdSpace::netSize()
|
||||
{
|
||||
calcSizes();
|
||||
return mLastNetSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -153,6 +153,10 @@ int out_of_date_peer(bdId &id); // side-effect updates, send flag on peer.
|
|||
int add_peer(const bdId *id, uint32_t mode);
|
||||
int printDHT();
|
||||
|
||||
int calcSizes();
|
||||
uint32_t size();
|
||||
uint32_t netSize();
|
||||
|
||||
/* to add later */
|
||||
int updateOwnId(bdNodeId *newOwnId);
|
||||
|
||||
|
@ -161,6 +165,9 @@ int updateOwnId(bdNodeId *newOwnId);
|
|||
std::vector<bdBucket> buckets;
|
||||
bdNodeId mOwnId;
|
||||
bdDhtFunctions *mFns;
|
||||
|
||||
uint32_t mLastSize;
|
||||
uint32_t mLastNetSize;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -353,9 +353,11 @@ int bdQuery::addPeer(const bdId *id, uint32_t mode)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_QUERY
|
||||
fprintf(stderr, "bdQuery::addPeer(): Closer Peer!: ");
|
||||
mFns->bdPrintId(std::cerr, id);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
/* add it in */
|
||||
bdPeer peer;
|
||||
|
@ -502,9 +504,11 @@ int bdQuery::addPotentialPeer(const bdId *id, uint32_t mode)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_QUERY
|
||||
fprintf(stderr, "bdQuery::addPotentialPeer(): Closer Peer!: ");
|
||||
mFns->bdPrintId(std::cerr, id);
|
||||
fprintf(stderr, "\n");
|
||||
#endif
|
||||
|
||||
/* add it in */
|
||||
bdPeer peer;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include "bitdht/bdiface.h"
|
||||
|
||||
#define BITDHT_STANDARD_BUCKET_SIZE 10 // 20 - too many per query.
|
||||
#define BITDHT_STANDARD_BUCKET_SIZE 10 // 20 too many per query?
|
||||
#define BITDHT_STANDARD_BUCKET_SIZE_BITS 5
|
||||
|
||||
#define BITDHT_STANDARD_N_BUCKETS BITDHT_KEY_BITLEN
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue