From 54c052476456cbb845d464d440c7fca114d64e9e Mon Sep 17 00:00:00 2001 From: drbob Date: Tue, 10 Jan 2012 19:50:16 +0000 Subject: [PATCH] Added Low Pass Filter to Relay Bandwidth Check... To allow brief bits over the peak. git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-dhtmods@4774 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/tcponudp/udprelay.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/tcponudp/udprelay.cc b/libretroshare/src/tcponudp/udprelay.cc index 9f50ab935..78ca3241a 100644 --- a/libretroshare/src/tcponudp/udprelay.cc +++ b/libretroshare/src/tcponudp/udprelay.cc @@ -223,11 +223,19 @@ int UdpRelayReceiver::checkRelays() std::list eraseList; std::map::iterator rit; time_t now = time(NULL); + +#define BANDWIDTH_FILTER_K (0.8) for(rit = mRelays.begin(); rit != mRelays.end(); rit++) { /* calc bandwidth */ - rit->second.mBandwidth = rit->second.mDataSize / (float) (now - rit->second.mLastBandwidthTS); + //rit->second.mBandwidth = rit->second.mDataSize / (float) (now - rit->second.mLastBandwidthTS); + // Switch to a Low-Pass Filter to average it out. + float instantBandwidth = rit->second.mDataSize / (float) (now - rit->second.mLastBandwidthTS); + + rit->second.mBandwidth *= (BANDWIDTH_FILTER_K); + rit->second.mBandwidth += (1.0 - BANDWIDTH_FILTER_K) * instantBandwidth; + rit->second.mDataSize = 0; rit->second.mLastBandwidthTS = now; @@ -238,6 +246,18 @@ int UdpRelayReceiver::checkRelays() std::cerr << std::endl; #endif + // ONLY A WARNING. +#ifdef DEBUG_UDP_RELAY + if (instantBandwidth > rit->second.mBandwidthLimit) + { + std::cerr << "UdpRelayReceiver::checkRelays() "; + std::cerr << "Warning instantBandwidth: " << instantBandwidth; + std::cerr << " Exceeding Limit: " << rit->second.mBandwidthLimit; + std::cerr << " for Relay: " << rit->first; + std::cerr << std::endl; + } +#endif + if (rit->second.mBandwidth > rit->second.mBandwidthLimit) { #ifdef DEBUG_UDP_RELAY