propagate from branch 'i2p.i2p' (head 60c5cb17c0406b6e6e547489f9ea8ef3c290e262)

to branch 'i2p.i2p.zzz.jrobin159' (head 330a4f9652fe5f67e6e9998f5c0a87c7ef163764)
This commit is contained in:
zzz
2011-03-21 14:29:03 +00:00
42 changed files with 355 additions and 124 deletions

View File

@ -79,7 +79,7 @@
<manifest> <manifest>
<attribute name="Build-Date" value="${build.timestamp}" /> <attribute name="Build-Date" value="${build.timestamp}" />
<attribute name="Base-Revision" value="${workspace.version}" /> <attribute name="Base-Revision" value="${workspace.version}" />
<attribute name="Workspace-Changes" value="${workspace.changes}" /> <attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
</manifest> </manifest>
</war> </war>
</target> </target>

View File

@ -426,6 +426,10 @@ public class PeerCoordinator implements PeerListener
_log.info("New connection to peer: " + peer + " for " + name); _log.info("New connection to peer: " + peer + " for " + name);
} }
// We may have gotten the metainfo after the peer was created.
if (metainfo != null)
peer.setMetaInfo(metainfo);
// Add it to the beginning of the list. // Add it to the beginning of the list.
// And try to optimistically make it a uploader. // And try to optimistically make it a uploader.
// Can't add to beginning since we converted from a List to a Queue // Can't add to beginning since we converted from a List to a Queue

View File

@ -496,10 +496,14 @@ class PeerState implements DataLoader
} }
/** /**
* Switch from magnet mode to normal mode * Switch from magnet mode to normal mode.
* If we already have the metainfo, this does nothing.
* @param meta non-null
* @since 0.8.4 * @since 0.8.4
*/ */
public void setMetaInfo(MetaInfo meta) { public void setMetaInfo(MetaInfo meta) {
if (metainfo != null)
return;
BitField oldBF = bitfield; BitField oldBF = bitfield;
if (oldBF != null) { if (oldBF != null) {
if (oldBF.size() != meta.getPieces()) if (oldBF.size() != meta.getPieces())
@ -511,7 +515,7 @@ class PeerState implements DataLoader
//bitfield = new BitField(meta.getPieces()); //bitfield = new BitField(meta.getPieces());
} }
metainfo = meta; metainfo = meta;
if (bitfield.count() > 0) if (bitfield != null && bitfield.count() > 0)
setInteresting(true); setInteresting(true);
} }

View File

