From 8da1e9022674156b32fc821eb40e446c154c1069 Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 19 Jan 2011 16:40:48 +0000 Subject: [PATCH] * RouterContext: Clean up clock overrides * PeerManager: Make calculators static, take out of router context --- core/java/src/net/i2p/I2PAppContext.java | 2 +- .../src/net/i2p/router/RouterContext.java | 38 +------------------ .../i2p/router/peermanager/Calculator.java | 18 --------- .../peermanager/CapacityCalculator.java | 16 ++------ .../peermanager/IntegrationCalculator.java | 15 +------- .../i2p/router/peermanager/PeerProfile.java | 20 +++------- .../router/peermanager/SpeedCalculator.java | 10 +---- 7 files changed, 17 insertions(+), 102 deletions(-) delete mode 100644 router/java/src/net/i2p/router/peermanager/Calculator.java diff --git a/core/java/src/net/i2p/I2PAppContext.java b/core/java/src/net/i2p/I2PAppContext.java index e5ec21c75..ad1140a0f 100644 --- a/core/java/src/net/i2p/I2PAppContext.java +++ b/core/java/src/net/i2p/I2PAppContext.java @@ -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; diff --git a/router/java/src/net/i2p/router/RouterContext.java b/router/java/src/net/i2p/router/RouterContext.java index 7fa3c4607..086dab8b9 100644 --- a/router/java/src/net/i2p/router/RouterContext.java +++ b/router/java/src/net/i2p/router/RouterContext.java @@ -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 _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; } } diff --git a/router/java/src/net/i2p/router/peermanager/Calculator.java b/router/java/src/net/i2p/router/peermanager/Calculator.java deleted file mode 100644 index 99fb99fd8..000000000 --- a/router/java/src/net/i2p/router/peermanager/Calculator.java +++ /dev/null @@ -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; } -} diff --git a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java index 891ca88c4..9d23ceddf 100644 --- a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java +++ b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java @@ -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)) { diff --git a/router/java/src/net/i2p/router/peermanager/IntegrationCalculator.java b/router/java/src/net/i2p/router/peermanager/IntegrationCalculator.java index f306b1995..14437e4bf 100644 --- a/router/java/src/net/i2p/router/peermanager/IntegrationCalculator.java +++ b/router/java/src/net/i2p/router/peermanager/IntegrationCalculator.java @@ -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 diff --git a/router/java/src/net/i2p/router/peermanager/PeerProfile.java b/router/java/src/net/i2p/router/peermanager/PeerProfile.java index a2665004b..6818abb96 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerProfile.java +++ b/router/java/src/net/i2p/router/peermanager/PeerProfile.java @@ -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 */ diff --git a/router/java/src/net/i2p/router/peermanager/SpeedCalculator.java b/router/java/src/net/i2p/router/peermanager/SpeedCalculator.java index c5ac1c3c5..cf1b7f069 100644 --- a/router/java/src/net/i2p/router/peermanager/SpeedCalculator.java +++ b/router/java/src/net/i2p/router/peermanager/SpeedCalculator.java @@ -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;