diff --git a/core/java/src/gnu/crypto/prng/BasePRNGStandalone.java b/core/java/src/gnu/crypto/prng/BasePRNGStandalone.java index e94f6bfc4f..6b71330d86 100644 --- a/core/java/src/gnu/crypto/prng/BasePRNGStandalone.java +++ b/core/java/src/gnu/crypto/prng/BasePRNGStandalone.java @@ -125,6 +125,8 @@ public abstract class BasePRNGStandalone implements IRandomStandalone { throw new ArrayIndexOutOfBoundsException("offset=" + offset + " length=" + length + " limit=" + out.length); + if (buffer == null) + throw new IllegalStateException("Random is shut down - do you have a static ref?"); if (ndx >= buffer.length) { fillBlock(); ndx = 0; @@ -162,6 +164,8 @@ public abstract class BasePRNGStandalone implements IRandomStandalone { } private byte nextByteInternal() {//throws LimitReachedException { + if (buffer == null) + throw new IllegalStateException("Random is shut down - do you have a static ref?"); if (ndx >= buffer.length) { this.fillBlock(); ndx = 0; diff --git a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java index ceb234c466..5c3894e1a6 100644 --- a/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java +++ b/router/java/src/net/i2p/router/peermanager/CapacityCalculator.java @@ -8,7 +8,6 @@ import net.i2p.stat.RateStat; * Estimate how many of our tunnels the peer can join per hour. */ class CapacityCalculator { - private static final I2PAppContext _context = I2PAppContext.getGlobalContext(); public static final String PROP_COUNTRY_BONUS = "profileOrganizer.sameCountryBonus"; @@ -54,11 +53,12 @@ class CapacityCalculator { // now take into account non-rejection tunnel rejections (which haven't // incremented the rejection counter, since they were only temporary) - long now = _context.clock().now(); + I2PAppContext context = profile.getContext(); + long now = context.clock().now(); if (profile.getTunnelHistory().getLastRejectedTransient() > now - 5*60*1000) capacity = 1; else if (profile.getTunnelHistory().getLastRejectedProbabalistic() > now - 5*60*1000) - capacity -= _context.random().nextInt(5); + capacity -= context.random().nextInt(5); // boost new profiles if (now - profile.getFirstHeardAbout() < 45*60*1000) @@ -69,7 +69,7 @@ class CapacityCalculator { // boost same country if (profile.isSameCountry()) { double bonus = BONUS_SAME_COUNTRY; - String b = _context.getProperty(PROP_COUNTRY_BONUS); + String b = context.getProperty(PROP_COUNTRY_BONUS); if (b != null) { try { bonus = Double.parseDouble(b); diff --git a/router/java/src/net/i2p/router/peermanager/PeerProfile.java b/router/java/src/net/i2p/router/peermanager/PeerProfile.java index 96d9273c2a..c40c26e018 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerProfile.java +++ b/router/java/src/net/i2p/router/peermanager/PeerProfile.java @@ -530,6 +530,14 @@ public class PeerProfile { /** deprecated - unused - always false */ void setIsFailing(boolean val) { _isFailing = val; } + /** + * Helper for calculators + * @since 0.9.2 + */ + RouterContext getContext() { + return _context; + } + @Override public int hashCode() { return _peer.hashCode(); } @@ -574,6 +582,7 @@ public class PeerProfile { * for an expanded profile, and ~212 bytes for a compacted one. * */ +/**** public static void main(String args[]) { RouterContext ctx = new RouterContext(new net.i2p.router.Router()); testProfileSize(ctx, 100, 0); // 560KB @@ -583,6 +592,7 @@ public class PeerProfile { testProfileSize(ctx, 0, 100000); // 21MB testProfileSize(ctx, 0, 300000); // 63MB } +****/ /** * Read in all of the profiles specified and print out @@ -590,6 +600,7 @@ public class PeerProfile { * PeerProfile [filename]* * */ +/**** public static void main2(String args[]) { RouterContext ctx = new RouterContext(new net.i2p.router.Router()); DecimalFormat fmt = new DecimalFormat("0,000.0"); @@ -654,4 +665,5 @@ public class PeerProfile { profsCompact = null; Runtime.getRuntime().gc(); } +****/ }