* Profiles:

- Nicer profile dump
      - More efficient profile lookup for display
      - Fix dumpprofile NPE
      - Change file suffix from .dat to .txt.gz
This commit is contained in:
zzz
2011-03-19 17:19:54 +00:00
parent 34d951aa6b
commit 14986fbfa1
9 changed files with 219 additions and 93 deletions

View File

@ -171,8 +171,10 @@ class ProfileOrganizerRenderer {
buf.append(' ').append(fails).append('/').append(total).append(' ').append(_("Test Fails")); buf.append(' ').append(fails).append('/').append(total).append(' ').append(_("Test Fails"));
} }
buf.append("&nbsp;</td>"); buf.append("&nbsp;</td>");
buf.append("<td nowrap align=\"center\"><a target=\"_blank\" href=\"dumpprofile.jsp?peer=") //buf.append("<td nowrap align=\"center\"><a target=\"_blank\" href=\"dumpprofile.jsp?peer=")
.append(peer.toBase64().substring(0,6)).append("\">").append(_("profile")).append("</a>"); // .append(peer.toBase64().substring(0,6)).append("\">").append(_("profile")).append("</a>");
buf.append("<td nowrap align=\"center\"><a href=\"viewprofile?peer=")
.append(peer.toBase64()).append("\">").append(_("profile")).append("</a>");
buf.append("&nbsp;<a href=\"configpeer?peer=").append(peer.toBase64()).append("\">+-</a></td>\n"); buf.append("&nbsp;<a href=\"configpeer?peer=").append(peer.toBase64()).append("\">+-</a></td>\n");
buf.append("</tr>"); buf.append("</tr>");
// let's not build the whole page in memory (~500 bytes per peer) // let's not build the whole page in memory (~500 bytes per peer)

View File

@ -1,37 +1,73 @@
package net.i2p.router.web; package net.i2p.router.web;
import java.util.Iterator; import java.io.IOException;
import java.util.Set; import java.util.Set;
import net.i2p.data.DataFormatException;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.router.RouterContext;
/** /**
* uuuugly. dump the peer profile data if given a peer. * Dump the peer profile data if given a full B64 peer string or prefix.
* *
*/ */
public class StatHelper extends HelperBase { public class StatHelper extends HelperBase {
private String _peer; private String _peer;
/**
* Caller should strip HTML (XSS)
*/
public void setPeer(String peer) { _peer = peer; } public void setPeer(String peer) { _peer = peer; }
/**
* Look up based on a b64 prefix or full b64.
* Prefix is inefficient.
*/
public String getProfile() { public String getProfile() {
RouterContext ctx = (RouterContext)net.i2p.router.RouterContext.listContexts().get(0); if (_peer == null || _peer.length() <= 0)
Set peers = ctx.profileOrganizer().selectAllPeers(); return "No peer specified";
for (Iterator iter = peers.iterator(); iter.hasNext(); ) { if (_peer.length() >= 44)
Hash peer = (Hash)iter.next(); return outputProfile();
Set<Hash> peers = _context.profileOrganizer().selectAllPeers();
for (Hash peer : peers) {
if (peer.toBase64().startsWith(_peer)) { if (peer.toBase64().startsWith(_peer)) {
try { return dumpProfile(peer);
WriterOutputStream wos = new WriterOutputStream(_out);
ctx.profileOrganizer().exportProfile(peer, wos);
wos.flush();
_out.flush();
return "";
} catch (Exception e) {
e.printStackTrace();
}
} }
} }
return "Unknown"; return "Unknown peer " + _peer;
}
/**
* Look up based on the full b64 - efficient
* @since 0.8.5
*/
private String outputProfile() {
Hash peer = new Hash();
try {
peer.fromBase64(_peer);
return dumpProfile(peer);
} catch (DataFormatException dfe) {
return "Bad peer hash " + _peer;
}
}
/**
* dump the profile
* @since 0.8.5
*/
private String dumpProfile(Hash peer) {
try {
WriterOutputStream wos = new WriterOutputStream(_out);
boolean success = _context.profileOrganizer().exportProfile(peer, wos);
if (success) {
wos.flush();
_out.flush();
return "";
} else {
return "Unknown peer " + _peer;
}
} catch (IOException e) {
e.printStackTrace();
return "IO Error " + e;
}
} }
} }

