forked from I2P_Developers/i2p.i2p
Profiles: Omit comments from stored profiles
This commit is contained in:
@ -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) {
|
||||
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).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) {
|
||||
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, prefix, name, description + ' ' + when, value);
|
||||
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) {
|
||||
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, prefix, name, description + ' ' + when, 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) {
|
||||
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).append(NL);
|
||||
}
|
||||
buf.append(prefix).append(name).append('=').append(value).append(NL);
|
||||
if (addComments)
|
||||
buf.append(NL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -177,8 +177,20 @@ 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);
|
||||
if (addComments) {
|
||||
buf.append(NL);
|
||||
buf.append("################################################################################").append(NL);
|
||||
buf.append("# Rate: ").append(_groupName).append(": ").append(_statName).append(NL);
|
||||
@ -186,13 +198,16 @@ public class RateStat {
|
||||
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);
|
||||
}
|
||||
|
19
history.txt
19
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
|
||||
|
@ -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 = "";
|
||||
|
@ -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);
|
||||
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) {
|
||||
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).append(NL);
|
||||
buf.append("dbHistory.").append(name).append('=').append(val).append(NL);
|
||||
if (addComments)
|
||||
buf.append(NL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,6 +128,7 @@ class ProfilePersistenceHelper {
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder(512);
|
||||
if (addComments) {
|
||||
buf.append("########################################################################").append(NL);
|
||||
buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL);
|
||||
if (_us != null)
|
||||
@ -126,54 +141,66 @@ class ProfilePersistenceHelper {
|
||||
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");
|
||||
}
|
||||
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) {
|
||||
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, name, val, description + ' ' + when);
|
||||
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) {
|
||||
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).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) {
|
||||
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).append(NL);
|
||||
buf.append(name).append('=').append(val).append(NL);
|
||||
if (addComments)
|
||||
buf.append(NL);
|
||||
}
|
||||
|
||||
public Set<PeerProfile> readProfiles() {
|
||||
|
@ -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);
|
||||
if (addComments) {
|
||||
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?");
|
||||
}
|
||||
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) {
|
||||
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, name, val, description + ' ' + when);
|
||||
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) {
|
||||
if (addComments)
|
||||
buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
|
||||
buf.append("tunnels.").append(name).append('=').append(val).append(NL).append(NL);
|
||||
buf.append("tunnels.").append(name).append('=').append(val).append(NL);
|
||||
if (addComments)
|
||||
buf.append(NL);
|
||||
}
|
||||
|
||||
public void load(Properties props) {
|
||||
|
Reference in New Issue
Block a user