mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-04-22 16:09:18 -04:00
Tightened up DHT Peer Storage.
* Force a Ping of Peers without version string. * Drop peers which don't respond (very quickly) * Only re-ping if we haven't received a packet in a while. * Fixed Peer Timeout (comparision the wrong way around) * Added Peer Drop even if there is no replacement. * reduced timeout periods. * changed LocalNet to include all BitDHT clients (temporary). git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-peernet@4305 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
2abd787af1
commit
c9874176b9
@ -56,6 +56,12 @@
|
||||
|
||||
//#define DEBUG_MGR 1
|
||||
|
||||
//#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_APPL)
|
||||
#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_ENGINE)
|
||||
// This is eventually what we want.
|
||||
//#define LOCAL_NET_FLAG (BITDHT_PEER_STATUS_DHT_ENGINE_VERSION)
|
||||
|
||||
|
||||
bdNodeManager::bdNodeManager(bdNodeId *id, std::string dhtVersion, std::string bootfile, bdDhtFunctions *fns)
|
||||
:bdNode(id, dhtVersion, bootfile, fns)
|
||||
{
|
||||
@ -393,7 +399,7 @@ void bdNodeManager::QueryRandomLocalNet()
|
||||
bdId id;
|
||||
bdNodeId targetNodeId;
|
||||
|
||||
uint32_t withFlag = BITDHT_PEER_STATUS_DHT_APPL;
|
||||
uint32_t withFlag = LOCAL_NET_FLAG;
|
||||
if (mNodeSpace.findRandomPeerWithFlag(id, withFlag))
|
||||
{
|
||||
/* calculate mid point */
|
||||
@ -435,7 +441,7 @@ int bdNodeManager::status()
|
||||
/* update the network numbers */
|
||||
mNetworkSize = mNodeSpace.calcNetworkSize();
|
||||
mBdNetworkSize = mNodeSpace.calcNetworkSizeWithFlag(
|
||||
BITDHT_PEER_STATUS_DHT_APPL);
|
||||
LOCAL_NET_FLAG);
|
||||
|
||||
#ifdef DEBUG_MGR
|
||||
std::cerr << "BitDHT NetworkSize: " << mNetworkSize << std::endl;
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "bitdht/bdpeer.h"
|
||||
#include "util/bdnet.h"
|
||||
#include "bitdht/bdiface.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -310,7 +311,6 @@ int bdBucketDistance(const bdMetric *m)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
bdBucket::bdBucket()
|
||||
{
|
||||
return;
|
||||
@ -529,14 +529,52 @@ int bdSpace::out_of_date_peer(bdId &id)
|
||||
/* iterate through the buckets, and sort by distance */
|
||||
for(it = buckets.begin(); it != buckets.end(); it++)
|
||||
{
|
||||
for(eit = it->entries.begin(); eit != it->entries.end(); eit++)
|
||||
for(eit = it->entries.begin(); eit != it->entries.end(); )
|
||||
{
|
||||
/* timeout on last send time! */
|
||||
if (ts - eit->mLastSendTime > BITDHT_MAX_SEND_PERIOD )
|
||||
{
|
||||
id = eit->mPeerId;
|
||||
eit->mLastSendTime = ts;
|
||||
return 1;
|
||||
/* We want to ping a peer iff:
|
||||
* 1) They are out-of-date: mLastRecvTime is too old.
|
||||
* 2) They don't have 0x0001 flag (we haven't received a PONG) and never sent.
|
||||
*/
|
||||
if ((ts - eit->mLastRecvTime > BITDHT_MAX_SEND_PERIOD ) ||
|
||||
!(eit->mPeerFlags & BITDHT_PEER_STATUS_RECV_PONG))
|
||||
{
|
||||
id = eit->mPeerId;
|
||||
eit->mLastSendTime = ts;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* we also want to remove very old entries (should it happen here?)
|
||||
* which are not pushed out by newer entries (will happen in for closer buckets)
|
||||
*/
|
||||
|
||||
bool discard = false;
|
||||
/* discard very old entries */
|
||||
if (ts - eit->mLastRecvTime > BITDHT_DISCARD_PERIOD)
|
||||
{
|
||||
discard = true;
|
||||
}
|
||||
|
||||
/* discard peers which have not responded to anything (ie have no flags set) */
|
||||
if ((ts - eit->mFoundTime > BITDHT_MAX_RESPONSE_PERIOD ) &&
|
||||
(eit->mPeerFlags == 0))
|
||||
{
|
||||
discard = true;
|
||||
}
|
||||
|
||||
|
||||
/* INCREMENT */
|
||||
if (discard)
|
||||
{
|
||||
eit = it->entries.erase(eit);
|
||||
}
|
||||
else
|
||||
{
|
||||
eit++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -632,7 +670,7 @@ int bdSpace::add_peer(const bdId *id, uint32_t peerflags)
|
||||
{
|
||||
/* check head of list */
|
||||
bdPeer &peer = buck.entries.front();
|
||||
if (peer.mLastRecvTime - ts > BITDHT_MAX_RECV_PERIOD)
|
||||
if (ts - peer.mLastRecvTime > BITDHT_MAX_RECV_PERIOD)
|
||||
{
|
||||
#ifdef DEBUG_BD_SPACE
|
||||
std::cerr << "Dropping Out-of-Date peer in bucket" << std::endl;
|
||||
@ -673,7 +711,7 @@ int bdSpace::add_peer(const bdId *id, uint32_t peerflags)
|
||||
|
||||
newPeer.mPeerId = *id;
|
||||
newPeer.mLastRecvTime = ts;
|
||||
newPeer.mLastSendTime = ts; //????
|
||||
newPeer.mLastSendTime = 0; // ts; //????
|
||||
newPeer.mFoundTime = ts;
|
||||
newPeer.mPeerFlags = peerflags;
|
||||
|
||||
|
@ -49,8 +49,14 @@
|
||||
|
||||
#define BITDHT_ULLONG_BITS 64
|
||||
|
||||
#define BITDHT_MAX_SEND_PERIOD 600 // retry every 10 secs.
|
||||
#define BITDHT_MAX_RECV_PERIOD 1500 // out-of-date
|
||||
#define BITDHT_MAX_RESPONSE_PERIOD (15)
|
||||
#define BITDHT_MAX_SEND_PERIOD 300 // 5 minutes.
|
||||
#define BITDHT_MAX_RECV_PERIOD (BITDHT_MAX_SEND_PERIOD + BITDHT_MAX_RESPONSE_PERIOD) // didn't respond to a ping.
|
||||
|
||||
// Properly out of date.
|
||||
#define BITDHT_DISCARD_PERIOD (2 * BITDHT_MAX_SEND_PERIOD + BITDHT_MAX_RESPONSE_PERIOD) // didn't respond to two pings.
|
||||
|
||||
// Must have a FLAG by this time. (Make it really quick - so we through away the rubbish).
|
||||
|
||||
|
||||
#include <list>
|
||||
|
Loading…
x
Reference in New Issue
Block a user