mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-27 15:57:08 -05:00
--- Merging r4700 through r4704 --- from https://retroshare.svn.sourceforge.net/svnroot/retroshare/branches/v0.5-dhtmods
Summary Of Changes: * Reduced Default DHT Message rate from (50msg/sec) => (5msg/sec) - Searches now take longer, but it should make crappy firewalls happy. * Added Interface to allow this rate to be dynamically changed. * Bugfixes for p3BanList: removed internal IPs from Lists, fixed AddBanPeer() logic bug. * Disabled p3Dsdv, after brief test. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4705 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
commit
4c8d15de58
@ -107,6 +107,23 @@ virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a) = 0;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// DHT MODES
|
||||||
|
#define BITDHT_MODE_TRAFFIC_MASK 0x00000f00
|
||||||
|
#define BITDHT_MODE_RELAY_MASK 0x0000f000
|
||||||
|
|
||||||
|
// These are not ORd - only one can apply.
|
||||||
|
#define BITDHT_MODE_TRAFFIC_DEFAULT 0x00000000
|
||||||
|
#define BITDHT_MODE_TRAFFIC_HIGH 0x00000100
|
||||||
|
#define BITDHT_MODE_TRAFFIC_MED 0x00000200
|
||||||
|
#define BITDHT_MODE_TRAFFIC_LOW 0x00000300
|
||||||
|
#define BITDHT_MODE_TRAFFIC_TRICKLE 0x00000400
|
||||||
|
|
||||||
|
// These are not ORd - only one can apply.
|
||||||
|
#define BITDHT_MODE_RELAYS_IGNORED 0x00000000
|
||||||
|
#define BITDHT_MODE_RELAYS_FLAGGED 0x00001000
|
||||||
|
#define BITDHT_MODE_RELAYS_ONLY 0x00002000
|
||||||
|
|
||||||
|
|
||||||
/* NODE OPTIONS */
|
/* NODE OPTIONS */
|
||||||
#define BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT 0x00000001
|
#define BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT 0x00000001
|
||||||
#define BITDHT_OPTIONS_ENABLE_RELAYS 0x00000002
|
#define BITDHT_OPTIONS_ENABLE_RELAYS 0x00000002
|
||||||
@ -306,6 +323,7 @@ class bdQuerySummary
|
|||||||
|
|
||||||
#define BITDHT_INFO_CB_TYPE_BADPEER 1
|
#define BITDHT_INFO_CB_TYPE_BADPEER 1
|
||||||
|
|
||||||
|
|
||||||
class BitDhtCallback
|
class BitDhtCallback
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -370,6 +388,8 @@ virtual int stopDht() = 0;
|
|||||||
virtual int stateDht() = 0; /* STOPPED, STARTING, ACTIVE, FAILED */
|
virtual int stateDht() = 0; /* STOPPED, STARTING, ACTIVE, FAILED */
|
||||||
virtual uint32_t statsNetworkSize() = 0;
|
virtual uint32_t statsNetworkSize() = 0;
|
||||||
virtual uint32_t statsBDVersionSize() = 0; /* same version as us! */
|
virtual uint32_t statsBDVersionSize() = 0; /* same version as us! */
|
||||||
|
|
||||||
|
virtual uint32_t setDhtMode(uint32_t dhtFlags) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,6 +144,15 @@ uint32_t bdNodeManager::statsBDVersionSize()
|
|||||||
return mBdNetworkSize;
|
return mBdNetworkSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t bdNodeManager::setDhtMode(uint32_t dhtFlags)
|
||||||
|
{
|
||||||
|
/* handle options here? */
|
||||||
|
setNodeDhtMode(dhtFlags);
|
||||||
|
|
||||||
|
return dhtFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool bdNodeManager::setAttachMode(bool on)
|
bool bdNodeManager::setAttachMode(bool on)
|
||||||
{
|
{
|
||||||
if (on)
|
if (on)
|
||||||
|
@ -140,6 +140,9 @@ virtual int stopDht();
|
|||||||
virtual int stateDht(); /* STOPPED, STARTING, ACTIVE, FAILED */
|
virtual int stateDht(); /* STOPPED, STARTING, ACTIVE, FAILED */
|
||||||
virtual uint32_t statsNetworkSize();
|
virtual uint32_t statsNetworkSize();
|
||||||
virtual uint32_t statsBDVersionSize(); /* same version as us! */
|
virtual uint32_t statsBDVersionSize(); /* same version as us! */
|
||||||
|
|
||||||
|
virtual uint32_t setDhtMode(uint32_t dhtFlags);
|
||||||
|
|
||||||
/******************* Internals *************************/
|
/******************* Internals *************************/
|
||||||
|
|
||||||
// Overloaded from bdnode for external node callback.
|
// Overloaded from bdnode for external node callback.
|
||||||
|
@ -83,8 +83,15 @@ void bdNode::init()
|
|||||||
//setNodeOptions(BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT);
|
//setNodeOptions(BITDHT_OPTIONS_MAINTAIN_UNSTABLE_PORT);
|
||||||
setNodeOptions(0);
|
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
|
#define ATTACH_NUMBER 5
|
||||||
void bdNode::setNodeOptions(uint32_t optFlags)
|
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)
|
void bdNode::getOwnId(bdNodeId *id)
|
||||||
{
|
{
|
||||||
@ -169,7 +225,12 @@ void bdNode::printState()
|
|||||||
#ifdef USE_HISTORY
|
#ifdef USE_HISTORY
|
||||||
mHistory.printMsgs();
|
mHistory.printMsgs();
|
||||||
#endif
|
#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);
|
mAccount.printStats(std::cerr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,50 +275,25 @@ void bdNode::iteration()
|
|||||||
* so allow up to 90% of messages to be pings.
|
* so allow up to 90% of messages to be pings.
|
||||||
*
|
*
|
||||||
* ignore responses to other peers... as the number is very small generally
|
* 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
|
int allowedPings = 0.9 * mMaxAllowedMsgs;
|
||||||
#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 sentMsgs = 0;
|
int sentMsgs = 0;
|
||||||
int sentPings = 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))
|
while((mPotentialPeers.size() > 0) && (sentMsgs < allowedPings))
|
||||||
{
|
{
|
||||||
/* check history ... is we have pinged them already...
|
/* 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 */
|
/* 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;
|
sentMsgs += sentQueries;
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_NODE_ACTIONS
|
#ifdef DEBUG_NODE_ACTIONS
|
||||||
std::cerr << "bdNode::iteration() maxMsgs: " << maxMsgs << " sentPings: " << sentPings;
|
std::cerr << "bdNode::iteration() maxMsgs: " << maxMsgs << " sentPings: " << sentPings;
|
||||||
|
@ -123,6 +123,7 @@ class bdNode: public bdNodePublisher
|
|||||||
void init(); /* sets up the self referential classes (mQueryMgr & mConnMgr) */
|
void init(); /* sets up the self referential classes (mQueryMgr & mConnMgr) */
|
||||||
|
|
||||||
void setNodeOptions(uint32_t optFlags);
|
void setNodeOptions(uint32_t optFlags);
|
||||||
|
uint32_t setNodeDhtMode(uint32_t dhtFlags);
|
||||||
|
|
||||||
/* startup / shutdown node */
|
/* startup / shutdown node */
|
||||||
void restartNode();
|
void restartNode();
|
||||||
@ -249,6 +250,8 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
uint32_t mNodeOptionFlags;
|
uint32_t mNodeOptionFlags;
|
||||||
|
uint32_t mNodeDhtMode;
|
||||||
|
uint32_t mMaxAllowedMsgs;
|
||||||
|
|
||||||
bdHistory mHistory; /* for understanding the DHT */
|
bdHistory mHistory; /* for understanding the DHT */
|
||||||
|
|
||||||
@ -258,6 +261,7 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
|
|||||||
|
|
||||||
std::list<bdNodeNetMsg *> mOutgoingMsgs;
|
std::list<bdNodeNetMsg *> mOutgoingMsgs;
|
||||||
std::list<bdNodeNetMsg *> mIncomingMsgs;
|
std::list<bdNodeNetMsg *> mIncomingMsgs;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -249,6 +249,14 @@ uint32_t UdpBitDht::statsBDVersionSize()
|
|||||||
return mBitDhtManager->statsBDVersionSize();
|
return mBitDhtManager->statsBDVersionSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t UdpBitDht::setDhtMode(uint32_t dhtFlags)
|
||||||
|
{
|
||||||
|
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
|
||||||
|
|
||||||
|
return mBitDhtManager->setDhtMode(dhtFlags);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/******************* Internals *************************/
|
/******************* Internals *************************/
|
||||||
|
|
||||||
/***** Iteration / Loop Management *****/
|
/***** Iteration / Loop Management *****/
|
||||||
|
@ -93,6 +93,7 @@ virtual int stopDht();
|
|||||||
virtual int stateDht();
|
virtual int stateDht();
|
||||||
virtual uint32_t statsNetworkSize();
|
virtual uint32_t statsNetworkSize();
|
||||||
virtual uint32_t statsBDVersionSize();
|
virtual uint32_t statsBDVersionSize();
|
||||||
|
virtual uint32_t setDhtMode(uint32_t dhtFlags);
|
||||||
|
|
||||||
/******************* Internals *************************/
|
/******************* Internals *************************/
|
||||||
/***** Iteration / Loop Management *****/
|
/***** Iteration / Loop Management *****/
|
||||||
|
@ -879,8 +879,12 @@ bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t
|
|||||||
/* always switch it off now */
|
/* always switch it off now */
|
||||||
mNetMgr->netAssistFriend(id,false);
|
mNetMgr->netAssistFriend(id,false);
|
||||||
|
|
||||||
/* inform NetMgr that we know this peers address */
|
/* inform NetMgr that we know this peers address: but only if external address */
|
||||||
mNetMgr->netAssistKnownPeer(id,remote_peer_address, NETASSIST_KNOWN_PEER_FRIEND | NETASSIST_KNOWN_PEER_ONLINE);
|
if (isExternalNet(&(remote_peer_address.sin_addr)))
|
||||||
|
{
|
||||||
|
mNetMgr->netAssistKnownPeer(id,remote_peer_address,
|
||||||
|
NETASSIST_KNOWN_PEER_FRIEND | NETASSIST_KNOWN_PEER_ONLINE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -2135,10 +2135,12 @@ int RsServer::StartupRetroShare()
|
|||||||
pqih -> addService(mBanList);
|
pqih -> addService(mBanList);
|
||||||
mBitDht->setupPeerSharer(mBanList);
|
mBitDht->setupPeerSharer(mBanList);
|
||||||
|
|
||||||
|
#ifdef RS_DSDVTEST
|
||||||
p3Dsdv *mDsdv = new p3Dsdv(mLinkMgr);
|
p3Dsdv *mDsdv = new p3Dsdv(mLinkMgr);
|
||||||
pqih -> addService(mDsdv);
|
pqih -> addService(mDsdv);
|
||||||
rsDsdv = mDsdv;
|
rsDsdv = mDsdv;
|
||||||
mDsdv->addTestService();
|
mDsdv->addTestService();
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // MINIMAL_LIBRS
|
#endif // MINIMAL_LIBRS
|
||||||
|
|
||||||
|
@ -103,7 +103,8 @@ bool p3BanList::processIncoming()
|
|||||||
break;
|
break;
|
||||||
case RS_PKT_SUBTYPE_BANLIST_ITEM:
|
case RS_PKT_SUBTYPE_BANLIST_ITEM:
|
||||||
{
|
{
|
||||||
updated = (updated || recvBanItem((RsBanListItem *) item));
|
// Order is important!.
|
||||||
|
updated = (recvBanItem((RsBanListItem *) item) || updated);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -136,8 +137,9 @@ bool p3BanList::recvBanItem(RsBanListItem *item)
|
|||||||
std::list<RsTlvBanListEntry>::const_iterator it;
|
std::list<RsTlvBanListEntry>::const_iterator it;
|
||||||
for(it = item->peerList.entries.begin(); it != item->peerList.entries.end(); it++)
|
for(it = item->peerList.entries.begin(); it != item->peerList.entries.end(); it++)
|
||||||
{
|
{
|
||||||
updated = (updated || addBanEntry(item->PeerId(),
|
// Order is important!.
|
||||||
it->addr, it->level, it->reason, it->age));
|
updated = (addBanEntry(item->PeerId(), it->addr, it->level,
|
||||||
|
it->reason, it->age) || updated);
|
||||||
}
|
}
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
@ -173,6 +175,17 @@ bool p3BanList::addBanEntry(const std::string &peerId, const struct sockaddr_in
|
|||||||
std::cerr << std::endl;
|
std::cerr << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Only Accept it - if external address */
|
||||||
|
if (!isExternalNet(&(addr.sin_addr)))
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_BANLIST
|
||||||
|
std::cerr << "p3BanList::addBanEntry() Ignoring Non External Addr: " << rs_inet_ntoa(addr.sin_addr);
|
||||||
|
std::cerr << std::endl;
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::map<std::string, BanList>::iterator it;
|
std::map<std::string, BanList>::iterator it;
|
||||||
it = mBanSources.find(peerId);
|
it = mBanSources.find(peerId);
|
||||||
if (it == mBanSources.end())
|
if (it == mBanSources.end())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user