mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
* Added NumQueryNodes() function to bdDhtFunctions.
* Switched bdquery.cc to use bdNumQueryNodes(). * Extended bdStdDht class to bdModDht to allow NodesPerBucket to be modified. * Fixed up Connection Fail Callback for Relay Servers. * Added Extra debugging for Proxy Connections. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4794 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
9e5e07d3f0
commit
fe955c9a4f
@ -2148,7 +2148,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||
bool areProxy = (srcConnAddr->id == id->id);
|
||||
if (areProxy)
|
||||
{
|
||||
#ifdef DEBUG_NODE_CONNECTION
|
||||
#ifdef DEBUG_PROXY_CONNECTION
|
||||
std::cerr << "bdConnectManager::recvedConnectionRequest() We are MID Point for Proxy / Relay Connection.";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -2170,7 +2170,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||
|
||||
if (mNodeSpace->find_node(&(destConnAddr->id), numNodes, matchingIds, with_flag))
|
||||
{
|
||||
#ifdef DEBUG_NODE_CONNECTION
|
||||
#ifdef DEBUG_PROXY_CONNECTION
|
||||
std::cerr << "bdConnectManager::recvedConnectionRequest() Found Suitable Destination Addr";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -2188,7 +2188,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||
|
||||
if (proxyOk)
|
||||
{
|
||||
#ifdef DEBUG_NODE_CONNECTION
|
||||
#ifdef DEBUG_PROXY_CONNECTION
|
||||
std::cerr << "bdConnectManager::recvedConnectionRequest() Proxy Addr Ok: ";
|
||||
bdStdPrintId(std::cerr, destConnAddr);
|
||||
std::cerr << "asking for AUTH to continue";
|
||||
@ -2215,7 +2215,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||
else
|
||||
{
|
||||
/* clean up connection... its not going to work */
|
||||
#ifdef DEBUG_NODE_CONNECTION
|
||||
#ifdef DEBUG_PROXY_CONNECTION
|
||||
std::cerr << "bdConnectManager::recvedConnectionRequest() WARNING No Proxy Addr, Shutting Connect Attempt";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
@ -2227,18 +2227,25 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||
int param = 0;
|
||||
mPub->send_connect_msg(id, msgtype, srcConnAddr, destConnAddr, mode, param, status);
|
||||
|
||||
/* remove connection */
|
||||
bdConnectManager::cleanConnectionBySender(id, srcConnAddr, destConnAddr);
|
||||
|
||||
/* WILL NEED CALLBACK FOR FAILED PROXY ATTEMPT - TO SUPPORT RELAYS PROPERLY
|
||||
* NODE needs to know PEERS to potentially WHITELIST!
|
||||
*/
|
||||
if (mRelayMode == BITDHT_RELAYS_SERVER)
|
||||
{
|
||||
callbackConnect(&(conn->mSrcId),&(conn->mProxyId),&(conn->mDestId),
|
||||
conn->mMode, conn->mPoint, param, BITDHT_CONNECT_CB_AUTH,
|
||||
#ifdef DEBUG_PROXY_CONNECTION
|
||||
std::cerr << "bdConnectManager::recvedConnectionRequest() In RelayServer Mode, doing FAIL callbackConnect()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
bdId proxyId;
|
||||
proxyId.id = mOwnId;
|
||||
callbackConnect(srcConnAddr, &proxyId, destConnAddr, mode, point, param, BITDHT_CONNECT_CB_AUTH,
|
||||
BITDHT_CONNECT_ERROR_NOADDRESS);
|
||||
}
|
||||
|
||||
/* remove connection */
|
||||
bdConnectManager::cleanConnectionBySender(id, srcConnAddr, destConnAddr);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -88,7 +88,8 @@ class bdDhtFunctions
|
||||
// bdDhtFunctions();
|
||||
/* setup variables */
|
||||
virtual uint16_t bdNumBuckets() = 0;
|
||||
virtual uint16_t bdNodesPerBucket() = 0; /* used for query + bdspace */
|
||||
virtual uint16_t bdNodesPerBucket() = 0; /* used for bdspace */
|
||||
virtual uint16_t bdNumQueryNodes() = 0; /* used for queries */
|
||||
virtual uint16_t bdBucketBitSize() = 0;
|
||||
|
||||
virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric) = 0;
|
||||
|
@ -37,7 +37,7 @@
|
||||
**/
|
||||
|
||||
#define EXPECTED_REPLY 10 // Speed up queries
|
||||
#define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNodesPerBucket() * 30)
|
||||
#define QUERY_IDLE_RETRY_PEER_PERIOD 300 // 5min = (mFns->bdNumQueryNodes() * 30)
|
||||
#define MAX_QUERY_IDLE_PERIOD 900 // 15min.
|
||||
|
||||
|
||||
@ -82,7 +82,7 @@ bdQuery::bdQuery(const bdNodeId *id, std::list<bdId> &startList, uint32_t queryF
|
||||
mQueryFlags = queryFlags;
|
||||
mQueryTS = now;
|
||||
mSearchTime = 0;
|
||||
mClosestListSize = (int) (1.5 * mFns->bdNodesPerBucket());
|
||||
mClosestListSize = (int) (1.5 * mFns->bdNumQueryNodes());
|
||||
mPotPeerCleanTS = now;
|
||||
|
||||
mQueryIdlePeerRetryPeriod = QUERY_IDLE_RETRY_PEER_PERIOD;
|
||||
@ -174,7 +174,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
|
||||
*/
|
||||
|
||||
if (((it->second.mLastRecvTime == 0) || (now - it->second.mLastRecvTime < EXPECTED_REPLY)) &&
|
||||
(i < mFns->bdNodesPerBucket()))
|
||||
(i < mFns->bdNumQueryNodes()))
|
||||
{
|
||||
#ifdef DEBUG_QUERY
|
||||
fprintf(stderr, "NextQuery() Never Received @Idx(%d) notFinished = true: ", i);
|
||||
@ -231,7 +231,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
|
||||
#endif
|
||||
/* fall through and stop */
|
||||
}
|
||||
else if ((mClosest.size() < mFns->bdNodesPerBucket()) || (notFinished))
|
||||
else if ((mClosest.size() < mFns->bdNumQueryNodes()) || (notFinished))
|
||||
{
|
||||
#ifdef DEBUG_QUERY
|
||||
fprintf(stderr, "NextQuery() notFinished | !size(): Query not finished / No Query\n");
|
||||
@ -510,7 +510,7 @@ int bdQuery::worthyPotentialPeer(const bdId *id)
|
||||
eit = mClosest.upper_bound(dist);
|
||||
|
||||
/* check if outside range, & bucket is full */
|
||||
if ((sit == mClosest.end()) && (mClosest.size() >= mFns->bdNodesPerBucket()))
|
||||
if ((sit == mClosest.end()) && (mClosest.size() >= mFns->bdNumQueryNodes()))
|
||||
{
|
||||
#ifdef DEBUG_QUERY
|
||||
fprintf(stderr, "Peer to far away for Potential\n");
|
||||
@ -604,7 +604,7 @@ int bdQuery::updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType
|
||||
|
||||
#if 0
|
||||
/* check if outside range, & bucket is full */
|
||||
if ((sit == mPotentialPeers.end()) && (mPotentialPeers.size() >= mFns->bdNodesPerBucket()))
|
||||
if ((sit == mPotentialPeers.end()) && (mPotentialPeers.size() >= mFns->bdNumQueryNodes()))
|
||||
{
|
||||
#ifdef DEBUG_QUERY
|
||||
fprintf(stderr, "Peer to far away for Potential\n");
|
||||
@ -640,7 +640,7 @@ int bdQuery::updatePotentialPeer(const bdId *id, uint32_t mode, uint32_t addType
|
||||
int bdQuery::trimPotentialPeers_FixedLength()
|
||||
{
|
||||
/* trim it back */
|
||||
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNodesPerBucket()))
|
||||
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNumQueryNodes()))
|
||||
{
|
||||
std::multimap<bdMetric, bdPeer>::iterator it;
|
||||
it = mPotentialPeers.end();
|
||||
@ -658,7 +658,7 @@ int bdQuery::trimPotentialPeers_FixedLength()
|
||||
|
||||
int bdQuery::trimPotentialPeers_toClosest()
|
||||
{
|
||||
if (mPotentialPeers.size() <= (uint32_t) (mFns->bdNodesPerBucket()))
|
||||
if (mPotentialPeers.size() <= (uint32_t) (mFns->bdNumQueryNodes()))
|
||||
return 1;
|
||||
|
||||
std::multimap<bdMetric, bdPeer>::reverse_iterator it;
|
||||
@ -666,7 +666,7 @@ int bdQuery::trimPotentialPeers_toClosest()
|
||||
bdMetric lastClosest = it->first;
|
||||
|
||||
/* trim it back */
|
||||
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNodesPerBucket()))
|
||||
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNumQueryNodes()))
|
||||
{
|
||||
std::multimap<bdMetric, bdPeer>::iterator it;
|
||||
it = mPotentialPeers.end();
|
||||
|
@ -256,10 +256,16 @@ uint16_t bdStdDht::bdNumBuckets()
|
||||
return BITDHT_STANDARD_N_BUCKETS;
|
||||
}
|
||||
|
||||
uint16_t bdStdDht::bdNodesPerBucket() /* used for query + bdspace */
|
||||
uint16_t bdStdDht::bdNodesPerBucket() /* used for bdspace */
|
||||
{
|
||||
return BITDHT_STANDARD_BUCKET_SIZE;
|
||||
}
|
||||
|
||||
uint16_t bdStdDht::bdNumQueryNodes() /* used for queries */
|
||||
{
|
||||
return BITDHT_STANDARD_BUCKET_SIZE;
|
||||
}
|
||||
|
||||
uint16_t bdStdDht::bdBucketBitSize()
|
||||
{
|
||||
return BITDHT_STANDARD_BUCKET_SIZE_BITS;
|
||||
@ -308,6 +314,20 @@ void bdStdDht::bdPrintNodeId(std::ostream &out, const bdNodeId *a)
|
||||
{
|
||||
return bdStdPrintNodeId(out, a);
|
||||
}
|
||||
|
||||
|
||||
/**************************/
|
||||
|
||||
void bdModDht::setNodesPerBucket(uint16_t nodesPerBucket)
|
||||
{
|
||||
mNodesPerBucket = nodesPerBucket;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
uint16_t bdModDht::bdNodesPerBucket() /* used for bdspace */
|
||||
{
|
||||
return mNodesPerBucket;
|
||||
}
|
||||
|
||||
|
||||
|
@ -69,7 +69,8 @@ class bdStdDht: public bdDhtFunctions
|
||||
bdStdDht();
|
||||
/* setup variables */
|
||||
virtual uint16_t bdNumBuckets();
|
||||
virtual uint16_t bdNodesPerBucket(); /* used for query + bdspace */
|
||||
virtual uint16_t bdNodesPerBucket(); /* used for bdspace */
|
||||
virtual uint16_t bdNumQueryNodes(); /* used for queries */
|
||||
virtual uint16_t bdBucketBitSize();
|
||||
|
||||
virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric);
|
||||
@ -86,6 +87,16 @@ virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a);
|
||||
|
||||
};
|
||||
|
||||
class bdModDht: public bdStdDht
|
||||
{
|
||||
public:
|
||||
virtual void setNodesPerBucket(uint16_t nodesPerBucket);
|
||||
virtual uint16_t bdNodesPerBucket(); /* used for bdspace */
|
||||
|
||||
private:
|
||||
uint16_t mNodesPerBucket;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user