diff --git a/core/java/src/net/i2p/stat/PersistenceHelper.java b/core/java/src/net/i2p/stat/PersistenceHelper.java index f0994ff4f0..4d4e3db54e 100644 --- a/core/java/src/net/i2p/stat/PersistenceHelper.java +++ b/core/java/src/net/i2p/stat/PersistenceHelper.java @@ -15,29 +15,45 @@ import net.i2p.util.Log; class PersistenceHelper { private final static String NL = System.getProperty("line.separator"); - public final static void add(StringBuilder buf, String prefix, String name, String description, double value) { - buf.append("# ").append(prefix).append(name).append(NL); - buf.append("# ").append(description).append(NL); - buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL); + public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, double value) { + if (addComments) { + buf.append("# ").append(prefix).append(name).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 */ - public final static void addDate(StringBuilder buf, String prefix, String name, String description, long value) { - String when = value > 0 ? (new Date(value)).toString() : "Never"; - add(buf, prefix, name, description + ' ' + when, value); + public final static void addDate(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) { + if (addComments) { + 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 */ - public final static void addTime(StringBuilder buf, String prefix, String name, String description, long value) { - String when = DataHelper.formatDuration(value); - add(buf, prefix, name, description + ' ' + when, value); - } + public final static void addTime(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) { + if (addComments) { + 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 */ - public final static void add(StringBuilder buf, String prefix, String name, String description, long value) { - buf.append("# ").append(prefix).append(name).append(NL); - buf.append("# ").append(description).append(NL); - buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL); + public final static void add(StringBuilder buf, boolean addComments, String prefix, String name, String description, long value) { + if (addComments) { + buf.append("# ").append(prefix).append(name).append(NL); + buf.append("# ").append(description).append(NL); + } + buf.append(prefix).append(name).append('=').append(value).append(NL); + if (addComments) + buf.append(NL); } /** diff --git a/core/java/src/net/i2p/stat/Rate.java b/core/java/src/net/i2p/stat/Rate.java index d12ece8aa0..1675667a44 100644 --- a/core/java/src/net/i2p/stat/Rate.java +++ b/core/java/src/net/i2p/stat/Rate.java @@ -452,41 +452,52 @@ public class Rate { return out; } + /** + * Includes comment lines + */ public synchronized void store(String prefix, StringBuilder buf) throws IOException { - PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period); - PersistenceHelper.addDate(buf, prefix, ".creationDate", + store(prefix, buf, true); + } + + /** + * @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); - PersistenceHelper.addDate(buf, prefix, ".lastCoalesceDate", + PersistenceHelper.addDate(buf, addComments, prefix, ".lastCoalesceDate", "When did we last coalesce this rate?", _lastCoalesceDate); - PersistenceHelper.addDate(buf, prefix, ".currentDate", + PersistenceHelper.addDate(buf, addComments, prefix, ".currentDate", "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); - PersistenceHelper.add(buf, prefix, ".currentEventCount", + PersistenceHelper.add(buf, addComments, prefix, ".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?", _currentTotalEventTime); - PersistenceHelper.add(buf, prefix, ".lastTotalValue", + PersistenceHelper.add(buf, addComments, prefix, ".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); - PersistenceHelper.addTime(buf, prefix, ".lastTotalEventTime", + PersistenceHelper.addTime(buf, addComments, prefix, ".lastTotalEventTime", "How much time have the events in the most recent (coalesced) period consumed?", _lastTotalEventTime); - PersistenceHelper.add(buf, prefix, ".extremeTotalValue", + PersistenceHelper.add(buf, addComments, prefix, ".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); - PersistenceHelper.addTime(buf, prefix, ".extremeTotalEventTime", + PersistenceHelper.addTime(buf, addComments, prefix, ".extremeTotalEventTime", "How much time have the events in the most extreme period consumed?", _extremeTotalEventTime); - PersistenceHelper.add(buf, prefix, ".lifetimeTotalValue", + PersistenceHelper.add(buf, addComments, prefix, ".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); - 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?", _lifetimeTotalEventTime); } diff --git a/core/java/src/net/i2p/stat/RateStat.java b/core/java/src/net/i2p/stat/RateStat.java index 018ef19734..aaf06f1d38 100644 --- a/core/java/src/net/i2p/stat/RateStat.java +++ b/core/java/src/net/i2p/stat/RateStat.java @@ -177,22 +177,37 @@ public class RateStat { && DataHelper.eq(getName(), rs.getName()); } + /** + * Includes comment lines + */ 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); - 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){ - buf.append("#######").append(NL); - buf.append("# Period : ").append(DataHelper.formatDuration(r.getPeriod())).append(" for rate ") - .append(_groupName).append(" - ").append(_statName).append(NL); + if (addComments) { 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()); - r.store(curPrefix, buf); + r.store(curPrefix, buf, addComments); out.write(buf.toString().getBytes("UTF-8")); buf.setLength(0); } diff --git a/history.txt b/history.txt index 893dd704fb..c7e9ffaa85 100644 --- a/history.txt +++ b/history.txt @@ -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 - * 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 * Javadoc: fixes from FreeBSD ports diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index f6e6df3a5c..4e28a2c8d2 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 4; + public final static long BUILD = 5; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/peermanager/DBHistory.java b/router/java/src/net/i2p/router/peermanager/DBHistory.java index 7106b10e06..f814ddd72c 100644 --- a/router/java/src/net/i2p/router/peermanager/DBHistory.java +++ b/router/java/src/net/i2p/router/peermanager/DBHistory.java @@ -237,12 +237,27 @@ public class DBHistory { 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 { + 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); - buf.append(NL); - buf.append("#################").append(NL); - buf.append("# DB history").append(NL); - buf.append("###").append(NL); + if (addComments) { + buf.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, "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?"); @@ -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, "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, "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, "unpromptedDbStoreNew", _unpromptedDbStoreNew, "How times have they sent us something we didn't ask for and hadn't 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, "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 - add(buf, "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, "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, "lastLookupSuccessful", _lastLookupSuccessful, "When was the last time a lookup from them succeeded? (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, addComments, "lastStoreSuccessful", _lastStoreSuccessful, "When was the last time a store to them succeeded? (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")); - _failedLookupRate.store(out, "dbHistory.failedLookupRate"); - _invalidReplyRate.store(out, "dbHistory.invalidReplyRate"); + _failedLookupRate.store(out, "dbHistory.failedLookupRate", addComments); + _invalidReplyRate.store(out, "dbHistory.invalidReplyRate", addComments); } - private static void add(StringBuilder buf, String name, long val, String description) { - buf.append("# ").append(name.toUpperCase(Locale.US)).append(NL).append("# ").append(description).append(NL); - buf.append("dbHistory.").append(name).append('=').append(val).append(NL).append(NL); + private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) { + if (addComments) + 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); } diff --git a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java index 1275659100..1d5702d553 100644 --- a/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java +++ b/router/java/src/net/i2p/router/peermanager/ProfilePersistenceHelper.java @@ -75,7 +75,9 @@ class ProfilePersistenceHelper { 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) { if (isExpired(profile.getLastSendSuccessful())) return; @@ -85,7 +87,7 @@ class ProfilePersistenceHelper { OutputStream fos = null; try { fos = new BufferedOutputStream(new GZIPOutputStream(new SecureFileOutputStream(f))); - writeProfile(profile, fos); + writeProfile(profile, fos, false); } catch (IOException ioe) { _log.error("Error writing profile to " + f); } finally { @@ -96,8 +98,20 @@ class ProfilePersistenceHelper { _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 { + 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; if (_context.profileOrganizer().isFailing(profile.getPeer())) { groups = "Failing"; @@ -114,66 +128,79 @@ class ProfilePersistenceHelper { } StringBuilder buf = new StringBuilder(512); - buf.append("########################################################################").append(NL); - buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL); - if (_us != null) - buf.append("# as calculated by ").append(_us.toBase64()).append(NL); - buf.append("#").append(NL); - buf.append("# Speed: ").append(profile.getSpeedValue()).append(NL); - buf.append("# Capacity: ").append(profile.getCapacityValue()).append(NL); - buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL); - buf.append("# Groups: ").append(groups).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"); - add(buf, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score"); - add(buf, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score"); - addDate(buf, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?"); - addDate(buf, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?"); - addDate(buf, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?"); - addDate(buf, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?"); - addDate(buf, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?"); - add(buf, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies"); - add(buf, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec"); - add(buf, "tunnelPeakTunnelThroughput", profile.getPeakTunnelThroughputKBps(), "KBytes/sec"); - add(buf, "tunnelPeakTunnel1mThroughput", profile.getPeakTunnel1mThroughputKBps(), "KBytes/sec"); - buf.append(NL); + if (addComments) { + buf.append("########################################################################").append(NL); + buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL); + if (_us != null) + buf.append("# as calculated by ").append(_us.toBase64()).append(NL); + buf.append("#").append(NL); + buf.append("# Speed: ").append(profile.getSpeedValue()).append(NL); + buf.append("# Capacity: ").append(profile.getCapacityValue()).append(NL); + buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL); + buf.append("# Groups: ").append(groups).append(NL); + buf.append("#").append(NL); + buf.append("########################################################################").append(NL); + buf.append("##").append(NL); + } + add(buf, addComments, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score"); + add(buf, addComments, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score"); + add(buf, addComments, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score"); + addDate(buf, addComments, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?"); + addDate(buf, addComments, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?"); + addDate(buf, addComments, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?"); + addDate(buf, addComments, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?"); + addDate(buf, addComments, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?"); + add(buf, addComments, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies"); + add(buf, addComments, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec"); + 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")); if (profile.getIsExpanded()) { // 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.getSendSuccessSize().store(out, "sendSuccessSize"); - profile.getTunnelCreateResponseTime().store(out, "tunnelCreateResponseTime"); - profile.getTunnelTestResponseTime().store(out, "tunnelTestResponseTime"); + profile.getTunnelCreateResponseTime().store(out, "tunnelCreateResponseTime", addComments); + profile.getTunnelTestResponseTime().store(out, "tunnelTestResponseTime", addComments); } if (profile.getIsExpandedDB()) { - profile.getDBHistory().store(out); - profile.getDbIntroduction().store(out, "dbIntroduction"); - profile.getDbResponseTime().store(out, "dbResponseTime"); + profile.getDBHistory().store(out, addComments); + profile.getDbIntroduction().store(out, "dbIntroduction", addComments); + profile.getDbResponseTime().store(out, "dbResponseTime", addComments); } } /** @since 0.8.5 */ - private static void addDate(StringBuilder buf, String name, long val, String description) { - String when = val > 0 ? (new Date(val)).toString() : "Never"; - add(buf, name, val, description + ' ' + when); + private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) { + if (addComments) { + 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 */ - private static void add(StringBuilder buf, String name, long val, String description) { - buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL); - buf.append(name).append('=').append(val).append(NL).append(NL); + private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) { + if (addComments) + 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 */ - 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); + private static void add(StringBuilder buf, boolean addComments, String name, float val, String description) { + if (addComments) + 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 readProfiles() { diff --git a/router/java/src/net/i2p/router/peermanager/TunnelHistory.java b/router/java/src/net/i2p/router/peermanager/TunnelHistory.java index 64e21a6e88..4b5ba88d0d 100644 --- a/router/java/src/net/i2p/router/peermanager/TunnelHistory.java +++ b/router/java/src/net/i2p/router/peermanager/TunnelHistory.java @@ -137,33 +137,51 @@ public class TunnelHistory { private final static String NL = System.getProperty("line.separator"); 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); - buf.append(NL); - buf.append("#################").append(NL); - buf.append("# Tunnel history").append(NL); - buf.append("###").append(NL); - addDate(buf, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?"); - 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, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?"); - addDate(buf, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?"); - addDate(buf, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?"); - add(buf, "lifetimeAgreedTo", _lifetimeAgreedTo.get(), "How many tunnels has the peer ever agreed to participate in?"); - add(buf, "lifetimeFailed", _lifetimeFailed.get(), "How many tunnels has the peer ever agreed to participate in that failed prematurely?"); - add(buf, "lifetimeRejected", _lifetimeRejected.get(), "How many tunnels has the peer ever refused to participate in?"); + if (addComments) { + buf.append(NL); + buf.append("#################").append(NL); + buf.append("# Tunnel history").append(NL); + buf.append("###").append(NL); + } + addDate(buf, addComments, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?"); + addDate(buf, addComments, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed?"); + addDate(buf, addComments, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel (Critical response code)?"); + addDate(buf, addComments, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?"); + addDate(buf, addComments, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?"); + addDate(buf, addComments, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?"); + 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")); - _rejectRate.store(out, "tunnelHistory.rejectRate"); - _failRate.store(out, "tunnelHistory.failRate"); + _rejectRate.store(out, "tunnelHistory.rejectRate", addComments); + _failRate.store(out, "tunnelHistory.failRate", addComments); } - private static void addDate(StringBuilder buf, String name, long val, String description) { - String when = val > 0 ? (new Date(val)).toString() : "Never"; - add(buf, name, val, description + ' ' + when); + private static void addDate(StringBuilder buf, boolean addComments, String name, long val, String description) { + if (addComments) { + 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) { - buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL); - buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL); + private static void add(StringBuilder buf, boolean addComments, String name, long val, String description) { + if (addComments) + 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) {