View File

@ -1,5 +1,6 @@
<%@page contentType="text/plain" <%@page contentType="text/plain"
%><jsp:useBean id="helper" class="net.i2p.router.web.StatHelper" %><jsp:useBean id="helper" class="net.i2p.router.web.StatHelper"
/><jsp:setProperty name="helper" property="peer" value="<%=request.getParameter("peer")%>" /><jsp:setProperty name="helper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>"
/><jsp:setProperty name="helper" property="peer" value="<%=net.i2p.data.DataHelper.stripHTML(request.getParameter("peer"))%>"
/><% helper.storeWriter(out); /><% helper.storeWriter(out);
%><jsp:getProperty name="helper" property="profile" /> %><jsp:getProperty name="helper" property="profile" />

View File

@ -0,0 +1,30 @@
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<%@include file="css.jsi" %>
<%=intl.title("Peer Profile")%>
</head><body>
<%@include file="summary.jsi" %>
<h1><%=intl._("Peer Profile")%></h1>
<div class="main" id="main"><div class="wideload">
<%
String peerB64 = request.getParameter("peer");
if (peerB64 == null || peerB64.length() <= 0) {
out.print("No peer specified");
} else {
peerB64 = net.i2p.data.DataHelper.stripHTML(peerB64); // XSS
%>
<jsp:useBean id="stathelper" class="net.i2p.router.web.StatHelper" />
<jsp:setProperty name="stathelper" property="contextId" value="<%=(String)session.getAttribute("i2p.contextId")%>" />
<jsp:setProperty name="stathelper" property="peer" value="<%=peerB64%>" />
<% stathelper.storeWriter(out); %>
<h2><%=intl._("Profile for peer {0}", peerB64)%></h2>
<pre>
<jsp:getProperty name="stathelper" property="profile" />
</pre>
<%
}
%>
</div></div></body></html>

View File

