diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java index 4281dee00..b63993f8c 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SybilRenderer.java @@ -390,6 +390,7 @@ class SybilRenderer { foo.add(ii); } Collections.sort(foo, new FooComparator(oc)); + boolean found = false; DecimalFormat fmt = new DecimalFormat("#0.00"); for (Integer ii : foo) { int count = oc.count(ii); @@ -409,11 +410,14 @@ class SybilRenderer { continue; if ((ip[2] & 0xff) != i2) continue; + found = true; renderRouterInfo(buf, info, null, false, false); double point = POINTS24 * (count - 1); addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other"); } } + if (!found) + buf.append("
None
"); out.write(buf.toString()); out.flush(); buf.setLength(0); @@ -437,6 +441,7 @@ class SybilRenderer { foo.add(ii); } Collections.sort(foo, new FooComparator(oc)); + boolean found = false; DecimalFormat fmt = new DecimalFormat("#0.00"); for (Integer ii : foo) { int count = oc.count(ii); @@ -453,11 +458,14 @@ class SybilRenderer { continue; if ((ip[1] & 0xff) != i1) continue; + found = true; renderRouterInfo(buf, info, null, false, false); double point = POINTS16 * (count - 1); addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other"); } } + if (!found) + buf.append("None
"); out.write(buf.toString()); out.flush(); buf.setLength(0); diff --git a/router/java/src/net/i2p/router/peermanager/PeerProfile.java b/router/java/src/net/i2p/router/peermanager/PeerProfile.java index a2f598afa..3a6c02fa7 100644 --- a/router/java/src/net/i2p/router/peermanager/PeerProfile.java +++ b/router/java/src/net/i2p/router/peermanager/PeerProfile.java @@ -40,7 +40,7 @@ public class PeerProfile { private long _lastSentToSuccessfully; private long _lastFailedSend; private long _lastHeardFrom; - private double _tunnelTestResponseTimeAvg; + private float _tunnelTestResponseTimeAvg; // periodic rates //private RateStat _sendSuccessSize = null; //private RateStat _receiveSize = null; @@ -54,13 +54,15 @@ public class PeerProfile { private int _capacityBonus; private int _integrationBonus; // calculation values - private double _speedValue; - private double _capacityValue; - private double _integrationValue; + // floats to save some space + private float _speedValue; + private float _capacityValue; + private float _integrationValue; private boolean _isFailing; // new calculation values, to be updated - private double _speedValueNew; - private double _capacityValueNew; + // floats to save some space + private float _speedValueNew; + private float _capacityValueNew; // are we in coalescing state? private boolean _coalescing; // good vs bad behavior @@ -71,6 +73,24 @@ public class PeerProfile { private boolean _expandedDB; //private int _consecutiveBanlists; private final int _distance; + + /** keep track of the fastest 3 throughputs */ + private static final int THROUGHPUT_COUNT = 3; + /** + * fastest 1 minute throughput, in bytes per minute, ordered with fastest + * first. this is not synchronized, as we don't *need* perfection, and we only + * reorder/insert values on coallesce + */ + private final float _peakThroughput[] = new float[THROUGHPUT_COUNT]; + private volatile long _peakThroughputCurrentTotal; + private final float _peakTunnelThroughput[] = new float[THROUGHPUT_COUNT]; + /** total number of bytes pushed through a single tunnel in a 1 minute period */ + private final float _peakTunnel1mThroughput[] = new float[THROUGHPUT_COUNT]; + /** once a day, on average, cut the measured throughtput values in half */ + /** let's try once an hour times 3/4 */ + private static final int DROP_PERIOD_MINUTES = 60; + private static final float DEGRADE_FACTOR = 0.75f; + private long _lastCoalesceDate = System.currentTimeMillis(); /** * Countries with more than about a 2% share of the netdb. @@ -300,26 +320,26 @@ public class PeerProfile { * (or measured) max rates, allowing this speed to reflect the speed /available/. * */ - public double getSpeedValue() { return _speedValue; } + public float getSpeedValue() { return _speedValue; } /** * How many tunnels do we think this peer can handle over the next hour? * */ - public double getCapacityValue() { return _capacityValue; } + public float getCapacityValue() { return _capacityValue; } /** * How well integrated into the network is this peer (as measured by how much they've * told us that we didn't already know). Higher numbers means better integrated * */ - public double getIntegrationValue() { return _integrationValue; } + public float getIntegrationValue() { return _integrationValue; } /** * is this peer actively failing (aka not worth touching)? * deprecated - unused - always false */ public boolean getIsFailing() { return _isFailing; } - public double getTunnelTestTimeAverage() { return _tunnelTestResponseTimeAvg; } - void setTunnelTestTimeAverage(double avg) { _tunnelTestResponseTimeAvg = avg; } + public float getTunnelTestTimeAverage() { return _tunnelTestResponseTimeAvg; } + void setTunnelTestTimeAverage(float avg) { _tunnelTestResponseTimeAvg = avg; } void updateTunnelTestTimeAverage(long ms) { if (_tunnelTestResponseTimeAvg <= 0) @@ -327,42 +347,32 @@ public class PeerProfile { // weighted since we want to let the average grow quickly and shrink slowly if (ms < _tunnelTestResponseTimeAvg) - _tunnelTestResponseTimeAvg = 0.95*_tunnelTestResponseTimeAvg + .05*ms; + _tunnelTestResponseTimeAvg = 0.95f * _tunnelTestResponseTimeAvg + .05f * ms; else - _tunnelTestResponseTimeAvg = 0.75*_tunnelTestResponseTimeAvg + .25*ms; + _tunnelTestResponseTimeAvg = 0.75f * _tunnelTestResponseTimeAvg + .25f * ms; if (_log.shouldLog(Log.INFO)) _log.info("Updating tunnel test time for " + _peer.toBase64().substring(0,6) + " to " + _tunnelTestResponseTimeAvg + " via " + ms); } - /** keep track of the fastest 3 throughputs */ - private static final int THROUGHPUT_COUNT = 3; - /** - * fastest 1 minute throughput, in bytes per minute, ordered with fastest - * first. this is not synchronized, as we don't *need* perfection, and we only - * reorder/insert values on coallesce - */ - private final double _peakThroughput[] = new double[THROUGHPUT_COUNT]; - private volatile long _peakThroughputCurrentTotal; - public double getPeakThroughputKBps() { - double rv = 0; + public float getPeakThroughputKBps() { + float rv = 0; for (int i = 0; i < THROUGHPUT_COUNT; i++) rv += _peakThroughput[i]; - rv /= (60d*1024d*THROUGHPUT_COUNT); + rv /= (60 * 1024 * THROUGHPUT_COUNT); return rv; } - public void setPeakThroughputKBps(double kBps) { + public void setPeakThroughputKBps(float kBps) { _peakThroughput[0] = kBps*60*1024; //for (int i = 0; i < THROUGHPUT_COUNT; i++) // _peakThroughput[i] = kBps*60; } void dataPushed(int size) { _peakThroughputCurrentTotal += size; } - private final double _peakTunnelThroughput[] = new double[THROUGHPUT_COUNT]; /** the tunnel pushed that much data in its lifetime */ void tunnelDataTransferred(long tunnelByteLifetime) { - double lowPeak = _peakTunnelThroughput[THROUGHPUT_COUNT-1]; + float lowPeak = _peakTunnelThroughput[THROUGHPUT_COUNT-1]; if (tunnelByteLifetime > lowPeak) { synchronized (_peakTunnelThroughput) { for (int i = 0; i < THROUGHPUT_COUNT; i++) { @@ -376,22 +386,20 @@ public class PeerProfile { } } } - public double getPeakTunnelThroughputKBps() { - double rv = 0; + public float getPeakTunnelThroughputKBps() { + float rv = 0; for (int i = 0; i < THROUGHPUT_COUNT; i++) rv += _peakTunnelThroughput[i]; - rv /= (10d*60d*1024d*THROUGHPUT_COUNT); + rv /= (10 * 60 * 1024 * THROUGHPUT_COUNT); return rv; } - public void setPeakTunnelThroughputKBps(double kBps) { - _peakTunnelThroughput[0] = kBps*60d*10d*1024d; + public void setPeakTunnelThroughputKBps(float kBps) { + _peakTunnelThroughput[0] = kBps * (60 * 10 * 1024); } - /** total number of bytes pushed through a single tunnel in a 1 minute period */ - private final double _peakTunnel1mThroughput[] = new double[THROUGHPUT_COUNT]; /** the tunnel pushed that much data in a 1 minute period */ void dataPushed1m(int size) { - double lowPeak = _peakTunnel1mThroughput[THROUGHPUT_COUNT-1]; + float lowPeak = _peakTunnel1mThroughput[THROUGHPUT_COUNT-1]; if (size > lowPeak) { synchronized (_peakTunnel1mThroughput) { for (int i = 0; i < THROUGHPUT_COUNT; i++) { @@ -419,14 +427,14 @@ public class PeerProfile { * through this peer. Ever. Except that the peak values are cut in half * once a day by coalesceThroughput(). This seems way too seldom. */ - public double getPeakTunnel1mThroughputKBps() { - double rv = 0; + public float getPeakTunnel1mThroughputKBps() { + float rv = 0; for (int i = 0; i < THROUGHPUT_COUNT; i++) rv += _peakTunnel1mThroughput[i]; - rv /= (60d*1024d*THROUGHPUT_COUNT); + rv /= (60 * 1024 * THROUGHPUT_COUNT); return rv; } - public void setPeakTunnel1mThroughputKBps(double kBps) { + public void setPeakTunnel1mThroughputKBps(float kBps) { _peakTunnel1mThroughput[0] = kBps*60*1024; } @@ -499,17 +507,12 @@ public class PeerProfile { _expandedDB = true; } - /** once a day, on average, cut the measured throughtput values in half */ - /** let's try once an hour times 3/4 */ - private static final int DROP_PERIOD_MINUTES = 60; - private static final double DEGRADE_FACTOR = 0.75; - private long _lastCoalesceDate = System.currentTimeMillis(); private void coalesceThroughput() { long now = System.currentTimeMillis(); long measuredPeriod = now - _lastCoalesceDate; if (measuredPeriod >= 60*1000) { long tot = _peakThroughputCurrentTotal; - double lowPeak = _peakThroughput[THROUGHPUT_COUNT-1]; + float lowPeak = _peakThroughput[THROUGHPUT_COUNT-1]; if (tot > lowPeak) { for (int i = 0; i < THROUGHPUT_COUNT; i++) { if (tot > _peakThroughput[i]) { @@ -593,9 +596,9 @@ public class PeerProfile { _capacityValue = _capacityValueNew; } - private double calculateSpeed() { return SpeedCalculator.calc(this); } - private double calculateCapacity() { return CapacityCalculator.calc(this); } - private double calculateIntegration() { return IntegrationCalculator.calc(this); } + private float calculateSpeed() { return (float) SpeedCalculator.calc(this); } + private float calculateCapacity() { return (float) CapacityCalculator.calc(this); } + private float calculateIntegration() { return (float) 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/ProfilePersistenceHelper.java b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java index 25b1fa579..f978194d3 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java +++ b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java @@ -170,7 +170,7 @@ class ProfilePersistenceHelper { } /** @since 0.8.5 */ - private static void add(StringBuilder buf, String name, double val, String description) { + private static void add(StringBuilder buf, String name, float val, String description) { buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL); buf.append(name).append('=').append(val).append(NL).append(NL); } @@ -272,10 +272,10 @@ class ProfilePersistenceHelper { profile.setLastSendSuccessful(getLong(props, "lastSentToSuccessfully")); profile.setLastSendFailed(getLong(props, "lastFailedSend")); profile.setLastHeardFrom(getLong(props, "lastHeardFrom")); - profile.setTunnelTestTimeAverage(getDouble(props, "tunnelTestTimeAverage")); - profile.setPeakThroughputKBps(getDouble(props, "tunnelPeakThroughput")); - profile.setPeakTunnelThroughputKBps(getDouble(props, "tunnelPeakTunnelThroughput")); - profile.setPeakTunnel1mThroughputKBps(getDouble(props, "tunnelPeakTunnel1mThroughput")); + profile.setTunnelTestTimeAverage(getFloat(props, "tunnelTestTimeAverage")); + profile.setPeakThroughputKBps(getFloat(props, "tunnelPeakThroughput")); + profile.setPeakTunnelThroughputKBps(getFloat(props, "tunnelPeakTunnelThroughput")); + profile.setPeakTunnel1mThroughputKBps(getFloat(props, "tunnelPeakTunnel1mThroughput")); profile.getTunnelHistory().load(props); @@ -368,23 +368,19 @@ class ProfilePersistenceHelper { if (val != null) { try { return Long.parseLong(val); - } catch (NumberFormatException nfe) { - return 0; - } + } catch (NumberFormatException nfe) {} } return 0; } - private final static double getDouble(Properties props, String key) { + private final static float getFloat(Properties props, String key) { String val = props.getProperty(key); if (val != null) { try { - return Double.parseDouble(val); - } catch (NumberFormatException nfe) { - return 0.0; - } + return Float.parseFloat(val); + } catch (NumberFormatException nfe) {} } - return 0.0; + return 0.0f; } private void loadProps(Properties props, File file) throws IOException {