Profiles: Omit comments from stored profiles

This commit is contained in:
zzz
2019-05-21 17:24:18 +00:00
parent 67e7e45779
commit a8f11d1834
8 changed files with 246 additions and 124 deletions

View File

@ -15,29 +15,45 @@ import net.i2p.util.Log;
class PersistenceHelper { class PersistenceHelper {
private final static String NL = System.getProperty("line.separator"); private final static String NL = System.getProperty("line.separator");
public final static void add(StringBuilder buf, String prefix, String name, String description, double value) { public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, double value) {
buf.append("# ").append(prefix).append(name).append(NL); if (addComments) {
buf.append("# ").append(description).append(NL); buf.append("# ").append(prefix).append(name).append(NL);
buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL); buf.append("# ").append(description).append(NL);
}
buf.append(prefix).append(name).append('=').append(value).append(NL);
if (addComments)
buf.append(NL);
} }
/** @since 0.8.5 */ /** @since 0.8.5 */
public final static void addDate(StringBuilder buf, String prefix, String name, String description, long value) { public final static void addDate(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
String when = value > 0 ? (new Date(value)).toString() : "Never"; if (addComments) {
add(buf, prefix, name, description + ' ' + when, value); String when = value > 0 ? (new Date(value)).toString() : "Never";
add(buf, true, prefix, name, description + ' ' + when, value);
} else {
add(buf, false, prefix, name, description, value);
}
} }
/** @since 0.8.5 */ /** @since 0.8.5 */
public final static void addTime(StringBuilder buf, String prefix, String name, String description, long value) { public final static void addTime(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
String when = DataHelper.formatDuration(value); if (addComments) {
add(buf, prefix, name, description + ' ' + when, value); String when = DataHelper.formatDuration(value);
} add(buf, true, prefix, name, description + ' ' + when, value);
} else {
add(buf, false, prefix, name, description, value);
}
}
/** @param value non-negative */ /** @param value non-negative */
public final static void add(StringBuilder buf, String prefix, String name, String description, long value) { public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) {
buf.append("# ").append(prefix).append(name).append(NL); if (addComments) {
buf.append("# ").append(description).append(NL); buf.append("# ").append(prefix).append(name).append(NL);
buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL); buf.append("# ").append(description).append(NL);
}
buf.append(prefix).append(name).append('=').append(value).append(NL);
if (addComments)
buf.append(NL);
} }
/** /**

View File

@ -452,41 +452,52 @@ public class Rate {
return out; return out;
} }
/**
* Includes comment lines
*/
public synchronized void store(String prefix, StringBuilder buf) throws IOException { public synchronized void store(String prefix, StringBuilder buf) throws IOException {
PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period); store(prefix, buf, true);
PersistenceHelper.addDate(buf, prefix, ".creationDate", }
/**
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public synchronized void store(String prefix, StringBuilder buf, boolean addComments) throws IOException {
PersistenceHelper.addTime(buf, addComments, prefix, ".period", "Length of the period:", _period);
PersistenceHelper.addDate(buf, addComments, prefix, ".creationDate",
"When was this rate created?", _creationDate); "When was this rate created?", _creationDate);
PersistenceHelper.addDate(buf, prefix, ".lastCoalesceDate", PersistenceHelper.addDate(buf, addComments, prefix, ".lastCoalesceDate",
"When did we last coalesce this rate?", "When did we last coalesce this rate?",
_lastCoalesceDate); _lastCoalesceDate);
PersistenceHelper.addDate(buf, prefix, ".currentDate", PersistenceHelper.addDate(buf, addComments, prefix, ".currentDate",
"When was this data written?", now()); "When was this data written?", now());
PersistenceHelper.add(buf, prefix, ".currentTotalValue", PersistenceHelper.add(buf, addComments, prefix, ".currentTotalValue",
"Total value of data points in the current (uncoalesced) period", _currentTotalValue); "Total value of data points in the current (uncoalesced) period", _currentTotalValue);
PersistenceHelper.add(buf, prefix, ".currentEventCount", PersistenceHelper.add(buf, addComments, prefix, ".currentEventCount",
"How many events have occurred in the current (uncoalesced) period?", _currentEventCount); "How many events have occurred in the current (uncoalesced) period?", _currentEventCount);
PersistenceHelper.addTime(buf, prefix, ".currentTotalEventTime", PersistenceHelper.addTime(buf, addComments, prefix, ".currentTotalEventTime",
"How much time have the events in the current (uncoalesced) period consumed?", "How much time have the events in the current (uncoalesced) period consumed?",
_currentTotalEventTime); _currentTotalEventTime);
PersistenceHelper.add(buf, prefix, ".lastTotalValue", PersistenceHelper.add(buf, addComments, prefix, ".lastTotalValue",
"Total value of data points in the most recent (coalesced) period", _lastTotalValue); "Total value of data points in the most recent (coalesced) period", _lastTotalValue);
PersistenceHelper.add(buf, prefix, ".lastEventCount", PersistenceHelper.add(buf, addComments, prefix, ".lastEventCount",
"How many events have occurred in the most recent (coalesced) period?", _lastEventCount); "How many events have occurred in the most recent (coalesced) period?", _lastEventCount);
PersistenceHelper.addTime(buf, prefix, ".lastTotalEventTime", PersistenceHelper.addTime(buf, addComments, prefix, ".lastTotalEventTime",
"How much time have the events in the most recent (coalesced) period consumed?", "How much time have the events in the most recent (coalesced) period consumed?",
_lastTotalEventTime); _lastTotalEventTime);
PersistenceHelper.add(buf, prefix, ".extremeTotalValue", PersistenceHelper.add(buf, addComments, prefix, ".extremeTotalValue",
"Total value of data points in the most extreme period", _extremeTotalValue); "Total value of data points in the most extreme period", _extremeTotalValue);
PersistenceHelper.add(buf, prefix, ".extremeEventCount", PersistenceHelper.add(buf, addComments, prefix, ".extremeEventCount",
"How many events have occurred in the most extreme period?", _extremeEventCount); "How many events have occurred in the most extreme period?", _extremeEventCount);
PersistenceHelper.addTime(buf, prefix, ".extremeTotalEventTime", PersistenceHelper.addTime(buf, addComments, prefix, ".extremeTotalEventTime",
"How much time have the events in the most extreme period consumed?", "How much time have the events in the most extreme period consumed?",
_extremeTotalEventTime); _extremeTotalEventTime);
PersistenceHelper.add(buf, prefix, ".lifetimeTotalValue", PersistenceHelper.add(buf, addComments, prefix, ".lifetimeTotalValue",
"Total value of data points since this stat was created", _lifetimeTotalValue); "Total value of data points since this stat was created", _lifetimeTotalValue);
PersistenceHelper.add(buf, prefix, ".lifetimeEventCount", PersistenceHelper.add(buf, addComments, prefix, ".lifetimeEventCount",
"How many events have occurred since this stat was created?", _lifetimeEventCount); "How many events have occurred since this stat was created?", _lifetimeEventCount);
PersistenceHelper.addTime(buf, prefix, ".lifetimeTotalEventTime", PersistenceHelper.addTime(buf, addComments, prefix, ".lifetimeTotalEventTime",
"How much total time was consumed by the events since this stat was created?", "How much total time was consumed by the events since this stat was created?",
_lifetimeTotalEventTime); _lifetimeTotalEventTime);
} }

View File

@ -177,22 +177,37 @@ public class RateStat {
&& DataHelper.eq(getName(), rs.getName()); && DataHelper.eq(getName(), rs.getName());
} }
/**
* Includes comment lines
*/
public void store(OutputStream out, String prefix) throws IOException { public void store(OutputStream out, String prefix) throws IOException {
store(out, prefix, true);
}
/**
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public void store(OutputStream out, String prefix, boolean addComments) throws IOException {
StringBuilder buf = new StringBuilder(1024); StringBuilder buf = new StringBuilder(1024);
buf.append(NL); if (addComments) {
buf.append("################################################################################").append(NL);
buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
buf.append("# ").append(_description).append(NL);
buf.append("# ").append(NL).append(NL);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
for (Rate r: _rates){
buf.append("#######").append(NL);
buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);
buf.append(NL); buf.append(NL);
buf.append("################################################################################").append(NL);
buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
buf.append("# ").append(_description).append(NL);
buf.append("# ").append(NL).append(NL);
out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0);
}
for (Rate r: _rates){
if (addComments) {
buf.append("#######").append(NL);
buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ")
.append(_groupName).append(" - ").append(_statName).append(NL);
buf.append(NL);
}
String curPrefix = prefix + "." + DataHelper.formatDuration(r.getPeriod()); String curPrefix = prefix + "." + DataHelper.formatDuration(r.getPeriod());
r.store(curPrefix, buf); r.store(curPrefix, buf, addComments);
out.write(buf.toString().getBytes("UTF-8")); out.write(buf.toString().getBytes("UTF-8"));
buf.setLength(0); buf.setLength(0);
} }

View File

@ -1,5 +1,22 @@
2019-05-21 zzz
* Profiles: Omit comments from stored profiles
2019-05-20 zzz
* Console: Hide some columns on /peers SSU tab unless advanced
* Installer:
- Fix -console install for Izpack 5 (ticket #2492)
- Switch to Izpack 5 for non-windows release installer
* Sybil:
- Escape % in stored reasons
- Improve error handling when loading files
- Skip comment lines in stored files
* Tunnels: Increase tunnel reuse probability
2019-05-19 zzz 2019-05-19 zzz
* Sybil: Run IP and family tests on all routers * Build: Remove dependencies on Nashorn (ticket #2367)
* Sybil:
- Run IP and family tests on all routers
- Delete old stored analysis if configured
2019-05-18 zzz 2019-05-18 zzz
* Javadoc: fixes from FreeBSD ports * Javadoc: fixes from FreeBSD ports

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 4; public final static long BUILD = 5;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";

View File

@ -237,12 +237,27 @@ public class DBHistory {
private final static String NL = System.getProperty("line.separator"); private final static String NL = System.getProperty("line.separator");
/**
* write out the data from the profile to the stream
* includes comments
*/
public void store(OutputStream out) throws IOException { public void store(OutputStream out) throws IOException {
store(out, true);
}
/**
* write out the data from the profile to the stream
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public void store(OutputStream out, boolean addComments) throws IOException {
StringBuilder buf = new StringBuilder(512); StringBuilder buf = new StringBuilder(512);
buf.append(NL); if (addComments) {
buf.append("#################").append(NL); buf.append(NL);
buf.append("# DB history").append(NL); buf.append("#################").append(NL);
buf.append("###").append(NL); buf.append("# DB history").append(NL);
buf.append("###").append(NL);
}
//add(buf, "successfulLookups", _successfulLookups, "How many times have they successfully given us what we wanted when looking for it?"); //add(buf, "successfulLookups", _successfulLookups, "How many times have they successfully given us what we wanted when looking for it?");
//add(buf, "failedLookups", _failedLookups, "How many times have we sent them a db lookup and they didn't reply?"); //add(buf, "failedLookups", _failedLookups, "How many times have we sent them a db lookup and they didn't reply?");
//add(buf, "lookupsReceived", _lookupsReceived, "How many lookups have they sent us?"); //add(buf, "lookupsReceived", _lookupsReceived, "How many lookups have they sent us?");
@ -250,23 +265,26 @@ public class DBHistory {
//add(buf, "lookupReplyInvalid", _lookupReplyInvalid, "How many of their reply values to our lookups were invalid (expired, forged, corrupted)?"); //add(buf, "lookupReplyInvalid", _lookupReplyInvalid, "How many of their reply values to our lookups were invalid (expired, forged, corrupted)?");
//add(buf, "lookupReplyNew", _lookupReplyNew, "How many of their reply values to our lookups were brand new to us?"); //add(buf, "lookupReplyNew", _lookupReplyNew, "How many of their reply values to our lookups were brand new to us?");
//add(buf, "lookupReplyOld", _lookupReplyOld, "How many of their reply values to our lookups were something we had seen before?"); //add(buf, "lookupReplyOld", _lookupReplyOld, "How many of their reply values to our lookups were something we had seen before?");
add(buf, "unpromptedDbStoreNew", _unpromptedDbStoreNew, "How times have they sent us something we didn't ask for and hadn't seen before?"); add(buf, addComments, "unpromptedDbStoreNew", _unpromptedDbStoreNew, "How times have they sent us something we didn't ask for and hadn't seen before?");
add(buf, "unpromptedDbStoreOld", _unpromptedDbStoreOld, "How times have they sent us something we didn't ask for but have seen before?"); add(buf, addComments, "unpromptedDbStoreOld", _unpromptedDbStoreOld, "How times have they sent us something we didn't ask for but have seen before?");
//add(buf, "lastLookupReceived", _lastLookupReceived, "When was the last time they send us a lookup? (milliseconds since the epoch)"); //add(buf, "lastLookupReceived", _lastLookupReceived, "When was the last time they send us a lookup? (milliseconds since the epoch)");
//add(buf, "avgDelayBetweenLookupsReceived", _avgDelayBetweenLookupsReceived, "How long is it typically between each db lookup they send us? (in milliseconds)"); //add(buf, "avgDelayBetweenLookupsReceived", _avgDelayBetweenLookupsReceived, "How long is it typically between each db lookup they send us? (in milliseconds)");
// following 4 weren't persisted until 0.9.24 // following 4 weren't persisted until 0.9.24
add(buf, "lastLookupSuccessful", _lastLookupSuccessful, "When was the last time a lookup from them succeeded? (milliseconds since the epoch)"); add(buf, addComments, "lastLookupSuccessful", _lastLookupSuccessful, "When was the last time a lookup from them succeeded? (milliseconds since the epoch)");
add(buf, "lastLookupFailed", _lastLookupFailed, "When was the last time a lookup from them failed? (milliseconds since the epoch)"); add(buf, addComments, "lastLookupFailed", _lastLookupFailed, "When was the last time a lookup from them failed? (milliseconds since the epoch)");
add(buf, "lastStoreSuccessful", _lastStoreSuccessful, "When was the last time a store to them succeeded? (milliseconds since the epoch)"); add(buf, addComments, "lastStoreSuccessful", _lastStoreSuccessful, "When was the last time a store to them succeeded? (milliseconds since the epoch)");
add(buf, "lastStoreFailed", _lastStoreFailed, "When was the last time a store to them failed? (milliseconds since the epoch)"); add(buf, addComments, "lastStoreFailed", _lastStoreFailed, "When was the last time a store to them failed? (milliseconds since the epoch)");
out.write(buf.toString().getBytes("UTF-8")); out.write(buf.toString().getBytes("UTF-8"));
_failedLookupRate.store(out, "dbHistory.failedLookupRate"); _failedLookupRate.store(out, "dbHistory.failedLookupRate", addComments);
_invalidReplyRate.store(out, "dbHistory.invalidReplyRate"); _invalidReplyRate.store(out, "dbHistory.invalidReplyRate", addComments);
} }
private static void add(StringBuilder buf, String name, long val, String description) { private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) {
buf.append("# ").append(name.toUpperCase(Locale.US)).append(NL).append("# ").append(description).append(NL); if (addComments)
buf.append("dbHistory.").append(name).append('=').append(val).append(NL).append(NL); buf.append("# ").append(name.toUpperCase(Locale.US)).append(NL).append("# ").append(description).append(NL);
buf.append("dbHistory.").append(name).append('=').append(val).append(NL);
if (addComments)
buf.append(NL);
} }

View File

@ -75,7 +75,9 @@ class ProfilePersistenceHelper {
public void setUs(Hash routerIdentHash) { _us = routerIdentHash; } public void setUs(Hash routerIdentHash) { _us = routerIdentHash; }
/** write out the data from the profile to the stream */ /**
* write out the data from the profile to the file
*/
public void writeProfile(PeerProfile profile) { public void writeProfile(PeerProfile profile) {
if (isExpired(profile.getLastSendSuccessful())) if (isExpired(profile.getLastSendSuccessful()))
return; return;
@ -85,7 +87,7 @@ class ProfilePersistenceHelper {
OutputStream fos = null; OutputStream fos = null;
try { try {
fos = new BufferedOutputStream(new GZIPOutputStream(new SecureFileOutputStream(f))); fos = new BufferedOutputStream(new GZIPOutputStream(new SecureFileOutputStream(f)));
writeProfile(profile, fos); writeProfile(profile, fos, false);
} catch (IOException ioe) { } catch (IOException ioe) {
_log.error("Error writing profile to " + f); _log.error("Error writing profile to " + f);
} finally { } finally {
@ -96,8 +98,20 @@ class ProfilePersistenceHelper {
_log.debug("Writing the profile to " + f.getName() + " took " + delay + "ms"); _log.debug("Writing the profile to " + f.getName() + " took " + delay + "ms");
} }
/** write out the data from the profile to the stream */ /**
* write out the data from the profile to the stream
* includes comments
*/
public void writeProfile(PeerProfile profile, OutputStream out) throws IOException { public void writeProfile(PeerProfile profile, OutputStream out) throws IOException {
writeProfile(profile, out, true);
}
/**
* write out the data from the profile to the stream
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public void writeProfile(PeerProfile profile, OutputStream out, boolean addComments) throws IOException {
String groups = null; String groups = null;
if (_context.profileOrganizer().isFailing(profile.getPeer())) { if (_context.profileOrganizer().isFailing(profile.getPeer())) {
groups = "Failing"; groups = "Failing";
@ -114,66 +128,79 @@ class ProfilePersistenceHelper {
} }
StringBuilder buf = new StringBuilder(512); StringBuilder buf = new StringBuilder(512);
buf.append("########################################################################").append(NL); if (addComments) {
buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL); buf.append("########################################################################").append(NL);
if (_us != null) buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL);
buf.append("# as calculated by ").append(_us.toBase64()).append(NL); if (_us != null)
buf.append("#").append(NL); buf.append("# as calculated by ").append(_us.toBase64()).append(NL);
buf.append("# Speed: ").append(profile.getSpeedValue()).append(NL); buf.append("#").append(NL);
buf.append("# Capacity: ").append(profile.getCapacityValue()).append(NL); buf.append("# Speed: ").append(profile.getSpeedValue()).append(NL);
buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL); buf.append("# Capacity: ").append(profile.getCapacityValue()).append(NL);
buf.append("# Groups: ").append(groups).append(NL); buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL);
buf.append("#").append(NL); buf.append("# Groups: ").append(groups).append(NL);
buf.append("########################################################################").append(NL); buf.append("#").append(NL);
buf.append("##").append(NL); buf.append("########################################################################").append(NL);
add(buf, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score"); buf.append("##").append(NL);
add(buf, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score"); }
add(buf, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score"); add(buf, addComments, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score");
addDate(buf, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?"); add(buf, addComments, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score");
addDate(buf, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?"); add(buf, addComments, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score");
addDate(buf, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?"); addDate(buf, addComments, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?");
addDate(buf, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?"); addDate(buf, addComments, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?");
addDate(buf, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?"); addDate(buf, addComments, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?");
add(buf, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies"); addDate(buf, addComments, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?");
add(buf, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec"); addDate(buf, addComments, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?");
add(buf, "tunnelPeakTunnelThroughput", profile.getPeakTunnelThroughputKBps(), "KBytes/sec"); add(buf, addComments, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies");
add(buf, "tunnelPeakTunnel1mThroughput", profile.getPeakTunnel1mThroughputKBps(), "KBytes/sec"); add(buf, addComments, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec");
buf.append(NL); add(buf, addComments, "tunnelPeakTunnelThroughput", profile.getPeakTunnelThroughputKBps(), "KBytes/sec");
add(buf, addComments, "tunnelPeakTunnel1mThroughput", profile.getPeakTunnel1mThroughputKBps(), "KBytes/sec");
if (addComments)
buf.append(NL);
out.write(buf.toString().getBytes("UTF-8")); out.write(buf.toString().getBytes("UTF-8"));
if (profile.getIsExpanded()) { if (profile.getIsExpanded()) {
// only write out expanded data if, uh, we've got it // only write out expanded data if, uh, we've got it
profile.getTunnelHistory().store(out); profile.getTunnelHistory().store(out, addComments);
//profile.getReceiveSize().store(out, "receiveSize"); //profile.getReceiveSize().store(out, "receiveSize");
//profile.getSendSuccessSize().store(out, "sendSuccessSize"); //profile.getSendSuccessSize().store(out, "sendSuccessSize");
profile.getTunnelCreateResponseTime().store(out, "tunnelCreateResponseTime"); profile.getTunnelCreateResponseTime().store(out, "tunnelCreateResponseTime", addComments);
profile.getTunnelTestResponseTime().store(out, "tunnelTestResponseTime"); profile.getTunnelTestResponseTime().store(out, "tunnelTestResponseTime", addComments);
} }
if (profile.getIsExpandedDB()) { if (profile.getIsExpandedDB()) {
profile.getDBHistory().store(out); profile.getDBHistory().store(out, addComments);
profile.getDbIntroduction().store(out, "dbIntroduction"); profile.getDbIntroduction().store(out, "dbIntroduction", addComments);
profile.getDbResponseTime().store(out, "dbResponseTime"); profile.getDbResponseTime().store(out, "dbResponseTime", addComments);
} }
} }
/** @since 0.8.5 */ /** @since 0.8.5 */
private static void addDate(StringBuilder buf, String name, long val, String description) { private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) {
String when = val > 0 ? (new Date(val)).toString() : "Never"; if (addComments) {
add(buf, name, val, description + ' ' + when); String when = val > 0 ? (new Date(val)).toString() : "Never";
add(buf, true, name, val, description + ' ' + when);
} else {
add(buf, false, name, val, description);
}
} }
/** @since 0.8.5 */ /** @since 0.8.5 */
private static void add(StringBuilder buf, String name, long val, String description) { private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) {
buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL); if (addComments)
buf.append(name).append('=').append(val).append(NL).append(NL); buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
buf.append(name).append('=').append(val).append(NL);
if (addComments)
buf.append(NL);
} }
/** @since 0.8.5 */ /** @since 0.8.5 */
private static void add(StringBuilder buf, String name, float val, String description) { private static void add(StringBuilder buf, boolean addComments, String name, float val, String description) {
buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL); if (addComments)
buf.append(name).append('=').append(val).append(NL).append(NL); buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
buf.append(name).append('=').append(val).append(NL);
if (addComments)
buf.append(NL);
} }
public Set<PeerProfile> readProfiles() { public Set<PeerProfile> readProfiles() {

View File

@ -137,33 +137,51 @@ public class TunnelHistory {
private final static String NL = System.getProperty("line.separator"); private final static String NL = System.getProperty("line.separator");
public void store(OutputStream out) throws IOException { public void store(OutputStream out) throws IOException {
store(out, true);
}
/**
* write out the data from the profile to the stream
* @param addComments add comment lines to the output
* @since 0.9.41
*/
public void store(OutputStream out, boolean addComments) throws IOException {
StringBuilder buf = new StringBuilder(512); StringBuilder buf = new StringBuilder(512);
buf.append(NL); if (addComments) {
buf.append("#################").append(NL); buf.append(NL);
buf.append("# Tunnel history").append(NL); buf.append("#################").append(NL);
buf.append("###").append(NL); buf.append("# Tunnel history").append(NL);
addDate(buf, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?"); buf.append("###").append(NL);
addDate(buf, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed?"); }
addDate(buf, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel (Critical response code)?"); addDate(buf, addComments, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?");
addDate(buf, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?"); addDate(buf, addComments, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed?");
addDate(buf, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?"); addDate(buf, addComments, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel (Critical response code)?");
addDate(buf, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?"); addDate(buf, addComments, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?");
add(buf, "lifetimeAgreedTo", _lifetimeAgreedTo.get(), "How many tunnels has the peer ever agreed to participate in?"); addDate(buf, addComments, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?");
add(buf, "lifetimeFailed", _lifetimeFailed.get(), "How many tunnels has the peer ever agreed to participate in that failed prematurely?"); addDate(buf, addComments, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?");
add(buf, "lifetimeRejected", _lifetimeRejected.get(), "How many tunnels has the peer ever refused to participate in?"); add(buf, addComments, "lifetimeAgreedTo", _lifetimeAgreedTo.get(), "How many tunnels has the peer ever agreed to participate in?");
add(buf, addComments, "lifetimeFailed", _lifetimeFailed.get(), "How many tunnels has the peer ever agreed to participate in that failed prematurely?");
add(buf, addComments, "lifetimeRejected", _lifetimeRejected.get(), "How many tunnels has the peer ever refused to participate in?");
out.write(buf.toString().getBytes("UTF-8")); out.write(buf.toString().getBytes("UTF-8"));
_rejectRate.store(out, "tunnelHistory.rejectRate"); _rejectRate.store(out, "tunnelHistory.rejectRate", addComments);
_failRate.store(out, "tunnelHistory.failRate"); _failRate.store(out, "tunnelHistory.failRate", addComments);
} }
private static void addDate(StringBuilder buf, String name, long val, String description) { private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) {
String when = val > 0 ? (new Date(val)).toString() : "Never"; if (addComments) {
add(buf, name, val, description + ' ' + when); String when = val > 0 ? (new Date(val)).toString() : "Never";
add(buf, true, name, val, description + ' ' + when);
} else {
add(buf, false, name, val, description);
}
} }
private static void add(StringBuilder buf, String name, long val, String description) { private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) {
buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL); if (addComments)
buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL); buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
buf.append("tunnels.").append(name).append('=').append(val).append(NL);
if (addComments)
buf.append(NL);
} }
public void load(Properties props) { public void load(Properties props) {