@ -351,7 +351,8 @@ public class I2PSnarkServlet extends Default {
// Using a unique name fixes Opera, except for the buttons with js confirms, see below // Using a unique name fixes Opera, except for the buttons with js confirms, see below
String ua = req.getHeader("User-Agent"); String ua = req.getHeader("User-Agent");
boolean isDegraded = ua != null && (ua.startsWith("Lynx") || ua.startsWith("w3m") || boolean isDegraded = ua != null && (ua.startsWith("Lynx") || ua.startsWith("w3m") ||
ua.startsWith("ELinks") || ua.startsWith("Dillo")); ua.startsWith("ELinks") || ua.startsWith("Links") ||
ua.startsWith("Dillo"));
boolean noThinsp = isDegraded || (ua != null && ua.startsWith("Opera")); boolean noThinsp = isDegraded || (ua != null && ua.startsWith("Opera"));
if (_manager.util().connected()) { if (_manager.util().connected()) {

View File

@ -1,13 +1,17 @@
<%@page pageEncoding="UTF-8"%> <%
<%@page contentType="text/html" import="net.i2p.i2ptunnel.web.EditBean" %><% // NOTE: Do the header carefully so there is no whitespace before the <?xml... line
%><%@page pageEncoding="UTF-8"
%><%@page contentType="text/html" import="net.i2p.i2ptunnel.web.EditBean"
%><%
String tun = request.getParameter("tunnel"); String tun = request.getParameter("tunnel");
if (tun != null) { if (tun != null) {
try { try {
int curTunnel = Integer.parseInt(tun); int curTunnel = Integer.parseInt(tun);
if (EditBean.staticIsClient(curTunnel)) { if (EditBean.staticIsClient(curTunnel)) {
%><jsp:include page="editClient.jsp" /><% %><jsp:include page="editClient.jsp" /><%
} else { } else {
%><jsp:include page="editServer.jsp" /><% %><jsp:include page="editServer.jsp" /><%
} }
} catch (NumberFormatException nfe) { } catch (NumberFormatException nfe) {
%>Invalid tunnel parameter<% %>Invalid tunnel parameter<%
@ -16,9 +20,9 @@ String tun = request.getParameter("tunnel");
String type = request.getParameter("type"); String type = request.getParameter("type");
int curTunnel = -1; int curTunnel = -1;
if (EditBean.isClient(type)) { if (EditBean.isClient(type)) {
%><jsp:include page="editClient.jsp" /><% %><jsp:include page="editClient.jsp" /><%
} else { } else {
%><jsp:include page="editServer.jsp" /><% %><jsp:include page="editServer.jsp" /><%
} }
} }
%> %>

View File

@ -188,7 +188,7 @@
</label> </label>
<textarea rows="1" style="height: 3em;" cols="60" readonly="readonly" id="localDestination" title="Read Only: Local Destination (if known)" wrap="off" spellcheck="false"><%=editBean.getDestinationBase64(curTunnel)%></textarea> <textarea rows="1" style="height: 3em;" cols="60" readonly="readonly" id="localDestination" title="Read Only: Local Destination (if known)" wrap="off" spellcheck="false"><%=editBean.getDestinationBase64(curTunnel)%></textarea>
<% if (!"".equals(editBean.getDestinationBase64(curTunnel))) { %> <% if (!"".equals(editBean.getDestinationBase64(curTunnel))) { %>
<a href="/susidns/addressbook.jsp?book=private&hostname=<%=editBean.getTunnelName(curTunnel)%>&destination=<%=editBean.getDestinationBase64(curTunnel)%>#add"><%=intl._("Add to local addressbook")%></a> <a href="/susidns/addressbook.jsp?book=private&amp;hostname=<%=editBean.getTunnelName(curTunnel)%>&amp;destination=<%=editBean.getDestinationBase64(curTunnel)%>#add"><%=intl._("Add to local addressbook")%></a>
<% } %> <% } %>
</div> </div>
@ -340,7 +340,7 @@
<label for="force" accesskey="c"> <label for="force" accesskey="c">
<%=intl._("Generate New Key")%>: <%=intl._("Generate New Key")%>:
</label> </label>
<button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Generate" title="Generate New Key Now"><%=intl._("Generate")%></button> <button accesskey="S" class="control" type="submit" name="action" value="Generate" title="Generate New Key Now"><%=intl._("Generate")%></button>
<span class="comment"><%=intl._("(Tunnel must be stopped first)")%></span> <span class="comment"><%=intl._("(Tunnel must be stopped first)")%></span>
</div> </div>
@ -374,7 +374,7 @@
<div class="rowItem"> <div class="rowItem">
<div id="optionsField" class="rowItem"> <div id="optionsField" class="rowItem">
<label><%=intl._("Inbound connection limits (0=unlimited)")%><br><%=intl._("Per client")%>:</label> <label><%=intl._("Inbound connection limits (0=unlimited)")%><br /><%=intl._("Per client")%>:</label>
</div> </div>
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label><%=intl._("Per minute")%>:</label> <label><%=intl._("Per minute")%>:</label>
@ -453,7 +453,6 @@
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label><%=intl._("None")%></label> <label><%=intl._("None")%></label>
<input value="0" type="radio" id="startOnLoad" name="cert" title="No Certificate"<%=(editBean.getCert(curTunnel)==0 ? " checked=\"checked\"" : "")%> class="tickbox" /> <input value="0" type="radio" id="startOnLoad" name="cert" title="No Certificate"<%=(editBean.getCert(curTunnel)==0 ? " checked=\"checked\"" : "")%> class="tickbox" />
<span class="comment"></span>
</div> </div>
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label><%=intl._("Hashcash (effort)")%></label> <label><%=intl._("Hashcash (effort)")%></label>
@ -465,13 +464,12 @@
<label for="force" accesskey="c"> <label for="force" accesskey="c">
<%=intl._("Hashcash Calc Time")%>: <%=intl._("Hashcash Calc Time")%>:
</label> </label>
<button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Estimate" title="Estimate Calculation Time"><%=intl._("Estimate")%></button> <button accesskey="S" class="control" type="submit" name="action" value="Estimate" title="Estimate Calculation Time"><%=intl._("Estimate")%></button>
</div> </div>
<div id="hostField" class="rowItem"> <div id="hostField" class="rowItem">
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label><%=intl._("Hidden")%></label> <label><%=intl._("Hidden")%></label>
<input value="2" type="radio" id="startOnLoad" name="cert" title="Hidden Certificate"<%=(editBean.getCert(curTunnel)==2 ? " checked=\"checked\"" : "")%> class="tickbox" /> <input value="2" type="radio" id="startOnLoad" name="cert" title="Hidden Certificate"<%=(editBean.getCert(curTunnel)==2 ? " checked=\"checked\"" : "")%> class="tickbox" />
<span class="comment"></span>
</div> </div>
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label for="signer" accesskey="c"> <label for="signer" accesskey="c">
@ -479,14 +477,13 @@
</label> </label>
<input value="3" type="radio" id="startOnLoad" name="cert" title="Signed Certificate"<%=(editBean.getCert(curTunnel)==3 ? " checked=\"checked\"" : "")%> class="tickbox" /> <input value="3" type="radio" id="startOnLoad" name="cert" title="Signed Certificate"<%=(editBean.getCert(curTunnel)==3 ? " checked=\"checked\"" : "")%> class="tickbox" />
<input type="text" id="port" name="signer" size="50" title="Cert Signer" value="<%=editBean.getSigner(curTunnel)%>" class="freetext" /> <input type="text" id="port" name="signer" size="50" title="Cert Signer" value="<%=editBean.getSigner(curTunnel)%>" class="freetext" />
<span class="comment"></span>
</div> </div>
</div> </div>
<div id="portField" class="rowItem"> <div id="portField" class="rowItem">
<label for="force" accesskey="c"> <label for="force" accesskey="c">
<%=intl._("Modify Certificate")%>: <%=intl._("Modify Certificate")%>:
</label> </label>
<button id="controlSave" accesskey="S" class="control" type="submit" name="action" value="Modify" title="Force New Cert Now"><%=intl._("Modify")%></button> <button accesskey="S" class="control" type="submit" name="action" value="Modify" title="Force New Cert Now"><%=intl._("Modify")%></button>
<span class="comment"><%=intl._("(Tunnel must be stopped first)")%></span> <span class="comment"><%=intl._("(Tunnel must be stopped first)")%></span>
</div> </div>

View File

@ -1,10 +1,13 @@
<% <%
// NOTE: Do the header carefully so there is no whitespace before the <?xml... line
// http://www.crazysquirrel.com/computing/general/form-encoding.jspx // http://www.crazysquirrel.com/computing/general/form-encoding.jspx
if (request.getCharacterEncoding() == null) if (request.getCharacterEncoding() == null)
request.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
%>
<%@page pageEncoding="UTF-8"%> %><%@page pageEncoding="UTF-8"
<%@page contentType="text/html" import="net.i2p.i2ptunnel.web.IndexBean"%><?xml version="1.0" encoding="UTF-8"?> %><%@page contentType="text/html" import="net.i2p.i2ptunnel.web.IndexBean"
%><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<jsp:useBean class="net.i2p.i2ptunnel.web.IndexBean" id="indexBean" scope="request" /> <jsp:useBean class="net.i2p.i2ptunnel.web.IndexBean" id="indexBean" scope="request" />
<jsp:setProperty name="indexBean" property="*" /> <jsp:setProperty name="indexBean" property="*" />

View File

@ -70,6 +70,7 @@ public class CSSHelper extends HelperBase {
*/ */
public boolean allowIFrame(String ua) { public boolean allowIFrame(String ua) {
return ua == null || !(ua.startsWith("Lynx") || ua.startsWith("w3m") || return ua == null || !(ua.startsWith("Lynx") || ua.startsWith("w3m") ||
ua.startsWith("ELinks") || ua.startsWith("Dillo")); ua.startsWith("ELinks") || ua.startsWith("Links") ||
ua.startsWith("Dillo"));
} }
} }

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

@ -10,9 +10,12 @@
if (request.getCharacterEncoding() == null) if (request.getCharacterEncoding() == null)
request.setCharacterEncoding("UTF-8"); request.setCharacterEncoding("UTF-8");
response.setHeader("Pragma", "no-cache"); // Now that we use POST for most forms, these prevent the back button from working after a form submit
response.setHeader("Cache-Control","no-cache"); // Just let the browser do its thing
response.setDateHeader("Expires", 0); //response.setHeader("Pragma", "no-cache");
//response.setHeader("Cache-Control","no-cache");
//response.setDateHeader("Expires", 0);
// the above will b0rk if the servlet engine has already flushed // the above will b0rk if the servlet engine has already flushed
// the response prior to including this file, so it should be // the response prior to including this file, so it should be
// near the top // near the top

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

@ -82,7 +82,9 @@ public class DHSessionKeyBuilder {
// add to the defaults for every 128MB of RAM, up to 512MB // add to the defaults for every 128MB of RAM, up to 512MB
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
int factor = Math.min(4, (int) (1 + (maxMemory / (128*1024*1024l)))); if (maxMemory == Long.MAX_VALUE)
maxMemory = 127*1024*1024l;
int factor = (int) Math.max(1l, Math.min(4l, 1 + (maxMemory / (128*1024*1024l))));
int defaultMin = DEFAULT_DH_PRECALC_MIN * factor; int defaultMin = DEFAULT_DH_PRECALC_MIN * factor;
int defaultMax = DEFAULT_DH_PRECALC_MAX * factor; int defaultMax = DEFAULT_DH_PRECALC_MAX * factor;
MIN_NUM_BUILDERS = ctx.getProperty(PROP_DH_PRECALC_MIN, defaultMin); MIN_NUM_BUILDERS = ctx.getProperty(PROP_DH_PRECALC_MIN, defaultMin);

View File

@ -60,7 +60,9 @@ class YKGenerator {
// add to the defaults for every 128MB of RAM, up to 1GB // add to the defaults for every 128MB of RAM, up to 1GB
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
int factor = Math.min(8, (int) (1 + (maxMemory / (128*1024*1024l)))); if (maxMemory == Long.MAX_VALUE)
maxMemory = 127*1024*1024l;
int factor = (int) Math.max(1l, Math.min(8l, 1 + (maxMemory / (128*1024*1024l))));
int defaultMin = DEFAULT_YK_PRECALC_MIN * factor; int defaultMin = DEFAULT_YK_PRECALC_MIN * factor;
int defaultMax = DEFAULT_YK_PRECALC_MAX * factor; int defaultMax = DEFAULT_YK_PRECALC_MAX * factor;
MIN_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MIN, defaultMin); MIN_NUM_BUILDERS = ctx.getProperty(PROP_YK_PRECALC_MIN, defaultMin);

View File

@ -1195,6 +1195,10 @@ public class DataHelper {
case 2: return str + "M"; case 2: return str + "M";
case 3: return str + "G"; case 3: return str + "G";
case 4: return str + "T"; case 4: return str + "T";
case 5: return str + "P";
case 6: return str + "E";
case 7: return str + "Z";
case 8: return str + "Y";
default: return bytes + ""; default: return bytes + "";
} }
} }
@ -1221,12 +1225,17 @@ public class DataHelper {
case 2: return str + "&nbsp;M"; case 2: return str + "&nbsp;M";
case 3: return str + "&nbsp;G"; case 3: return str + "&nbsp;G";
case 4: return str + "&nbsp;T"; case 4: return str + "&nbsp;T";
case 5: return str + "&nbsp;P";
case 6: return str + "&nbsp;E";
case 7: return str + "&nbsp;Z";
case 8: return str + "&nbsp;Y";
default: return bytes + "&nbsp;"; default: return bytes + "&nbsp;";
} }
} }
/** /**
* Strip out any HTML (simply removing any less than / greater than symbols) * Strip out any HTML (simply removing any less than / greater than symbols)
* @param orig may be null, returns empty string if null
*/ */
public static String stripHTML(String orig) { public static String stripHTML(String orig) {
if (orig == null) return ""; if (orig == null) return "";

View File

@ -52,7 +52,8 @@ public class RouterInfo extends DatabaseEntry {
/** should we cache the byte and string versions _byteified ? **/ /** should we cache the byte and string versions _byteified ? **/
private boolean _shouldCache; private boolean _shouldCache;
/** maybe we should check if we are floodfill? */ /** maybe we should check if we are floodfill? */
private static final boolean CACHE_ALL = Runtime.getRuntime().maxMemory() > 128*1024*1024l; private static final boolean CACHE_ALL = Runtime.getRuntime().maxMemory() > 128*1024*1024l &&
Runtime.getRuntime().maxMemory() < Long.MAX_VALUE;
public static final String PROP_NETWORK_ID = "netId"; public static final String PROP_NETWORK_ID = "netId";
public static final String PROP_CAPABILITIES = "caps"; public static final String PROP_CAPABILITIES = "caps";

View File

@ -50,6 +50,8 @@ public class SDSCache<V extends SimpleDataStructure> {
private static final double FACTOR; private static final double FACTOR;
static { static {
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
FACTOR = Math.max(MIN_FACTOR, Math.min(MAX_FACTOR, maxMemory / (128*1024*1024d))); FACTOR = Math.max(MIN_FACTOR, Math.min(MAX_FACTOR, maxMemory / (128*1024*1024d)));
} }

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

@ -69,6 +69,8 @@ public final class ByteCache {
private static final int MAX_CACHE; private static final int MAX_CACHE;
static { static {
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
MAX_CACHE = (int) Math.min(4*1024*1024l, Math.max(128*1024l, maxMemory / 128)); MAX_CACHE = (int) Math.min(4*1024*1024l, Math.max(128*1024l, maxMemory / 128));
} }

View File

@ -43,6 +43,8 @@ public class SimpleScheduler {
_log = _context.logManager().getLog(SimpleScheduler.class); _log = _context.logManager().getLog(SimpleScheduler.class);
_name = name; _name = name;
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024)))); _threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
_executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory()); _executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
_executor.prestartAllCoreThreads(); _executor.prestartAllCoreThreads();

View File

@ -44,6 +44,8 @@ public class SimpleTimer {
runner.setDaemon(true); runner.setDaemon(true);
runner.start(); runner.start();
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
int threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024)))); int threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
for (int i = 1; i <= threads ; i++) { for (int i = 1; i <= threads ; i++) {
I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents, runn)); I2PThread executor = new I2PThread(new Executor(_context, _log, _readyEvents, runn));

