safer operation (for use in the sim where some things aren't always availble)
This commit is contained in:
@ -2,6 +2,7 @@ package net.i2p.router;
|
|||||||
|
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
import net.i2p.data.i2np.TunnelCreateMessage;
|
import net.i2p.data.i2np.TunnelCreateMessage;
|
||||||
|
import net.i2p.stat.RateStat;
|
||||||
import net.i2p.stat.Rate;
|
import net.i2p.stat.Rate;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -62,8 +63,11 @@ class RouterThrottleImpl implements RouterThrottle {
|
|||||||
}
|
}
|
||||||
public boolean acceptTunnelRequest(TunnelCreateMessage msg) {
|
public boolean acceptTunnelRequest(TunnelCreateMessage msg) {
|
||||||
long lag = _context.jobQueue().getMaxLag();
|
long lag = _context.jobQueue().getMaxLag();
|
||||||
Rate throttleRate = _context.statManager().getRate("router.throttleNetworkCause").getRate(10*60*1000);
|
RateStat rs = _context.statManager().getRate("router.throttleNetworkCause");
|
||||||
long throttleEvents = throttleRate.getCurrentEventCount() + throttleRate.getLastEventCount();
|
Rate r = null;
|
||||||
|
if (rs != null)
|
||||||
|
r = rs.getRate(10*60*1000);
|
||||||
|
long throttleEvents = (r != null ? r.getCurrentEventCount() + r.getLastEventCount() : 0);
|
||||||
if (throttleEvents > THROTTLE_EVENT_LIMIT) {
|
if (throttleEvents > THROTTLE_EVENT_LIMIT) {
|
||||||
if (_log.shouldLog(Log.DEBUG))
|
if (_log.shouldLog(Log.DEBUG))
|
||||||
_log.debug("Refusing tunnel request with the job lag of " + lag
|
_log.debug("Refusing tunnel request with the job lag of " + lag
|
||||||
@ -73,10 +77,20 @@ class RouterThrottleImpl implements RouterThrottle {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ok, we're not hosed, but can we handle the bandwidth requirements
|
// ok, we're not hosed, but can we handle the bandwidth requirements
|
||||||
// of another tunnel?
|
// of another tunnel?
|
||||||
double msgsPerTunnel = _context.statManager().getRate("tunnel.participatingMessagesProcessed").getRate(10*60*1000).getAverageValue();
|
rs = _context.statManager().getRate("tunnel.participatingMessagesProcessed");
|
||||||
double bytesPerMsg = _context.statManager().getRate("tunnel.relayMessageSize").getRate(10*60*1000).getAverageValue();
|
r = null;
|
||||||
|
if (rs != null)
|
||||||
|
r = rs.getRate(10*60*1000);
|
||||||
|
double msgsPerTunnel = (r != null ? r.getAverageValue() : 0);
|
||||||
|
r = null;
|
||||||
|
rs = _context.statManager().getRate("tunnel.relayMessageSize");
|
||||||
|
if (rs != null)
|
||||||
|
r = rs.getRate(10*60*1000);
|
||||||
|
double bytesPerMsg = (r != null ? r.getAverageValue() : 0);
|
||||||
double bytesPerTunnel = msgsPerTunnel * bytesPerMsg;
|
double bytesPerTunnel = msgsPerTunnel * bytesPerMsg;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user