take note of the reason each peer is shitlisted and display that on the console (good idea oOo)

cleaned up the shitlisting process within the TCPTransport so that we don't shitlist twice (clobbering the detailed cause with a general "uh, couldn't contact 'em" cause)
This commit is contained in:
jrandom
2004-08-11 22:51:00 +00:00
committed by zzz
parent 2f28a635a9
commit eeb1852d95

View File

@ -28,13 +28,15 @@ public class Shitlist {
private Log _log;
private RouterContext _context;
private Map _shitlist; // H(routerIdent) --> Date
private Map _shitlistCause; // H(routerIdent) --> String
public final static long SHITLIST_DURATION_MS = 4*60*1000; // 4 minute shitlist
public Shitlist(RouterContext context) {
_context = context;
_log = context.logManager().getLog(Shitlist.class);
_shitlist = new HashMap(100);
_shitlist = new HashMap(5);
_shitlistCause = new HashMap(5);
}
public int getRouterCount() {
@ -44,6 +46,9 @@ public class Shitlist {
}
public boolean shitlistRouter(Hash peer) {
return shitlistRouter(peer, null);
}
public boolean shitlistRouter(Hash peer, String reason) {
if (peer == null) return false;
if (_context.routerHash().equals(peer)) {
_log.error("wtf, why did we try to shitlist ourselves?", new Exception("shitfaced"));
@ -56,6 +61,11 @@ public class Shitlist {
synchronized (_shitlist) {
Date oldDate = (Date)_shitlist.put(peer, new Date(_context.clock().now()));
wasAlready = (null == oldDate);
if (reason != null) {
_shitlistCause.put(peer, reason);
} else {
_shitlistCause.remove(peer);
}
}
//_context.netDb().fail(peer);
@ -68,6 +78,7 @@ public class Shitlist {
_log.info("Unshitlisting router " + peer.toBase64());
synchronized (_shitlist) {
_shitlist.remove(peer);
_shitlistCause.remove(peer);
}
}
@ -90,9 +101,11 @@ public class Shitlist {
public void renderStatusHTML(OutputStream out) throws IOException {
StringBuffer buf = new StringBuffer(1024);
buf.append("<h2>Shitlist</h2>");
Map shitlist = new HashMap();
Map shitlist = null;
Map causes = null;
synchronized (_shitlist) {
shitlist.putAll(_shitlist);
shitlist = new HashMap(_shitlist);
causes = new HashMap(_shitlistCause);
}
buf.append("<ul>");
@ -101,10 +114,18 @@ public class Shitlist {
for (Iterator iter = shitlist.keySet().iterator(); iter.hasNext(); ) {
Hash key = (Hash)iter.next();
Date shitDate = (Date)shitlist.get(key);
if (shitDate.getTime() < limit)
if (shitDate.getTime() < limit) {
unshitlistRouter(key);
else
buf.append("<li><b>").append(key.toBase64()).append("</b> was shitlisted on ").append(shitDate).append("</li>\n");
} else {
buf.append("<li><b>").append(key.toBase64()).append("</b> was shitlisted on ");
buf.append(shitDate);
String cause = (String)causes.get(key);
if (cause != null) {
buf.append("<br />\n");
buf.append(cause);
}
buf.append("</li>\n");
}
}
buf.append("</ul>\n");
out.write(buf.toString().getBytes());