forked from I2P_Developers/i2p.i2p
* PeerManager: Fix NPE on Android (ticket #687)
This commit is contained in:
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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]*
|
||||
* </pre>
|
||||
*/
|
||||
/****
|
||||
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();
|
||||
}
|
||||
****/
|
||||
}
|
||||
|
Reference in New Issue
Block a user