* RouterContext: Clean up clock overrides

* PeerManager: Make calculators static, take out of router context
This commit is contained in:
zzz
2011-01-19 16:40:48 +00:00
parent 0d52399b15
commit 8da1e90226
7 changed files with 17 additions and 102 deletions

View File

@ -776,7 +776,7 @@ public class I2PAppContext {
* enable simulators to play with clock skew among different instances.
*
*/
public Clock clock() { // overridden in RouterContext
public Clock clock() {
if (!_clockInitialized)
initializeClock();
return _clock;

View File

@ -9,13 +9,9 @@ import net.i2p.data.Hash;
import net.i2p.internal.InternalClientManager;
import net.i2p.router.client.ClientManagerFacadeImpl;
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
import net.i2p.router.peermanager.Calculator;
import net.i2p.router.peermanager.CapacityCalculator;
import net.i2p.router.peermanager.IntegrationCalculator;
import net.i2p.router.peermanager.PeerManagerFacadeImpl;
import net.i2p.router.peermanager.ProfileManagerImpl;
import net.i2p.router.peermanager.ProfileOrganizer;
import net.i2p.router.peermanager.SpeedCalculator;
import net.i2p.router.transport.CommSystemFacadeImpl;
import net.i2p.router.transport.FIFOBandwidthLimiter;
import net.i2p.router.transport.OutboundMessageRegistry;
@ -57,11 +53,6 @@ public class RouterContext extends I2PAppContext {
private MessageValidator _messageValidator;
private MessageStateMonitor _messageStateMonitor;
private RouterThrottle _throttle;
private RouterClock _clockX; // LINT field hides another field, hope rename won't break anything.
private Calculator _integrationCalc;
private Calculator _speedCalc;
private Calculator _capacityCalc;
private static List<RouterContext> _contexts = new ArrayList(1);
@ -147,9 +138,6 @@ public class RouterContext extends I2PAppContext {
_messageValidator = new MessageValidator(this);
_throttle = new RouterThrottleImpl(this);
//_throttle = new RouterDoSThrottle(this);
_integrationCalc = new IntegrationCalculator(this);
_speedCalc = new SpeedCalculator(this);
_capacityCalc = new CapacityCalculator(this);
}
/**
@ -271,13 +259,6 @@ public class RouterContext extends I2PAppContext {
*/
public RouterThrottle throttle() { return _throttle; }
/** how do we rank the integration of profiles? */
public Calculator integrationCalculator() { return _integrationCalc; }
/** how do we rank the speed of profiles? */
public Calculator speedCalculator() { return _speedCalc; }
/** how do we rank the capacity of profiles? */
public Calculator capacityCalculator() { return _capacityCalc; }
@Override
public String toString() {
StringBuilder buf = new StringBuilder(512);
@ -301,8 +282,6 @@ public class RouterContext extends I2PAppContext {
buf.append(_statPublisher).append('\n');
buf.append(_shitlist).append('\n');
buf.append(_messageValidator).append('\n');
buf.append(_integrationCalc).append('\n');
buf.append(_speedCalc).append('\n');
return buf.toString();
}
@ -363,24 +342,11 @@ public class RouterContext extends I2PAppContext {
return rv;
}
/**
* The context's synchronized clock, which is kept context specific only to
* enable simulators to play with clock skew among different instances.
*
* It wouldn't be necessary to override clock(), except for the reason
* that it triggers initializeClock() of which we definitely
* need the local version to run.
*/
@Override
public Clock clock() {
if (!_clockInitialized) initializeClock();
return _clockX;
}
@Override
protected void initializeClock() {
synchronized (this) {
if (_clockX == null)
_clockX = new RouterClock(this);
if (_clock == null)
_clock = new RouterClock(this);
_clockInitialized = true;
}
}

View File

@ -1,18 +0,0 @@
package net.i2p.router.peermanager;
/**
* Provide a means of quantifying a profiles fitness in some particular aspect, as well
* as to coordinate via statics the four known aspects.
*
*/
public class Calculator {
/**
* Evaluate the profile according to the current metric
*/
public double calc(PeerProfile profile) { return 0.0d; }
/**
* Evaluate the profile according to the current metric
*/
public boolean calcBoolean(PeerProfile profile) { return false; }
}

View File

@ -1,21 +1,14 @@
package net.i2p.router.peermanager;
import net.i2p.router.RouterContext;
import net.i2p.I2PAppContext;
import net.i2p.stat.Rate;
import net.i2p.stat.RateStat;
import net.i2p.util.Log;
/**
* Estimate how many of our tunnels the peer can join per hour.
*/
public class CapacityCalculator extends Calculator {
private Log _log;
private RouterContext _context;
public CapacityCalculator(RouterContext context) {
_context = context;
_log = context.logManager().getLog(CapacityCalculator.class);
}
class CapacityCalculator {
private static final I2PAppContext _context = I2PAppContext.getGlobalContext();
/** used to adjust each period so that we keep trying to expand the peer's capacity */
static long GROWTH_FACTOR = 5;
@ -23,8 +16,7 @@ public class CapacityCalculator extends Calculator {
/** the calculator estimates over a 1 hour period */
private static long ESTIMATE_PERIOD = 60*60*1000;
@Override
public double calc(PeerProfile profile) {
public static double calc(PeerProfile profile) {
double capacity;
if (tooOld(profile)) {

View File

@ -1,24 +1,13 @@
package net.i2p.router.peermanager;
import net.i2p.router.RouterContext;
import net.i2p.util.Log;
/**
* Determine how well integrated the peer is - how likely they will be useful
* to us if we are trying to get further connected.
*
*/
public class IntegrationCalculator extends Calculator {
private Log _log;
private RouterContext _context;
class IntegrationCalculator {
public IntegrationCalculator(RouterContext context) {
_context = context;
_log = context.logManager().getLog(IntegrationCalculator.class);
}
@Override
public double calc(PeerProfile profile) {
public static double calc(PeerProfile profile) {
long val = 0;
if (profile.getIsExpandedDB()) {
// give more weight to recent counts

View File

@ -24,10 +24,10 @@ import net.i2p.util.Log;
*/
public class PeerProfile {
private Log _log;
private RouterContext _context;
private final Log _log;
private final RouterContext _context;
// whoozaat?
private Hash _peer;
private final Hash _peer;
// general peer stats
private long _firstHeardAbout;
private long _lastHeardAbout;
@ -65,13 +65,6 @@ public class PeerProfile {
public PeerProfile(RouterContext context, Hash peer, boolean expand) {
_context = context;
_log = context.logManager().getLog(PeerProfile.class);
_expanded = false;
_speedValue = 0;
_capacityValue = 0;
_integrationValue = 0;
_isFailing = false;
_consecutiveShitlists = 0;
_tunnelTestResponseTimeAvg = 0.0d;
_peer = peer;
// this is always true, and there are several places in the router that will NPE
// if it is false, so all need to be fixed before we can have non-expanded profiles
@ -81,7 +74,6 @@ public class PeerProfile {
/** what peer is being profiled */
public Hash getPeer() { return _peer; }
public void setPeer(Hash peer) { _peer = peer; }
/**
* are we keeping an expanded profile on the peer, or just the bare minimum.
@ -474,9 +466,9 @@ public class PeerProfile {
_log.debug("Coalesced: speed [" + _speedValue + "] capacity [" + _capacityValue + "] integration [" + _integrationValue + "] failing? [" + _isFailing + "]");
}
private double calculateSpeed() { return _context.speedCalculator().calc(this); }
private double calculateCapacity() { return _context.capacityCalculator().calc(this); }
private double calculateIntegration() { return _context.integrationCalculator().calc(this); }
private double calculateSpeed() { return SpeedCalculator.calc(this); }
private double calculateCapacity() { return CapacityCalculator.calc(this); }
private double calculateIntegration() { return IntegrationCalculator.calc(this); }
/** deprecated - unused - always false */
private boolean calculateIsFailing() { return false; }
/** deprecated - unused - always false */

View File

@ -1,7 +1,5 @@
package net.i2p.router.peermanager;
import net.i2p.router.RouterContext;
/**
* Quantify how fast the peer is - how fast they respond to our requests, how fast
* they pass messages on, etc. This should be affected both by their bandwidth/latency,
@ -13,13 +11,9 @@ import net.i2p.router.RouterContext;
* see the previous versions in change control to get 400+ lines of old code.
*
*/
public class SpeedCalculator extends Calculator {
class SpeedCalculator {
public SpeedCalculator(RouterContext context) {
}
@Override
public double calc(PeerProfile profile) {
public static double calc(PeerProfile profile) {
// measures 1 minute throughput of individual tunnels
double d = (profile.getPeakTunnel1mThroughputKBps()*1024d) + profile.getSpeedBonus();
if (d >= 0) return d;