Changes to support the delay / bandwidth changes in libbitdht

* switched off the TESTING PERIODS.
 * added BASE PROXY wait time.
 * Increased PEERNET_CONNECT_TIMEOUT to 120
 * Prevented connection startup with Request underway (dpd->mPeerReqState == RSDHT_PEERREQ_RUNNING)
 * corrected calculation of Exclusive Delay (Target of MIN_DETERMINISTIC_SWITCH_PERIOD = 60 secs).
 * don't do UDP Failed ConnectLogic update when connection was initiated remotely.
 * Extended UdpRelay to allow flexible Bandwidth limits in the future.
 * Added Timeout for Relays (30min for unknowns - 2hrs for friends).
 * Extract bandwidth from UdpRelay, at installation.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4463 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-17 23:41:30 +00:00
parent 551e2594bb
commit 96ec46478a
6 changed files with 174 additions and 61 deletions

View file

@ -213,10 +213,12 @@ int UdpRelayReceiver::checkRelays()
std::cerr << " using bandwidth: " << rit->second.mBandwidth;
std::cerr << std::endl;
if (rit->second.mBandwidth > RELAY_MAX_BANDWIDTH)
if (rit->second.mBandwidth > rit->second.mBandwidthLimit)
{
std::cerr << "UdpRelayReceiver::checkRelays()";
std::cerr << "Dropping Relay due to excessive Bandwidth: " << rit->first;
std::cerr << "UdpRelayReceiver::checkRelays() ";
std::cerr << "Dropping Relay due to excessive Bandwidth: " << rit->second.mBandwidth;
std::cerr << " Exceeding Limit: " << rit->second.mBandwidthLimit;
std::cerr << " Relay: " << rit->first;
std::cerr << std::endl;
/* if exceeding bandwidth -> drop */
@ -225,11 +227,39 @@ int UdpRelayReceiver::checkRelays()
else if (now - rit->second.mLastTS > RELAY_TIMEOUT)
{
/* if haven't transmitted for ages -> drop */
std::cerr << "UdpRelayReceiver::checkRelays()";
std::cerr << "UdpRelayReceiver::checkRelays() ";
std::cerr << "Dropping Relay due to Timeout: " << rit->first;
std::cerr << std::endl;
eraseList.push_back(rit->first);
}
else
{
/* check the length of the relay - we will drop them after a certain amount of time */
int lifetime = 0;
switch(rit->second.mRelayClass)
{
default:
case UDP_RELAY_CLASS_GENERAL:
lifetime = UDP_RELAY_LIFETIME_GENERAL;
break;
case UDP_RELAY_CLASS_FOF:
lifetime = UDP_RELAY_LIFETIME_FOF;
break;
case UDP_RELAY_CLASS_FRIENDS:
lifetime = UDP_RELAY_LIFETIME_FRIENDS;
break;
}
if (now - rit->second.mStartTS > lifetime)
{
std::cerr << "UdpRelayReceiver::checkRelays() ";
std::cerr << "Dropping Relay due to Passing Lifetime Limit: " << lifetime;
std::cerr << " for class: " << rit->second.mRelayClass;
std::cerr << " Relay: " << rit->first;
std::cerr << std::endl;
eraseList.push_back(rit->first);
}
}
}
std::list<UdpRelayAddrSet>::iterator it;
@ -249,7 +279,7 @@ int UdpRelayReceiver::removeUdpRelay(UdpRelayAddrSet *addrSet)
}
int UdpRelayReceiver::addUdpRelay(UdpRelayAddrSet *addrSet, int relayClass)
int UdpRelayReceiver::addUdpRelay(UdpRelayAddrSet *addrSet, int relayClass, uint32_t &bandwidth)
{
RsStackMutex stack(relayMtx); /********** LOCK MUTEX *********/
@ -279,6 +309,9 @@ int UdpRelayReceiver::addUdpRelay(UdpRelayAddrSet *addrSet, int relayClass)
mRelays[*addrSet] = udpRelay;
mRelays[alt] = altUdpRelay;
/* grab bandwidth from one set */
bandwidth = altUdpRelay.mBandwidthLimit;
return 1;
}
@ -799,6 +832,9 @@ UdpRelayProxy::UdpRelayProxy()
mLastBandwidthTS = 0;
mLastTS = time(NULL); // Must be set here, otherwise Proxy Timesout before anything can happen!
mRelayClass = 0;
mStartTS = time(NULL);
mBandwidthLimit = 0;
}
UdpRelayProxy::UdpRelayProxy(UdpRelayAddrSet *addrSet, int relayClass)
@ -810,6 +846,22 @@ UdpRelayProxy::UdpRelayProxy(UdpRelayAddrSet *addrSet, int relayClass)
mDataSize = 0;
mLastBandwidthTS = 0;
mLastTS = time(NULL);
mStartTS = time(NULL);
switch(relayClass)
{
default:
case UDP_RELAY_CLASS_GENERAL:
mBandwidthLimit = RELAY_MAX_BANDWIDTH;
break;
case UDP_RELAY_CLASS_FOF:
mBandwidthLimit = RELAY_MAX_BANDWIDTH;
break;
case UDP_RELAY_CLASS_FRIENDS:
mBandwidthLimit = RELAY_MAX_BANDWIDTH;
break;
}
}
UdpRelayEnd::UdpRelayEnd()

View file

@ -57,6 +57,9 @@ class UdpRelayProxy
time_t mLastBandwidthTS;
time_t mLastTS;
time_t mStartTS;
double mBandwidthLimit;
int mRelayClass;
};
@ -100,6 +103,15 @@ std::ostream &operator<<(std::ostream &out, const UdpRelayEnd &ure);
#define UDP_RELAY_CLASS_FOF 2
#define UDP_RELAY_CLASS_FRIENDS 3
// Just for some testing fun!
//#define UDP_RELAY_LIFETIME_GENERAL 180 // 3 minutes
//#define UDP_RELAY_LIFETIME_FOF 360 // 6 minutes.
//#define UDP_RELAY_LIFETIME_FRIENDS 720 // 12 minutes.
#define UDP_RELAY_LIFETIME_GENERAL 1800 // 30 minutes
#define UDP_RELAY_LIFETIME_FOF 3600 // 1 Hour.
#define UDP_RELAY_LIFETIME_FRIENDS 7200 // 2 Hour.
#define STD_RELAY_TTL 64
class UdpRelayReceiver: public UdpSubReceiver
@ -119,7 +131,7 @@ int removeUdpPeer(UdpPeer *peer);
* the end-points drop the connections
*/
int addUdpRelay(UdpRelayAddrSet *addrs, int classIdx);
int addUdpRelay(UdpRelayAddrSet *addrSet, int relayClass, uint32_t &bandwidth);
int removeUdpRelay(UdpRelayAddrSet *addrs);
/* Need some stats, to work out how many relays we are supporting */