View File

@ -43,6 +43,8 @@ public class SimpleTimer2 {
_name = name; _name = name;
_count = 0; _count = 0;
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024)))); _threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
_executor = new CustomScheduledThreadPoolExecutor(_threads, new CustomThreadFactory()); _executor = new CustomScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
_executor.prestartAllCoreThreads(); _executor.prestartAllCoreThreads();

View File

@ -1,3 +1,16 @@
2011-03-20 zzz
* Console: Remove cache directives
* i2psnark: Fix peers stuck at uninteresting after metainfo fetch
* i2ptunnel: Change all clients to 3 hops by default (new installs only)
* Profiles:
- Nicer profile dump
- More efficient profile lookup for display
- Fix dumpprofile NPE
- Change file suffix from .dat to .txt.gz
- Set firstHeardAbout on creation
* Rate: Fix equals()
* Recognize links and links2 as text browsers
2011-03-12 zzz 2011-03-12 zzz
* Blocklist: Add bogons since they won't change any more * Blocklist: Add bogons since they won't change any more
* BuildHandler: Loop double-check * BuildHandler: Loop double-check

View File

@ -21,6 +21,10 @@ tunnel.0.option.i2cp.reduceIdleTime=900000
tunnel.0.option.i2cp.reduceOnIdle=true tunnel.0.option.i2cp.reduceOnIdle=true
tunnel.0.option.i2cp.reduceQuantity=1 tunnel.0.option.i2cp.reduceQuantity=1
tunnel.0.option.i2p.streaming.connectDelay=1000 tunnel.0.option.i2p.streaming.connectDelay=1000
tunnel.0.option.inbound.length=3
tunnel.0.option.inbound.lengthVariance=0
tunnel.0.option.outbound.length=3
tunnel.0.option.outbound.lengthVariance=0
tunnel.0.startOnLoad=true tunnel.0.startOnLoad=true
# irc # irc
@ -44,6 +48,10 @@ tunnel.1.option.i2cp.reduceOnIdle=true
tunnel.1.option.i2cp.reduceQuantity=1 tunnel.1.option.i2cp.reduceQuantity=1
tunnel.1.option.i2p.streaming.connectDelay=1000 tunnel.1.option.i2p.streaming.connectDelay=1000
tunnel.1.option.i2p.streaming.maxWindowSize=16 tunnel.1.option.i2p.streaming.maxWindowSize=16
tunnel.1.option.inbound.length=3
tunnel.1.option.inbound.lengthVariance=0
tunnel.1.option.outbound.length=3
tunnel.1.option.outbound.lengthVariance=0
tunnel.1.startOnLoad=true tunnel.1.startOnLoad=true
# I2P's mtn server # I2P's mtn server
@ -61,6 +69,10 @@ tunnel.2.option.outbound.nickname=shared clients
tunnel.2.option.i2cp.reduceIdleTime=900000 tunnel.2.option.i2cp.reduceIdleTime=900000
tunnel.2.option.i2cp.reduceOnIdle=true tunnel.2.option.i2cp.reduceOnIdle=true
tunnel.2.option.i2cp.reduceQuantity=1 tunnel.2.option.i2cp.reduceQuantity=1
tunnel.2.option.inbound.length=3
tunnel.2.option.inbound.lengthVariance=0
tunnel.2.option.outbound.length=3
tunnel.2.option.outbound.lengthVariance=0
tunnel.2.startOnLoad=false tunnel.2.startOnLoad=false
# local eepserver # local eepserver
@ -94,6 +106,10 @@ tunnel.4.option.i2cp.reduceIdleTime=900000
tunnel.4.option.i2cp.reduceOnIdle=true tunnel.4.option.i2cp.reduceOnIdle=true
tunnel.4.option.i2cp.reduceQuantity=1 tunnel.4.option.i2cp.reduceQuantity=1
tunnel.4.option.i2p.streaming.connectDelay=1000 tunnel.4.option.i2p.streaming.connectDelay=1000
tunnel.4.option.inbound.length=3
tunnel.4.option.inbound.lengthVariance=0
tunnel.4.option.outbound.length=3
tunnel.4.option.outbound.lengthVariance=0
tunnel.4.startOnLoad=true tunnel.4.startOnLoad=true
tunnel.4.targetDestination=smtp.postman.i2p tunnel.4.targetDestination=smtp.postman.i2p
tunnel.4.type=client tunnel.4.type=client
@ -112,6 +128,10 @@ tunnel.5.option.i2cp.reduceIdleTime=900000
tunnel.5.option.i2cp.reduceOnIdle=true tunnel.5.option.i2cp.reduceOnIdle=true
tunnel.5.option.i2cp.reduceQuantity=1 tunnel.5.option.i2cp.reduceQuantity=1
tunnel.5.option.i2p.streaming.connectDelay=1000 tunnel.5.option.i2p.streaming.connectDelay=1000
tunnel.5.option.inbound.length=3
tunnel.5.option.inbound.lengthVariance=0
tunnel.5.option.outbound.length=3
tunnel.5.option.outbound.lengthVariance=0
tunnel.5.startOnLoad=true tunnel.5.startOnLoad=true
tunnel.5.targetDestination=pop.postman.i2p tunnel.5.targetDestination=pop.postman.i2p
tunnel.5.type=client tunnel.5.type=client
@ -133,5 +153,9 @@ tunnel.6.option.i2cp.reduceIdleTime=900000
tunnel.6.option.i2cp.reduceOnIdle=true tunnel.6.option.i2cp.reduceOnIdle=true
tunnel.6.option.i2cp.reduceQuantity=1 tunnel.6.option.i2cp.reduceQuantity=1
tunnel.6.option.i2p.streaming.connectDelay=1000 tunnel.6.option.i2p.streaming.connectDelay=1000
tunnel.6.option.inbound.length=3
tunnel.6.option.inbound.lengthVariance=0
tunnel.6.option.outbound.length=3
tunnel.6.option.outbound.lengthVariance=0
tunnel.6.startOnLoad=true tunnel.6.startOnLoad=true

