mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-12 02:55:18 -04:00
* Reduced DHT default msg rate to 5/sec. (was 50/sec)
- At this level it takes significantly longer for the searches to complete, but there are no DOS warnings on the router. This should hopefully make users happy. * Added DhtMode() Interface call to dynamically change this rate. - Can be switched between (HIGH: 50/sec, MED: 20/sec, LOW: 5/sec & TRICKLE: 3/sec) * Disable additional Queries if PotentialPeer Queue gets too big. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4703 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
8b40826940
commit
ed18152596
7 changed files with 123 additions and 41 deletions
|
@ -83,8 +83,15 @@ void bdNode::init()
|
|||
//setNodeOptions(BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT);
|
||||
setNodeOptions(0);
|
||||
|
||||
mNodeDhtMode = 0;
|
||||
setNodeDhtMode(BITDHT_MODE_TRAFFIC_DEFAULT);
|
||||
|
||||
}
|
||||
|
||||
/* Unfortunately I've ended up with 2 calls down through the heirarchy...
|
||||
* not ideal - must clean this up one day.
|
||||
*/
|
||||
|
||||
#define ATTACH_NUMBER 5
|
||||
void bdNode::setNodeOptions(uint32_t optFlags)
|
||||
{
|
||||
|
@ -99,6 +106,55 @@ void bdNode::setNodeOptions(uint32_t optFlags)
|
|||
}
|
||||
}
|
||||
|
||||
#define BDNODE_HIGH_MSG_RATE 50
|
||||
#define BDNODE_MED_MSG_RATE 10
|
||||
#define BDNODE_LOW_MSG_RATE 5
|
||||
#define BDNODE_TRICKLE_MSG_RATE 3
|
||||
|
||||
uint32_t bdNode::setNodeDhtMode(uint32_t dhtFlags)
|
||||
{
|
||||
uint32_t origFlags = mNodeDhtMode;
|
||||
mNodeDhtMode = dhtFlags;
|
||||
|
||||
uint32_t traffic = dhtFlags & BITDHT_MODE_TRAFFIC_MASK;
|
||||
|
||||
switch(traffic)
|
||||
{
|
||||
default:
|
||||
case BITDHT_MODE_TRAFFIC_DEFAULT:
|
||||
case BITDHT_MODE_TRAFFIC_LOW:
|
||||
mMaxAllowedMsgs = BDNODE_HIGH_MSG_RATE;
|
||||
break;
|
||||
case BITDHT_MODE_TRAFFIC_HIGH:
|
||||
mMaxAllowedMsgs = BDNODE_LOW_MSG_RATE;
|
||||
break;
|
||||
case BITDHT_MODE_TRAFFIC_MED:
|
||||
mMaxAllowedMsgs = BDNODE_MED_MSG_RATE;
|
||||
break;
|
||||
case BITDHT_MODE_TRAFFIC_TRICKLE:
|
||||
mMaxAllowedMsgs = BDNODE_TRICKLE_MSG_RATE;
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t relay = dhtFlags & BITDHT_MODE_RELAY_MASK;
|
||||
if (relay != (origFlags & BITDHT_MODE_RELAY_MASK))
|
||||
{
|
||||
/* changed */
|
||||
switch(relay)
|
||||
{
|
||||
default:
|
||||
case BITDHT_MODE_RELAYS_IGNORED:
|
||||
break;
|
||||
case BITDHT_MODE_RELAYS_FLAGGED:
|
||||
break;
|
||||
case BITDHT_MODE_RELAYS_ONLY:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return dhtFlags;
|
||||
}
|
||||
|
||||
|
||||
void bdNode::getOwnId(bdNodeId *id)
|
||||
{
|
||||
|
@ -169,7 +225,12 @@ void bdNode::printState()
|
|||
#ifdef USE_HISTORY
|
||||
mHistory.printMsgs();
|
||||
#endif
|
||||
std::cerr << "Outstanding Potential Peers: " << mPotentialPeers.size();
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "Outstanding Query Requests: " << mRemoteQueries.size();
|
||||
std::cerr << std::endl;
|
||||
|
||||
mAccount.printStats(std::cerr);
|
||||
}
|
||||
|
||||
|
@ -214,50 +275,25 @@ void bdNode::iteration()
|
|||
* so allow up to 90% of messages to be pings.
|
||||
*
|
||||
* ignore responses to other peers... as the number is very small generally
|
||||
*
|
||||
* The Rate IS NOW DEFINED IN NodeDhtMode.
|
||||
*/
|
||||
|
||||
#define BDNODE_MESSAGE_RATE_HIGH 1
|
||||
#define BDNODE_MESSAGE_RATE_MED 2
|
||||
#define BDNODE_MESSAGE_RATE_LOW 3
|
||||
#define BDNODE_MESSAGE_RATE_TRICKLE 4
|
||||
|
||||
#define BDNODE_HIGH_MSG_RATE 100
|
||||
#define BDNODE_MED_MSG_RATE 50
|
||||
#define BDNODE_LOW_MSG_RATE 20
|
||||
#define BDNODE_TRICKLE_MSG_RATE 5
|
||||
|
||||
int maxMsgs = BDNODE_MED_MSG_RATE;
|
||||
int mAllowedMsgRate = BDNODE_MESSAGE_RATE_MED;
|
||||
|
||||
switch(mAllowedMsgRate)
|
||||
{
|
||||
case BDNODE_MESSAGE_RATE_HIGH:
|
||||
maxMsgs = BDNODE_HIGH_MSG_RATE;
|
||||
break;
|
||||
|
||||
case BDNODE_MESSAGE_RATE_MED:
|
||||
maxMsgs = BDNODE_MED_MSG_RATE;
|
||||
break;
|
||||
|
||||
case BDNODE_MESSAGE_RATE_LOW:
|
||||
maxMsgs = BDNODE_LOW_MSG_RATE;
|
||||
break;
|
||||
|
||||
case BDNODE_MESSAGE_RATE_TRICKLE:
|
||||
maxMsgs = BDNODE_TRICKLE_MSG_RATE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int allowedPings = 0.9 * maxMsgs;
|
||||
int allowedPings = 0.9 * mMaxAllowedMsgs;
|
||||
int sentMsgs = 0;
|
||||
int sentPings = 0;
|
||||
|
||||
#define BDNODE_MAX_POTENTIAL_PEERS_MULTIPLIER 5
|
||||
|
||||
/* Disable Queries if our Ping Queue is too long */
|
||||
if (mPotentialPeers.size() > mMaxAllowedMsgs * BDNODE_MAX_POTENTIAL_PEERS_MULTIPLIER)
|
||||
{
|
||||
std::cerr << "bdNode::iteration() Disabling Queries until PotentialPeer Queue reduced";
|
||||
std::cerr << std::endl;
|
||||
allowedPings = mMaxAllowedMsgs;
|
||||
}
|
||||
|
||||
|
||||
while((mPotentialPeers.size() > 0) && (sentMsgs < allowedPings))
|
||||
{
|
||||
/* check history ... is we have pinged them already...
|
||||
|
@ -301,10 +337,11 @@ void bdNode::iteration()
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* allow each query to send up to one query... until maxMsgs has been reached */
|
||||
int sentQueries = mQueryMgr->iterateQueries(maxMsgs-sentMsgs);
|
||||
int sentQueries = mQueryMgr->iterateQueries(mMaxAllowedMsgs-sentMsgs);
|
||||
sentMsgs += sentQueries;
|
||||
|
||||
|
||||
#ifdef DEBUG_NODE_ACTIONS
|
||||
std::cerr << "bdNode::iteration() maxMsgs: " << maxMsgs << " sentPings: " << sentPings;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue