* Console: Some colon cleansing

* Shitlist: Move HTML renderer to router console,
      add cause parameter for ease of translation,
      tag all causes
This commit is contained in:
zzz
2009-11-11 20:28:13 +00:00
parent 573ac357d8
commit 6c00bb20b6
16 changed files with 223 additions and 78 deletions

View File

@@ -111,11 +111,13 @@ public class Blocklist {
}
for (Iterator iter = _peerBlocklist.keySet().iterator(); iter.hasNext(); ) {
Hash peer = (Hash) iter.next();
String reason = "Banned by router hash";
String reason;
String comment = (String) _peerBlocklist.get(peer);
if (comment != null)
reason = reason + ": " + comment;
_context.shitlist().shitlistRouterForever(peer, reason);
reason = _x("Banned by router hash: {0}");
else
reason = _x("Banned by router hash");
_context.shitlist().shitlistRouterForever(peer, reason, comment);
}
_peerBlocklist = null;
@@ -659,7 +661,7 @@ public class Blocklist {
*/
public void shitlist(Hash peer) {
// Temporary reason, until the job finishes
_context.shitlist().shitlistRouterForever(peer, "IP Banned");
_context.shitlist().shitlistRouterForever(peer, _x("IP banned"));
if (! "true".equals( _context.getProperty(PROP_BLOCKLIST_DETAIL, "true")))
return;
boolean shouldRunJob;
@@ -729,16 +731,17 @@ public class Blocklist {
}
if (match(ipint, toEntry(e.ip1, e.ip2))) {
try { in.close(); } catch (IOException ioe) {}
String reason = "IP ";
for (int i = 0; i < 4; i++) {
reason = reason + (ip[i] & 0xff);
if (i != 3)
reason = reason + '.';
}
reason = reason + " banned by " + BLOCKLIST_FILE_DEFAULT + " entry \"" + buf + "\"";
String reason = _x("IP banned by blocklist.txt entry {0}");
// only one translate parameter for now
//for (int i = 0; i < 4; i++) {
// reason = reason + (ip[i] & 0xff);
// if (i != 3)
// reason = reason + '.';
//}
//reason = reason + " banned by " + BLOCKLIST_FILE_DEFAULT + " entry \"" + buf + "\"";
if (_log.shouldLog(Log.WARN))
_log.warn("Shitlisting " + peer + " " + reason);
_context.shitlist().shitlistRouterForever(peer, reason);
_context.shitlist().shitlistRouterForever(peer, reason, buf.toString());
return;
}
buf.setLength(0);
@@ -791,6 +794,16 @@ public class Blocklist {
out.flush();
}
/**
* Mark a string for extraction by xgettext and translation.
* Use this only in static initializers.
* It does not translate!
* @return s
*/
private static final String _x(String s) {
return s;
}
public static void main(String args[]) {
Blocklist b = new Blocklist();
if ( (args != null) && (args.length == 1) )

View File

@@ -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 = 15;
public final static long BUILD = 16;
/** for example "-test" */
public final static String EXTRA = "";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;

View File

@@ -12,12 +12,11 @@ import java.io.IOException;
import java.io.Writer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import net.i2p.data.DataHelper;
import net.i2p.data.Hash;
@@ -36,13 +35,15 @@ public class Shitlist {
private RouterContext _context;
private Map<Hash, Entry> _entries;
private static class Entry {
public static class Entry {
/** when it should expire, per the i2p clock */
long expireOn;
public long expireOn;
/** why they were shitlisted */
String cause;
public String cause;
/** separate code so cause can contain {0} for translation */
public String causeCode;
/** what transports they were shitlisted for (String), or null for all transports */
Set<String> transports;
public Set<String> transports;
}
public final static long SHITLIST_DURATION_MS = 20*60*1000;
@@ -95,17 +96,32 @@ public class Shitlist {
return _entries.size();
}
/** for ShitlistRenderer in router console */
public Map<Hash, Entry> getEntries() {
return new HashMap<Hash, Entry>(_entries);
}
public boolean shitlistRouter(Hash peer) {
return shitlistRouter(peer, null);
}
public boolean shitlistRouter(Hash peer, String reason) { return shitlistRouter(peer, reason, null); }
/** ick have to put the reasonCode in the front to avoid ambiguity */
public boolean shitlistRouter(String reasonCode, Hash peer, String reason) {
return shitlistRouter(peer, reason, reasonCode, null, false);
}
public boolean shitlistRouter(Hash peer, String reason, String transport) {
return shitlistRouter(peer, reason, transport, false);
}
public boolean shitlistRouterForever(Hash peer, String reason) {
return shitlistRouter(peer, reason, null, true);
}
public boolean shitlistRouterForever(Hash peer, String reason, String reasonCode) {
return shitlistRouter(peer, reason, reasonCode, null, true);
}
public boolean shitlistRouter(Hash peer, String reason, String transport, boolean forever) {
return shitlistRouter(peer, reason, null, null, true);
}
private boolean shitlistRouter(Hash peer, String reason, String reasonCode, String transport, boolean forever) {
if (peer == null) {
_log.error("wtf, why did we try to shitlist null?", new Exception("shitfaced"));
return false;
@@ -137,6 +153,7 @@ public class Shitlist {
e.expireOn = _context.clock().now() + period;
}
e.cause = reason;
e.causeCode = reasonCode;
e.transports = null;
if (transport != null) {
e.transports = new ConcurrentHashSet(1);
@@ -150,6 +167,7 @@ public class Shitlist {
if (old.expireOn > e.expireOn) {
e.expireOn = old.expireOn;
e.cause = old.cause;
e.causeCode = old.causeCode;
}
if (e.transports != null) {
if (old.transports != null)
@@ -157,6 +175,7 @@ public class Shitlist {
else {
e.transports = null;
e.cause = reason;
e.causeCode = reasonCode;
}
}
}
@@ -245,44 +264,7 @@ public class Shitlist {
return entry != null && entry.expireOn > _context.clock().now() + SHITLIST_DURATION_MAX;
}
class HashComparator implements Comparator {
public int compare(Object l, Object r) {
return ((Hash)l).toBase64().compareTo(((Hash)r).toBase64());
}
}
/** @deprecated moved to router console */
public void renderStatusHTML(Writer out) throws IOException {
StringBuilder buf = new StringBuilder(1024);
// move to the jsp
//buf.append("<h2>Banned Peers</h2>");
Map<Hash, Entry> entries = new TreeMap(new HashComparator());
entries.putAll(_entries);
buf.append("<ul>");
for (Map.Entry<Hash, Entry> e : entries.entrySet()) {
Hash key = e.getKey();
Entry entry = e.getValue();
buf.append("<li>").append(_context.commSystem().renderPeerHTML(key));
long expires = entry.expireOn-_context.clock().now();
if (expires < 5l*24*60*60*1000)
buf.append(" Temporary ban expiring in ");
else
buf.append(" Banned until restart or in ");
buf.append(DataHelper.formatDuration(expires));
Set transports = entry.transports;
if ( (transports != null) && (transports.size() > 0) )
buf.append(" on the following transport: ").append(transports);
if (entry.cause != null) {
buf.append("<br>\n");
buf.append(entry.cause);
}
buf.append(" (<a href=\"configpeer.jsp?peer=").append(key.toBase64()).append("#unsh\">unban now</a>)");
buf.append("</li>\n");
}
buf.append("</ul>\n");
out.write(buf.toString());
out.flush();
}
}

View File

@@ -67,7 +67,7 @@ public class GetBidsJob extends JobImpl {
if (failedCount == 0) {
context.statManager().addRateData("transport.bidFailNoTransports", msg.getLifetime(), 0);
// This used to be "no common transports" but it is almost always no transports at all
context.shitlist().shitlistRouter(to, "No transports (hidden or starting up?)");
context.shitlist().shitlistRouter(to, _x("No transports (hidden or starting up?)"));
} else if (failedCount >= facade.getTransportCount()) {
context.statManager().addRateData("transport.bidFailAllTransports", msg.getLifetime(), 0);
// fail after all transports were unsuccessful
@@ -98,4 +98,14 @@ public class GetBidsJob extends JobImpl {
msg.discardData();
}
/**
* Mark a string for extraction by xgettext and translation.
* Use this only in static initializers.
* It does not translate!
* @return s
*/
private static final String _x(String s) {
return s;
}
}

View File

@@ -447,7 +447,7 @@ public class TransportManager implements TransportEventListener {
// Don't shitlist if we aren't talking to anybody, as we may have a network connection issue
if (unreachableTransports >= _transports.size() && countActivePeers() > 0) {
_context.statManager().addRateData("transport.shitlistOnUnreachable", msg.getLifetime(), msg.getLifetime());
_context.shitlist().shitlistRouter(peer, "Unreachable on any transport");
_context.shitlist().shitlistRouter(peer, _x("Unreachable on any transport"));
}
} else if (rv == null) {
_context.statManager().addRateData("transport.noBidsYetNotAllUnreachable", unreachableTransports, msg.getLifetime());
@@ -493,7 +493,7 @@ public class TransportManager implements TransportEventListener {
t.renderStatusHTML(out, urlBase, sortFlags);
}
StringBuilder buf = new StringBuilder(4*1024);
buf.append("<h3>Router Transport Addresses:</h3><pre>\n");
buf.append("<h3>Router Transport Addresses</h3><pre>\n");
for (int i = 0; i < _transports.size(); i++) {
Transport t = (Transport)_transports.get(i);
if (t.getCurrentAddress() != null)
@@ -508,4 +508,15 @@ public class TransportManager implements TransportEventListener {
buf.append("</p>\n");
out.flush();
}
/**
* Mark a string for extraction by xgettext and translation.
* Use this only in static initializers.
* It does not translate!
* @return s
*/
private static final String _x(String s) {
return s;
}
}

View File

@@ -368,8 +368,9 @@ public class EstablishState {
if (diff >= Router.CLOCK_FUDGE_FACTOR) {
_context.statManager().addRateData("ntcp.invalidOutboundSkew", diff, 0);
_transport.markReachable(_con.getRemotePeer().calculateHash(), false);
_context.shitlist().shitlistRouter(_con.getRemotePeer().calculateHash(),
"Excessive clock skew: " + DataHelper.formatDuration(diff));
_context.shitlist().shitlistRouter(DataHelper.formatDuration(diff),
_con.getRemotePeer().calculateHash(),
_x("Excessive clock skew: {0}"));
fail("Clocks too skewed (" + diff + " ms)", null, true);
return;
} else if (_log.shouldLog(Log.DEBUG)) {
@@ -572,7 +573,9 @@ public class EstablishState {
if (diff >= Router.CLOCK_FUDGE_FACTOR) {
_context.statManager().addRateData("ntcp.invalidInboundSkew", diff, 0);
_transport.markReachable(alice.calculateHash(), true);
_context.shitlist().shitlistRouter(alice.calculateHash(), "Clock skew of " + diff + " ms");
_context.shitlist().shitlistRouter(DataHelper.formatDuration(diff),
alice.calculateHash(),
_x("Excessive clock skew: {0}"));
fail("Clocks too skewed (" + diff + " ms)", null, true);
return;
} else if (_log.shouldLog(Log.DEBUG)) {
@@ -923,4 +926,15 @@ public class EstablishState {
e.printStackTrace();
}
}
/**
* Mark a string for extraction by xgettext and translation.
* Use this only in static initializers.
* It does not translate!
* @return s
*/
private static final String _x(String s) {
return s;
}
}

View File

@@ -2059,7 +2059,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
}
}
private static final String KEY = "<h3>Definitions:</h3><div class=\"configure\">" +
private static final String KEY = "<h3>Definitions</h3><div class=\"configure\">" +
"<p><b id=\"def.peer\">Peer</b>: the remote peer.<br>\n" +
"<b id=\"def.dir\">Dir</b>: v means they offer to introduce us, ^ means we offer to introduce them.<br>\n" +
"<b id=\"def.idle\">Idle</b>: the idle time is how long since a packet has been received or sent.<br>\n" +