View File

@ -61,6 +61,8 @@ public class JobQueue {
private static final int RUNNERS; private static final int RUNNERS;
static { static {
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
if (maxMemory < 64*1024*1024) if (maxMemory < 64*1024*1024)
RUNNERS = 3; RUNNERS = 3;
else if (maxMemory < 256*1024*1024) else if (maxMemory < 256*1024*1024)

View File

@ -1432,7 +1432,10 @@ private static class CoalesceStatsEvent implements SimpleTimer.TimedEvent {
ctx.statManager().createRateStat("router.highCapacityPeers", "How many high capacity peers we know", "Throttle", new long[] { 5*60*1000, 60*60*1000 }); ctx.statManager().createRateStat("router.highCapacityPeers", "How many high capacity peers we know", "Throttle", new long[] { 5*60*1000, 60*60*1000 });
ctx.statManager().createRateStat("router.fastPeers", "How many fast peers we know", "Throttle", new long[] { 5*60*1000, 60*60*1000 }); ctx.statManager().createRateStat("router.fastPeers", "How many fast peers we know", "Throttle", new long[] { 5*60*1000, 60*60*1000 });
_maxMemory = Runtime.getRuntime().maxMemory(); _maxMemory = Runtime.getRuntime().maxMemory();
ctx.statManager().createRateStat("router.memoryUsed", "(Bytes) Max is " + (_maxMemory / (1024*1024)) + "MB", "Router", new long[] { 60*1000 }); String legend = "(Bytes)";
if (_maxMemory < Long.MAX_VALUE)
legend += " Max is " + DataHelper.formatSize(_maxMemory) + 'B';
ctx.statManager().createRateStat("router.memoryUsed", legend, "Router", new long[] { 60*1000 });
} }
private RouterContext getContext() { return _ctx; } private RouterContext getContext() { return _ctx; }
public void timeReached() { public void timeReached() {

View File

@ -93,6 +93,8 @@ public class RouterContext extends I2PAppContext {
// or about 2 seconds per buffer - so about 200x faster // or about 2 seconds per buffer - so about 200x faster
// to fill than to drain - so we don't need too many // to fill than to drain - so we don't need too many
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
long buffs = Math.min(16, Math.max(2, maxMemory / (14 * 1024 * 1024))); long buffs = Math.min(16, Math.max(2, maxMemory / (14 * 1024 * 1024)));
envProps.setProperty("prng.buffers", "" + buffs); envProps.setProperty("prng.buffers", "" + buffs);
} }

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 = 6; public final static long BUILD = 7;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";

View File

@ -62,6 +62,10 @@ public class PeerProfile {
public PeerProfile(RouterContext context, Hash peer) { public PeerProfile(RouterContext context, Hash peer) {
this(context, peer, true); this(context, peer, true);
} }
/**
* @param expand must be true (see below)
*/
public PeerProfile(RouterContext context, Hash peer, boolean expand) { public PeerProfile(RouterContext context, Hash peer, boolean expand) {
_context = context; _context = context;
_log = context.logManager().getLog(PeerProfile.class); _log = context.logManager().getLog(PeerProfile.class);
@ -125,7 +129,10 @@ public class PeerProfile {
} }
/** when did we first hear about this peer? */ /**
* When did we first hear about this peer?
* Currently unused, candidate for removal.
*/
public long getFirstHeardAbout() { return _firstHeardAbout; } public long getFirstHeardAbout() { return _firstHeardAbout; }
public void setFirstHeardAbout(long when) { _firstHeardAbout = when; } public void setFirstHeardAbout(long when) { _firstHeardAbout = when; }

View File

@ -341,6 +341,7 @@ public class ProfileManagerImpl implements ProfileManager {
PeerProfile prof = _context.profileOrganizer().getProfile(peer); PeerProfile prof = _context.profileOrganizer().getProfile(peer);
if (prof == null) { if (prof == null) {
prof = new PeerProfile(_context, peer); prof = new PeerProfile(_context, peer);
prof.setFirstHeardAbout(_context.clock().now());
_context.profileOrganizer().addProfile(prof); _context.profileOrganizer().addProfile(prof);
} }
return prof; return prof;

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, "speedBonus", profile.getSpeedBonus(), "Manual adjustment to the speed score");
buf.append("capacityBonus=").append(profile.getCapacityBonus()).append(NL); add(buf, "capacityBonus", profile.getCapacityBonus(), "Manual adjustment to the capacity score");
buf.append("# Integration bonus: used to affect the integration score after all other calculations are done").append(NL); add(buf, "integrationBonus", profile.getIntegrationBonus(), "Manual adjustment to the integration score");
buf.append("integrationBonus=").append(profile.getIntegrationBonus()).append(NL); addDate(buf, "firstHeardAbout", profile.getFirstHeardAbout(), "When did we first 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, "lastHeardAbout", profile.getLastHeardAbout(), "When did we last get a reference to this peer?");
buf.append("speedBonus=").append(profile.getSpeedBonus()).append(NL); addDate(buf, "lastHeardFrom", profile.getLastHeardFrom(), "When did we last get a message from the peer?");
buf.append(NL).append(NL); addDate(buf, "lastSentToSuccessfully", profile.getLastSendSuccessful(), "When did we last send the peer a message successfully?");
buf.append("# Last heard about: when did we last get a reference to this peer? (milliseconds since the epoch)").append(NL); addDate(buf, "lastFailedSend", profile.getLastSendFailed(), "When did we last fail to send a message to 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);
} }

View File

@ -34,6 +34,8 @@ class NTCPSendFinisher {
private static final int THREADS; private static final int THREADS;
static { static {
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
THREADS = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024)))); THREADS = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
} }

View File

@ -491,6 +491,8 @@ public class NTCPTransport extends TransportImpl {
_pumper.startPumping(); _pumper.startPumping();
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 128*1024*1024l;
int nr, nw; int nr, nw;
if (maxMemory < 32*1024*1024) { if (maxMemory < 32*1024*1024) {
nr = nw = 1; nr = nw = 1;

View File

@ -39,6 +39,8 @@ class MessageReceiver {
_completeMessages = new LinkedBlockingQueue(); _completeMessages = new LinkedBlockingQueue();
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
if (maxMemory < 32*1024*1024) if (maxMemory < 32*1024*1024)
_threadCount = 1; _threadCount = 1;
else if (maxMemory < 64*1024*1024) else if (maxMemory < 64*1024*1024)

View File

@ -48,6 +48,8 @@ class PacketHandler {
_introManager = introManager; _introManager = introManager;
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
int num_handlers; int num_handlers;
if (maxMemory < 32*1024*1024) if (maxMemory < 32*1024*1024)
num_handlers = 1; num_handlers = 1;

View File

@ -26,6 +26,8 @@ public class TunnelGatewayPumper implements Runnable {
_wantsPumping = new LinkedBlockingQueue(); _wantsPumping = new LinkedBlockingQueue();
_stop = false; _stop = false;
long maxMemory = Runtime.getRuntime().maxMemory(); long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory == Long.MAX_VALUE)
maxMemory = 96*1024*1024l;
_pumpers = (int) Math.max(MIN_PUMPERS, Math.min(MAX_PUMPERS, 1 + (maxMemory / (32*1024*1024)))); _pumpers = (int) Math.max(MIN_PUMPERS, Math.min(MAX_PUMPERS, 1 + (maxMemory / (32*1024*1024))));
for (int i = 0; i < _pumpers; i++) for (int i = 0; i < _pumpers; i++)
new I2PThread(this, "Tunnel GW pumper " + (i+1) + '/' + _pumpers, true).start(); new I2PThread(this, "Tunnel GW pumper " + (i+1) + '/' + _pumpers, true).start();

View File

@ -13,6 +13,7 @@ DIRS="\
apps/i2ptunnel/locale \ apps/i2ptunnel/locale \
apps/i2psnark/locale \ apps/i2psnark/locale \
apps/susidns/locale \ apps/susidns/locale \
apps/susimail/locale \
apps/desktopgui/locale" apps/desktopgui/locale"
for i in `find $DIRS -maxdepth 1 -type f -name *.po` for i in `find $DIRS -maxdepth 1 -type f -name *.po`

View File

@ -16,6 +16,7 @@ DIRS="\
apps/i2ptunnel/locale \ apps/i2ptunnel/locale \
apps/i2psnark/locale \ apps/i2psnark/locale \
apps/susidns/locale \ apps/susidns/locale \
apps/susimail/locale \
apps/desktopgui/locale \ apps/desktopgui/locale \
installer/resources/eepsite.help/help \ installer/resources/eepsite.help/help \
installer/resources/initialNews \ installer/resources/initialNews \