mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-25 15:35:49 -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
5 changed files with 59 additions and 20 deletions
|
@ -2148,7 +2148,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||||
bool areProxy = (srcConnAddr->id == id->id);
|
bool areProxy = (srcConnAddr->id == id->id);
|
||||||
if (areProxy)
|
if (areProxy)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_NODE_CONNECTION
|
#ifdef DEBUG_PROXY_CONNECTION
|
||||||
std::cerr << "bdConnectManager::recvedConnectionRequest() We are MID Point for Proxy / Relay Connection.";
|
std::cerr << "bdConnectManager::recvedConnectionRequest() We are MID Point for Proxy / Relay Connection.";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2170,7 +2170,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||||
|
|
||||||
if (mNodeSpace->find_node(&(destConnAddr->id), numNodes, matchingIds, with_flag))
|
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 << "bdConnectManager::recvedConnectionRequest() Found Suitable Destination Addr";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2188,7 +2188,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||||
|
|
||||||
if (proxyOk)
|
if (proxyOk)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_NODE_CONNECTION
|
#ifdef DEBUG_PROXY_CONNECTION
|
||||||
std::cerr << "bdConnectManager::recvedConnectionRequest() Proxy Addr Ok: ";
|
std::cerr << "bdConnectManager::recvedConnectionRequest() Proxy Addr Ok: ";
|
||||||
bdStdPrintId(std::cerr, destConnAddr);
|
bdStdPrintId(std::cerr, destConnAddr);
|
||||||
std::cerr << "asking for AUTH to continue";
|
std::cerr << "asking for AUTH to continue";
|
||||||
|
@ -2215,7 +2215,7 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* clean up connection... its not going to work */
|
/* 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 << "bdConnectManager::recvedConnectionRequest() WARNING No Proxy Addr, Shutting Connect Attempt";
|
||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2227,18 +2227,25 @@ int bdConnectManager::recvedConnectionRequest(bdId *id, bdId *srcConnAddr, bdId
|
||||||
int param = 0;
|
int param = 0;
|
||||||
mPub->send_connect_msg(id, msgtype, srcConnAddr, destConnAddr, mode, param, status);
|
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
|
/* WILL NEED CALLBACK FOR FAILED PROXY ATTEMPT - TO SUPPORT RELAYS PROPERLY
|
||||||
* NODE needs to know PEERS to potentially WHITELIST!
|
* NODE needs to know PEERS to potentially WHITELIST!
|
||||||
*/
|
*/
|
||||||
if (mRelayMode == BITDHT_RELAYS_SERVER)
|
if (mRelayMode == BITDHT_RELAYS_SERVER)
|
||||||
{
|
{
|
||||||
callbackConnect(&(conn->mSrcId),&(conn->mProxyId),&(conn->mDestId),
|
#ifdef DEBUG_PROXY_CONNECTION
|
||||||
conn->mMode, conn->mPoint, param, BITDHT_CONNECT_CB_AUTH,
|
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);
|
BITDHT_CONNECT_ERROR_NOADDRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* remove connection */
|
||||||
|
bdConnectManager::cleanConnectionBySender(id, srcConnAddr, destConnAddr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -88,7 +88,8 @@ class bdDhtFunctions
|
||||||
// bdDhtFunctions();
|
// bdDhtFunctions();
|
||||||
/* setup variables */
|
/* setup variables */
|
||||||
virtual uint16_t bdNumBuckets() = 0;
|
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 uint16_t bdBucketBitSize() = 0;
|
||||||
|
|
||||||
virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric) = 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 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.
|
#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;
|
mQueryFlags = queryFlags;
|
||||||
mQueryTS = now;
|
mQueryTS = now;
|
||||||
mSearchTime = 0;
|
mSearchTime = 0;
|
||||||
mClosestListSize = (int) (1.5 * mFns->bdNodesPerBucket());
|
mClosestListSize = (int) (1.5 * mFns->bdNumQueryNodes());
|
||||||
mPotPeerCleanTS = now;
|
mPotPeerCleanTS = now;
|
||||||
|
|
||||||
mQueryIdlePeerRetryPeriod = QUERY_IDLE_RETRY_PEER_PERIOD;
|
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)) &&
|
if (((it->second.mLastRecvTime == 0) || (now - it->second.mLastRecvTime < EXPECTED_REPLY)) &&
|
||||||
(i < mFns->bdNodesPerBucket()))
|
(i < mFns->bdNumQueryNodes()))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_QUERY
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "NextQuery() Never Received @Idx(%d) notFinished = true: ", i);
|
fprintf(stderr, "NextQuery() Never Received @Idx(%d) notFinished = true: ", i);
|
||||||
|
@ -231,7 +231,7 @@ int bdQuery::nextQuery(bdId &id, bdNodeId &targetNodeId)
|
||||||
#endif
|
#endif
|
||||||
/* fall through and stop */
|
/* fall through and stop */
|
||||||
}
|
}
|
||||||
else if ((mClosest.size() < mFns->bdNodesPerBucket()) || (notFinished))
|
else if ((mClosest.size() < mFns->bdNumQueryNodes()) || (notFinished))
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_QUERY
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "NextQuery() notFinished | !size(): Query not finished / No Query\n");
|
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);
|
eit = mClosest.upper_bound(dist);
|
||||||
|
|
||||||
/* check if outside range, & bucket is full */
|
/* 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
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "Peer to far away for Potential\n");
|
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
|
#if 0
|
||||||
/* check if outside range, & bucket is full */
|
/* 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
|
#ifdef DEBUG_QUERY
|
||||||
fprintf(stderr, "Peer to far away for Potential\n");
|
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()
|
int bdQuery::trimPotentialPeers_FixedLength()
|
||||||
{
|
{
|
||||||
/* trim it back */
|
/* trim it back */
|
||||||
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNodesPerBucket()))
|
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNumQueryNodes()))
|
||||||
{
|
{
|
||||||
std::multimap<bdMetric, bdPeer>::iterator it;
|
std::multimap<bdMetric, bdPeer>::iterator it;
|
||||||
it = mPotentialPeers.end();
|
it = mPotentialPeers.end();
|
||||||
|
@ -658,7 +658,7 @@ int bdQuery::trimPotentialPeers_FixedLength()
|
||||||
|
|
||||||
int bdQuery::trimPotentialPeers_toClosest()
|
int bdQuery::trimPotentialPeers_toClosest()
|
||||||
{
|
{
|
||||||
if (mPotentialPeers.size() <= (uint32_t) (mFns->bdNodesPerBucket()))
|
if (mPotentialPeers.size() <= (uint32_t) (mFns->bdNumQueryNodes()))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
std::multimap<bdMetric, bdPeer>::reverse_iterator it;
|
std::multimap<bdMetric, bdPeer>::reverse_iterator it;
|
||||||
|
@ -666,7 +666,7 @@ int bdQuery::trimPotentialPeers_toClosest()
|
||||||
bdMetric lastClosest = it->first;
|
bdMetric lastClosest = it->first;
|
||||||
|
|
||||||
/* trim it back */
|
/* trim it back */
|
||||||
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNodesPerBucket()))
|
while(mPotentialPeers.size() > (uint32_t) (mFns->bdNumQueryNodes()))
|
||||||
{
|
{
|
||||||
std::multimap<bdMetric, bdPeer>::iterator it;
|
std::multimap<bdMetric, bdPeer>::iterator it;
|
||||||
it = mPotentialPeers.end();
|
it = mPotentialPeers.end();
|
||||||
|
|
|
@ -256,10 +256,16 @@ uint16_t bdStdDht::bdNumBuckets()
|
||||||
return BITDHT_STANDARD_N_BUCKETS;
|
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;
|
return BITDHT_STANDARD_BUCKET_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t bdStdDht::bdNumQueryNodes() /* used for queries */
|
||||||
|
{
|
||||||
|
return BITDHT_STANDARD_BUCKET_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t bdStdDht::bdBucketBitSize()
|
uint16_t bdStdDht::bdBucketBitSize()
|
||||||
{
|
{
|
||||||
return BITDHT_STANDARD_BUCKET_SIZE_BITS;
|
return BITDHT_STANDARD_BUCKET_SIZE_BITS;
|
||||||
|
@ -310,4 +316,18 @@ void bdStdDht::bdPrintNodeId(std::ostream &out, const bdNodeId *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();
|
bdStdDht();
|
||||||
/* setup variables */
|
/* setup variables */
|
||||||
virtual uint16_t bdNumBuckets();
|
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 uint16_t bdBucketBitSize();
|
||||||
|
|
||||||
virtual int bdDistance(const bdNodeId *n1, const bdNodeId *n2, bdMetric *metric);
|
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
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue