Profiles:

- Change doubles to floats to save memory
  - Move fields to top
Sybil tool: Tweaks
This commit is contained in:
zzz
2015-12-04 21:25:25 +00:00
parent 68c312139e
commit ff4d575196
3 changed files with 70 additions and 63 deletions

View File

@ -390,6 +390,7 @@ class SybilRenderer {
foo.add(ii); foo.add(ii);
} }
Collections.sort(foo, new FooComparator(oc)); Collections.sort(foo, new FooComparator(oc));
boolean found = false;
DecimalFormat fmt = new DecimalFormat("#0.00"); DecimalFormat fmt = new DecimalFormat("#0.00");
for (Integer ii : foo) { for (Integer ii : foo) {
int count = oc.count(ii); int count = oc.count(ii);
@ -409,11 +410,14 @@ class SybilRenderer {
continue; continue;
if ((ip[2] & 0xff) != i2) if ((ip[2] & 0xff) != i2)
continue; continue;
found = true;
renderRouterInfo(buf, info, null, false, false); renderRouterInfo(buf, info, null, false, false);
double point = POINTS24 * (count - 1); double point = POINTS24 * (count - 1);
addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other"); addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other");
} }
} }
if (!found)
buf.append("<p>None</p>");
out.write(buf.toString()); out.write(buf.toString());
out.flush(); out.flush();
buf.setLength(0); buf.setLength(0);
@ -437,6 +441,7 @@ class SybilRenderer {
foo.add(ii); foo.add(ii);
} }
Collections.sort(foo, new FooComparator(oc)); Collections.sort(foo, new FooComparator(oc));
boolean found = false;
DecimalFormat fmt = new DecimalFormat("#0.00"); DecimalFormat fmt = new DecimalFormat("#0.00");
for (Integer ii : foo) { for (Integer ii : foo) {
int count = oc.count(ii); int count = oc.count(ii);
@ -453,11 +458,14 @@ class SybilRenderer {
continue; continue;
if ((ip[1] & 0xff) != i1) if ((ip[1] & 0xff) != i1)
continue; continue;
found = true;
renderRouterInfo(buf, info, null, false, false); renderRouterInfo(buf, info, null, false, false);
double point = POINTS16 * (count - 1); double point = POINTS16 * (count - 1);
addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other"); addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other");
} }
} }
if (!found)
buf.append("<p>None</p>");
out.write(buf.toString()); out.write(buf.toString());
out.flush(); out.flush();
buf.setLength(0); buf.setLength(0);

View File

@ -40,7 +40,7 @@ public class PeerProfile {
private long _lastSentToSuccessfully; private long _lastSentToSuccessfully;
private long _lastFailedSend; private long _lastFailedSend;
private long _lastHeardFrom; private long _lastHeardFrom;
private double _tunnelTestResponseTimeAvg; private float _tunnelTestResponseTimeAvg;
// periodic rates // periodic rates
//private RateStat _sendSuccessSize = null; //private RateStat _sendSuccessSize = null;
//private RateStat _receiveSize = null; //private RateStat _receiveSize = null;
@ -54,13 +54,15 @@ public class PeerProfile {
private int _capacityBonus; private int _capacityBonus;
private int _integrationBonus; private int _integrationBonus;
// calculation values // calculation values
private double _speedValue; // floats to save some space
private double _capacityValue; private float _speedValue;
private double _integrationValue; private float _capacityValue;
private float _integrationValue;
private boolean _isFailing; private boolean _isFailing;
// new calculation values, to be updated // new calculation values, to be updated
private double _speedValueNew; // floats to save some space
private double _capacityValueNew; private float _speedValueNew;
private float _capacityValueNew;
// are we in coalescing state? // are we in coalescing state?
private boolean _coalescing; private boolean _coalescing;
// good vs bad behavior // good vs bad behavior
@ -71,6 +73,24 @@ public class PeerProfile {
private boolean _expandedDB; private boolean _expandedDB;
//private int _consecutiveBanlists; //private int _consecutiveBanlists;
private final int _distance; 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. * 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/. * (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? * 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 * 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 * 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)? * is this peer actively failing (aka not worth touching)?
* deprecated - unused - always false * deprecated - unused - always false
*/ */
public boolean getIsFailing() { return _isFailing; } public boolean getIsFailing() { return _isFailing; }
public double getTunnelTestTimeAverage() { return _tunnelTestResponseTimeAvg; } public float getTunnelTestTimeAverage() { return _tunnelTestResponseTimeAvg; }
void setTunnelTestTimeAverage(double avg) { _tunnelTestResponseTimeAvg = avg; } void setTunnelTestTimeAverage(float avg) { _tunnelTestResponseTimeAvg = avg; }
void updateTunnelTestTimeAverage(long ms) { void updateTunnelTestTimeAverage(long ms) {
if (_tunnelTestResponseTimeAvg <= 0) if (_tunnelTestResponseTimeAvg <= 0)
@ -327,42 +347,32 @@ public class PeerProfile {
// weighted since we want to let the average grow quickly and shrink slowly // weighted since we want to let the average grow quickly and shrink slowly
if (ms < _tunnelTestResponseTimeAvg) if (ms < _tunnelTestResponseTimeAvg)
_tunnelTestResponseTimeAvg = 0.95*_tunnelTestResponseTimeAvg + .05*ms; _tunnelTestResponseTimeAvg = 0.95f * _tunnelTestResponseTimeAvg + .05f * ms;
else else
_tunnelTestResponseTimeAvg = 0.75*_tunnelTestResponseTimeAvg + .25*ms; _tunnelTestResponseTimeAvg = 0.75f * _tunnelTestResponseTimeAvg + .25f * ms;
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Updating tunnel test time for " + _peer.toBase64().substring(0,6) _log.info("Updating tunnel test time for " + _peer.toBase64().substring(0,6)
+ " to " + _tunnelTestResponseTimeAvg + " via " + ms); + " to " + _tunnelTestResponseTimeAvg + " via " + ms);
} }
/** keep track of the fastest 3 throughputs */ public float getPeakThroughputKBps() {
private static final int THROUGHPUT_COUNT = 3; float rv = 0;
/**
* 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;
for (int i = 0; i < THROUGHPUT_COUNT; i++) for (int i = 0; i < THROUGHPUT_COUNT; i++)
rv += _peakThroughput[i]; rv += _peakThroughput[i];
rv /= (60d*1024d*THROUGHPUT_COUNT); rv /= (60 * 1024 * THROUGHPUT_COUNT);
return rv; return rv;
} }
public void setPeakThroughputKBps(double kBps) { public void setPeakThroughputKBps(float kBps) {
_peakThroughput[0] = kBps*60*1024; _peakThroughput[0] = kBps*60*1024;
//for (int i = 0; i < THROUGHPUT_COUNT; i++) //for (int i = 0; i < THROUGHPUT_COUNT; i++)
// _peakThroughput[i] = kBps*60; // _peakThroughput[i] = kBps*60;
} }
void dataPushed(int size) { _peakThroughputCurrentTotal += size; } void dataPushed(int size) { _peakThroughputCurrentTotal += size; }
private final double _peakTunnelThroughput[] = new double[THROUGHPUT_COUNT];
/** the tunnel pushed that much data in its lifetime */ /** the tunnel pushed that much data in its lifetime */
void tunnelDataTransferred(long tunnelByteLifetime) { void tunnelDataTransferred(long tunnelByteLifetime) {
double lowPeak = _peakTunnelThroughput[THROUGHPUT_COUNT-1]; float lowPeak = _peakTunnelThroughput[THROUGHPUT_COUNT-1];
if (tunnelByteLifetime > lowPeak) { if (tunnelByteLifetime > lowPeak) {
synchronized (_peakTunnelThroughput) { synchronized (_peakTunnelThroughput) {
for (int i = 0; i < THROUGHPUT_COUNT; i++) { for (int i = 0; i < THROUGHPUT_COUNT; i++) {
@ -376,22 +386,20 @@ public class PeerProfile {
} }
} }
} }
public double getPeakTunnelThroughputKBps() { public float getPeakTunnelThroughputKBps() {
double rv = 0; float rv = 0;
for (int i = 0; i < THROUGHPUT_COUNT; i++) for (int i = 0; i < THROUGHPUT_COUNT; i++)
rv += _peakTunnelThroughput[i]; rv += _peakTunnelThroughput[i];
rv /= (10d*60d*1024d*THROUGHPUT_COUNT); rv /= (10 * 60 * 1024 * THROUGHPUT_COUNT);
return rv; return rv;
} }
public void setPeakTunnelThroughputKBps(double kBps) { public void setPeakTunnelThroughputKBps(float kBps) {
_peakTunnelThroughput[0] = kBps*60d*10d*1024d; _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 */ /** the tunnel pushed that much data in a 1 minute period */
void dataPushed1m(int size) { void dataPushed1m(int size) {
double lowPeak = _peakTunnel1mThroughput[THROUGHPUT_COUNT-1]; float lowPeak = _peakTunnel1mThroughput[THROUGHPUT_COUNT-1];
if (size > lowPeak) { if (size > lowPeak) {
synchronized (_peakTunnel1mThroughput) { synchronized (_peakTunnel1mThroughput) {
for (int i = 0; i < THROUGHPUT_COUNT; i++) { 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 * through this peer. Ever. Except that the peak values are cut in half
* once a day by coalesceThroughput(). This seems way too seldom. * once a day by coalesceThroughput(). This seems way too seldom.
*/ */
public double getPeakTunnel1mThroughputKBps() { public float getPeakTunnel1mThroughputKBps() {
double rv = 0; float rv = 0;
for (int i = 0; i < THROUGHPUT_COUNT; i++) for (int i = 0; i < THROUGHPUT_COUNT; i++)
rv += _peakTunnel1mThroughput[i]; rv += _peakTunnel1mThroughput[i];
rv /= (60d*1024d*THROUGHPUT_COUNT); rv /= (60 * 1024 * THROUGHPUT_COUNT);
return rv; return rv;
} }
public void setPeakTunnel1mThroughputKBps(double kBps) { public void setPeakTunnel1mThroughputKBps(float kBps) {
_peakTunnel1mThroughput[0] = kBps*60*1024; _peakTunnel1mThroughput[0] = kBps*60*1024;
} }
@ -499,17 +507,12 @@ public class PeerProfile {
_expandedDB = true; _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() { private void coalesceThroughput() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long measuredPeriod = now - _lastCoalesceDate; long measuredPeriod = now - _lastCoalesceDate;
if (measuredPeriod >= 60*1000) { if (measuredPeriod >= 60*1000) {
long tot = _peakThroughputCurrentTotal; long tot = _peakThroughputCurrentTotal;
double lowPeak = _peakThroughput[THROUGHPUT_COUNT-1]; float lowPeak = _peakThroughput[THROUGHPUT_COUNT-1];
if (tot > lowPeak) { if (tot > lowPeak) {
for (int i = 0; i < THROUGHPUT_COUNT; i++) { for (int i = 0; i < THROUGHPUT_COUNT; i++) {
if (tot > _peakThroughput[i]) { if (tot > _peakThroughput[i]) {
@ -593,9 +596,9 @@ public class PeerProfile {
_capacityValue = _capacityValueNew; _capacityValue = _capacityValueNew;
} }
private double calculateSpeed() { return SpeedCalculator.calc(this); } private float calculateSpeed() { return (float) SpeedCalculator.calc(this); }
private double calculateCapacity() { return CapacityCalculator.calc(this); } private float calculateCapacity() { return (float) CapacityCalculator.calc(this); }
private double calculateIntegration() { return IntegrationCalculator.calc(this); } private float calculateIntegration() { return (float) IntegrationCalculator.calc(this); }
/** deprecated - unused - always false */ /** deprecated - unused - always false */
private boolean calculateIsFailing() { return false; } private boolean calculateIsFailing() { return false; }
/** deprecated - unused - always false */ /** deprecated - unused - always false */

View File

@ -170,7 +170,7 @@ class ProfilePersistenceHelper {
} }
/** @since 0.8.5 */ /** @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("# ").append(name).append(NL).append("# ").append(description).append(NL);
buf.append(name).append('=').append(val).append(NL).append(NL); buf.append(name).append('=').append(val).append(NL).append(NL);
} }
@ -272,10 +272,10 @@ class ProfilePersistenceHelper {
profile.setLastSendSuccessful(getLong(props, "lastSentToSuccessfully")); profile.setLastSendSuccessful(getLong(props, "lastSentToSuccessfully"));
profile.setLastSendFailed(getLong(props, "lastFailedSend")); profile.setLastSendFailed(getLong(props, "lastFailedSend"));
profile.setLastHeardFrom(getLong(props, "lastHeardFrom")); profile.setLastHeardFrom(getLong(props, "lastHeardFrom"));
profile.setTunnelTestTimeAverage(getDouble(props, "tunnelTestTimeAverage")); profile.setTunnelTestTimeAverage(getFloat(props, "tunnelTestTimeAverage"));
profile.setPeakThroughputKBps(getDouble(props, "tunnelPeakThroughput")); profile.setPeakThroughputKBps(getFloat(props, "tunnelPeakThroughput"));
profile.setPeakTunnelThroughputKBps(getDouble(props, "tunnelPeakTunnelThroughput")); profile.setPeakTunnelThroughputKBps(getFloat(props, "tunnelPeakTunnelThroughput"));
profile.setPeakTunnel1mThroughputKBps(getDouble(props, "tunnelPeakTunnel1mThroughput")); profile.setPeakTunnel1mThroughputKBps(getFloat(props, "tunnelPeakTunnel1mThroughput"));
profile.getTunnelHistory().load(props); profile.getTunnelHistory().load(props);
@ -368,23 +368,19 @@ class ProfilePersistenceHelper {
if (val != null) { if (val != null) {
try { try {
return Long.parseLong(val); return Long.parseLong(val);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {}
return 0;
}
} }
return 0; 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); String val = props.getProperty(key);
if (val != null) { if (val != null) {
try { try {
return Double.parseDouble(val); return Float.parseFloat(val);
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {}
return 0.0;
}
} }
return 0.0; return 0.0f;
} }
private void loadProps(Properties props, File file) throws IOException { private void loadProps(Properties props, File file) throws IOException {