@ -1,10 +1,16 @@
package net.i2p.stat; package net.i2p.stat;
import java.util.Date;
import java.util.Properties; import java.util.Properties;
import net.i2p.data.DataHelper;
import net.i2p.util.Log; import net.i2p.util.Log;
/** object orientation gives you hairy palms. */ /**
* Output rate data.
* This is used via ProfilePersistenceHelper and the output
* must be compatible.
*/
class PersistenceHelper { class PersistenceHelper {
private final static Log _log = new Log(PersistenceHelper.class); private final static Log _log = new Log(PersistenceHelper.class);
private final static String NL = System.getProperty("line.separator"); private final static String NL = System.getProperty("line.separator");
@ -15,6 +21,18 @@ class PersistenceHelper {
buf.append(prefix).append(name).append('=').append(value).append(NL).append(NL); buf.append(prefix).append(name).append('=').append(value).append(NL).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);
}
/** @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 add(StringBuilder buf, String prefix, String name, String description, long value) { 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(prefix).append(name).append(NL);
buf.append("# ").append(description).append(NL); buf.append("# ").append(description).append(NL);
@ -48,4 +66,4 @@ class PersistenceHelper {
} }
return 0; return 0;
} }
} }

View File

@ -400,42 +400,41 @@ public class Rate {
} }
public void store(String prefix, StringBuilder buf) throws IOException { public void store(String prefix, StringBuilder buf) throws IOException {
PersistenceHelper.add(buf, prefix, ".period", "Number of milliseconds in the period", _period); PersistenceHelper.addTime(buf, prefix, ".period", "Length of the period:", _period);
PersistenceHelper.add(buf, prefix, ".creationDate", PersistenceHelper.addDate(buf, prefix, ".creationDate",
"When was this rate created? (milliseconds since the epoch, GMT)", _creationDate); "When was this rate created?", _creationDate);
PersistenceHelper.add(buf, prefix, ".lastCoalesceDate", PersistenceHelper.addDate(buf, prefix, ".lastCoalesceDate",
"When did we last coalesce this rate? (milliseconds since the epoch, GMT)", "When did we last coalesce this rate?",
_lastCoalesceDate); _lastCoalesceDate);
PersistenceHelper.add(buf, prefix, ".currentDate", PersistenceHelper.addDate(buf, prefix, ".currentDate",
"When did this data get written? (milliseconds since the epoch, GMT)", now()); "When was this data written?", now());
PersistenceHelper.add(buf, prefix, ".currentTotalValue", PersistenceHelper.add(buf, 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 PersistenceHelper.add(buf, prefix, ".currentEventCount",
.add(buf, 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.add(buf, prefix, ".currentTotalEventTime", PersistenceHelper.addTime(buf, prefix, ".currentTotalEventTime",
"How many milliseconds 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, 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, 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.add(buf, prefix, ".lastTotalEventTime", PersistenceHelper.addTime(buf, prefix, ".lastTotalEventTime",
"How many milliseconds 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, 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, 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.add(buf, prefix, ".extremeTotalEventTime", PersistenceHelper.addTime(buf, prefix, ".extremeTotalEventTime",
"How many milliseconds 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, 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, 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.add(buf, prefix, ".lifetimeTotalEventTime", PersistenceHelper.addTime(buf, prefix, ".lifetimeTotalEventTime",
"How many milliseconds have the events since this stat was created consumed?", "How much total time was consumed by the events since this stat was created?",
_lifetimeTotalEventTime); _lifetimeTotalEventTime);
} }

View File

@ -256,10 +256,15 @@ public class ProfileOrganizer {
return false; return false;
} }
public void exportProfile(Hash profile, OutputStream out) throws IOException { /**
* @return true if successful, false if not found
*/
public boolean exportProfile(Hash profile, OutputStream out) throws IOException {
PeerProfile prof = getProfile(profile); PeerProfile prof = getProfile(profile);
if (prof != null) boolean rv = prof != null;
if (rv)
_persistenceHelper.writeProfile(prof, out); _persistenceHelper.writeProfile(prof, out);
return rv;
} }
/** /**

View File

@ -8,6 +8,7 @@ import java.io.FilenameFilter;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
@ -24,13 +25,24 @@ import net.i2p.util.Log;
import net.i2p.util.SecureDirectory; import net.i2p.util.SecureDirectory;
import net.i2p.util.SecureFileOutputStream; import net.i2p.util.SecureFileOutputStream;
/**
* Write profiles to disk at shutdown,
* read at startup.
* The files are gzip compressed, however we unfortunately store them
* with a ".dat" extension instead of ".txt.gz", so it isn't apparent.
* TODO: Migrate to new extension.
*/
class ProfilePersistenceHelper { class ProfilePersistenceHelper {
private Log _log; private final Log _log;
private RouterContext _context; private final RouterContext _context;
public final static String PROP_PEER_PROFILE_DIR = "router.profileDir"; public final static String PROP_PEER_PROFILE_DIR = "router.profileDir";
public final static String DEFAULT_PEER_PROFILE_DIR = "peerProfiles"; public final static String DEFAULT_PEER_PROFILE_DIR = "peerProfiles";
private final static String NL = System.getProperty("line.separator"); private final static String NL = System.getProperty("line.separator");
private static final String PREFIX = "profile-";
private static final String SUFFIX = ".txt.gz";
private static final String UNCOMPRESSED_SUFFIX = ".txt";
private static final String OLD_SUFFIX = ".dat";
/** /**
* If we haven't been able to get a message through to the peer in 3 days, * If we haven't been able to get a message through to the peer in 3 days,
@ -76,58 +88,49 @@ class ProfilePersistenceHelper {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_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 */
public void writeProfile(PeerProfile profile, OutputStream out) throws IOException { public void writeProfile(PeerProfile profile, OutputStream out) throws IOException {
String groups = null; String groups = null;
if (_context.profileOrganizer().isFailing(profile.getPeer())) { if (_context.profileOrganizer().isFailing(profile.getPeer())) {
groups = "failing"; groups = "Failing";
} else if (!_context.profileOrganizer().isHighCapacity(profile.getPeer())) { } else if (!_context.profileOrganizer().isHighCapacity(profile.getPeer())) {
groups = "not failing"; groups = "Standard";
} else { } else {
if (_context.profileOrganizer().isFast(profile.getPeer())) if (_context.profileOrganizer().isFast(profile.getPeer()))
groups = "fast and high capacity"; groups = "Fast, High Capacity";
else else
groups = "high capacity"; groups = "High Capacity";
if (_context.profileOrganizer().isWellIntegrated(profile.getPeer())) if (_context.profileOrganizer().isWellIntegrated(profile.getPeer()))
groups = groups + ", well integrated"; groups = groups + ", Integrated";
} }
StringBuilder buf = new StringBuilder(512); StringBuilder buf = new StringBuilder(512);
buf.append("########################################################################").append(NL); buf.append("########################################################################").append(NL);
buf.append("# profile for ").append(profile.getPeer().toBase64()).append(NL); buf.append("# Profile for peer ").append(profile.getPeer().toBase64()).append(NL);
if (_us != null) if (_us != null)
buf.append("# as calculated by ").append(_us.toBase64()).append(NL); buf.append("# as calculated by ").append(_us.toBase64()).append(NL);
buf.append("#").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("# speedValue: ").append(profile.getSpeedValue()).append(NL); buf.append("# Integration: ").append(profile.getIntegrationValue()).append(NL);
buf.append("#").append(NL);
buf.append("# Groups: ").append(groups).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); buf.append("##").append(NL);
buf.append("# Capacity bonus: used to affect the capacity score after all other calculations are done").append(NL); add(buf, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score");
buf.append("capacityBonus=").append(profile.getCapacityBonus()).append(NL); add(buf, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score");
buf.append("# Integration bonus: used to affect the integration score after all other calculations are done").append(NL); add(buf, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score");
buf.append("integrationBonus=").append(profile.getIntegrationBonus()).append(NL); addDate(buf, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?");
buf.append("# Speed bonus: used to affect the speed score after all other calculations are done").append(NL); addDate(buf, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first get a reference to this peer?");
buf.append("speedBonus=").append(profile.getSpeedBonus()).append(NL); addDate(buf, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?");
buf.append(NL).append(NL); addDate(buf, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to the peer?");
buf.append("# Last heard about: when did we last get a reference to this peer? (milliseconds since the epoch)").append(NL); addDate(buf, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?");
buf.append("lastHeardAbout=").append(profile.getLastHeardAbout()).append(NL); add(buf, "tunnelTestTimeAverage", profile.getTunnelTestTimeAverage(), "Moving average as to how fast the peer replies");
buf.append("# First heard about: when did we first get a reference to this peer? (milliseconds since the epoch)").append(NL); add(buf, "tunnelPeakThroughput", profile.getPeakThroughputKBps(), "KBytes/sec");
buf.append("firstHeardAbout=").append(profile.getFirstHeardAbout()).append(NL); add(buf, "tunnelPeakTunnelThroughput", profile.getPeakTunnelThroughputKBps(), "KBytes/sec");
buf.append("# Last sent to successfully: when did we last send the peer a message successfully? (milliseconds from the epoch)").append(NL); add(buf, "tunnelPeakTunnel1mThroughput", profile.getPeakTunnel1mThroughputKBps(), "KBytes/sec");
buf.append("lastSentToSuccessfully=").append(profile.getLastSendSuccessful()).append(NL);
buf.append("# Last failed send: when did we last fail to send a message to the peer? (milliseconds from the epoch)").append(NL);
buf.append("lastFailedSend=").append(profile.getLastSendFailed()).append(NL);
buf.append("# Last heard from: when did we last get a message from the peer? (milliseconds from the epoch)").append(NL);
buf.append("lastHeardFrom=").append(profile.getLastHeardFrom()).append(NL);
buf.append("# moving average as to how fast the peer replies").append(NL);
buf.append("tunnelTestTimeAverage=").append(profile.getTunnelTestTimeAverage()).append(NL);
buf.append("tunnelPeakThroughput=").append(profile.getPeakThroughputKBps()).append(NL);
buf.append("tunnelPeakTunnelThroughput=").append(profile.getPeakTunnelThroughputKBps()).append(NL);
buf.append("tunnelPeakTunnel1mThroughput=").append(profile.getPeakTunnel1mThroughputKBps()).append(NL);
buf.append(NL); buf.append(NL);
out.write(buf.toString().getBytes()); out.write(buf.toString().getBytes());
@ -148,12 +151,29 @@ class ProfilePersistenceHelper {
} }
} }
public Set readProfiles() { /** @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);
}
/** @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);
}
/** @since 0.8.5 */
private static void add(StringBuilder buf, String name, double val, String description) {
buf.append("# ").append(name).append(NL).append("# ").append(description).append(NL);
buf.append(name).append('=').append(val).append(NL).append(NL);
}
public Set<PeerProfile> readProfiles() {
long start = _context.clock().now(); long start = _context.clock().now();
Set files = selectFiles(); Set<File> files = selectFiles();
Set profiles = new HashSet(files.size()); Set<PeerProfile> profiles = new HashSet(files.size());
for (Iterator iter = files.iterator(); iter.hasNext();) { for (File f : files) {
File f = (File)iter.next();
PeerProfile profile = readProfile(f); PeerProfile profile = readProfile(f);
if (profile != null) if (profile != null)
profiles.add(profile); profiles.add(profile);
@ -164,10 +184,11 @@ class ProfilePersistenceHelper {
return profiles; return profiles;
} }
private Set selectFiles() { private Set<File> selectFiles() {
File files[] = getProfileDir().listFiles(new FilenameFilter() { File files[] = getProfileDir().listFiles(new FilenameFilter() {
public boolean accept(File dir, String filename) { public boolean accept(File dir, String filename) {
return (filename.startsWith("profile-") && filename.endsWith(".dat")); return (filename.startsWith(PREFIX) &&
(filename.endsWith(SUFFIX) || filename.endsWith(OLD_SUFFIX) || filename.endsWith(UNCOMPRESSED_SUFFIX)));
} }
}); });
Set rv = new HashSet(files.length); Set rv = new HashSet(files.length);
@ -200,6 +221,14 @@ class ProfilePersistenceHelper {
", since we haven't heard from them in a long time"); ", since we haven't heard from them in a long time");
file.delete(); file.delete();
return null; return null;
} else if (file.getName().endsWith(OLD_SUFFIX)) {
// migrate to new file name, ignore failure
String newName = file.getAbsolutePath();
newName = newName.substring(0, newName.length() - OLD_SUFFIX.length()) + SUFFIX;
boolean success = file.renameTo(new File(newName));
if (!success)
// new file exists and on Windows?
file.delete();
} }
profile.setCapacityBonus(getLong(props, "capacityBonus")); profile.setCapacityBonus(getLong(props, "capacityBonus"));
@ -300,8 +329,8 @@ class ProfilePersistenceHelper {
} }
private Hash getHash(String name) { private Hash getHash(String name) {
String key = name.substring("profile-".length()); String key = name.substring(PREFIX.length());
key = key.substring(0, key.length() - ".dat".length()); key = key.substring(0, 44);
//Hash h = new Hash(); //Hash h = new Hash();
try { try {
//h.fromBase64(key); //h.fromBase64(key);
@ -317,7 +346,7 @@ class ProfilePersistenceHelper {
} }
private File pickFile(PeerProfile profile) { private File pickFile(PeerProfile profile) {
return new File(getProfileDir(), "profile-" + profile.getPeer().toBase64() + ".dat"); return new File(getProfileDir(), PREFIX + profile.getPeer().toBase64() + SUFFIX);
} }
private File getProfileDir() { private File getProfileDir() {
@ -339,7 +368,7 @@ class ProfilePersistenceHelper {
rnd.nextBytes(data); rnd.nextBytes(data);
Hash peer = new Hash(data); Hash peer = new Hash(data);
try { try {
File f = new File(dir, "profile-" + peer.toBase64() + ".dat"); File f = new File(dir, PREFIX + peer.toBase64() + SUFFIX);
f.createNewFile(); f.createNewFile();
System.out.println("Created " + peer.toBase64()); System.out.println("Created " + peer.toBase64());
} catch (IOException ioe) {} } catch (IOException ioe) {}

View File

@ -2,6 +2,7 @@ package net.i2p.router.peermanager;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date;
import java.util.Properties; import java.util.Properties;
import net.i2p.router.RouterContext; import net.i2p.router.RouterContext;
@ -138,12 +139,12 @@ public class TunnelHistory {
buf.append("#################").append(NL); buf.append("#################").append(NL);
buf.append("# Tunnel history").append(NL); buf.append("# Tunnel history").append(NL);
buf.append("###").append(NL); buf.append("###").append(NL);
add(buf, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel? (milliseconds since the epoch)"); addDate(buf, "lastAgreedTo", _lastAgreedTo, "When did the peer last agree to participate in a tunnel?");
add(buf, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed? (milliseconds since the epoch)"); addDate(buf, "lastFailed", _lastFailed, "When was the last time a tunnel that the peer agreed to participate failed?");
add(buf, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel? (milliseconds since the epoch)"); addDate(buf, "lastRejectedCritical", _lastRejectedCritical, "When was the last time the peer refused to participate in a tunnel (Critical response code)?");
add(buf, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel? (milliseconds since the epoch)"); addDate(buf, "lastRejectedBandwidth", _lastRejectedBandwidth, "When was the last time the peer refused to participate in a tunnel (Bandwidth response code)?");
add(buf, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel? (milliseconds since the epoch)"); addDate(buf, "lastRejectedTransient", _lastRejectedTransient, "When was the last time the peer refused to participate in a tunnel (Transient load response code)?");
add(buf, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel? (milliseconds since the epoch)"); addDate(buf, "lastRejectedProbabalistic", _lastRejectedProbabalistic, "When was the last time the peer refused to participate in a tunnel (Probabalistic response code)?");
add(buf, "lifetimeAgreedTo", _lifetimeAgreedTo, "How many tunnels has the peer ever agreed to participate in?"); add(buf, "lifetimeAgreedTo", _lifetimeAgreedTo, "How many tunnels has the peer ever agreed to participate in?");
add(buf, "lifetimeFailed", _lifetimeFailed, "How many tunnels has the peer ever agreed to participate in that failed prematurely?"); add(buf, "lifetimeFailed", _lifetimeFailed, "How many tunnels has the peer ever agreed to participate in that failed prematurely?");
add(buf, "lifetimeRejected", _lifetimeRejected, "How many tunnels has the peer ever refused to participate in?"); add(buf, "lifetimeRejected", _lifetimeRejected, "How many tunnels has the peer ever refused to participate in?");
@ -152,8 +153,13 @@ public class TunnelHistory {
_failRate.store(out, "tunnelHistory.failRate"); _failRate.store(out, "tunnelHistory.failRate");
} }
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 add(StringBuilder buf, String name, long val, String description) { private static void add(StringBuilder buf, String name, long val, String description) {
buf.append("# ").append(name.toUpperCase()).append(NL).append("# ").append(description).append(NL); 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).append(NL);
} }