use of net.i2p.util.ObjectCounter in project i2p.i2p by i2p.
the class JobQueueHelper method renderStatusHTML.
/**
* Moved from JobQueue
* @since 0.8.9
*/
private void renderStatusHTML(Writer out) throws IOException {
List<Job> readyJobs = new ArrayList<Job>(8);
List<Job> timedJobs = new ArrayList<Job>(128);
List<Job> activeJobs = new ArrayList<Job>(8);
List<Job> justFinishedJobs = new ArrayList<Job>(8);
int numRunners = _context.jobQueue().getJobs(readyJobs, timedJobs, activeJobs, justFinishedJobs);
StringBuilder buf = new StringBuilder(32 * 1024);
buf.append("<div class=\"joblog\">").append("<h2 id=\"jobrunners\">").append(_t("Job runners")).append(": ").append(numRunners).append("</h2>\n");
long now = _context.clock().now();
buf.append("<h3 id=\"activejobs\">").append(_t("Active jobs")).append(": ").append(activeJobs.size()).append("</h3><ol>");
for (int i = 0; i < activeJobs.size(); i++) {
Job j = activeJobs.get(i);
buf.append("<li>(").append(_t("started {0} ago", DataHelper.formatDuration2(now - j.getTiming().getStartAfter()))).append("): ");
buf.append(j.toString()).append("</li>\n");
}
buf.append("</ol>\n");
buf.append("<h3 id=\"finishedjobs\">").append(_t("Just finished jobs")).append(": ").append(justFinishedJobs.size()).append("</h3><ol>");
for (int i = 0; i < justFinishedJobs.size(); i++) {
Job j = justFinishedJobs.get(i);
buf.append("<li>(").append(_t("finished {0} ago", DataHelper.formatDuration2(now - j.getTiming().getActualEnd()))).append("): ");
buf.append(j.toString()).append("</li>\n");
}
buf.append("</ol>\n");
buf.append("<h3 id=\"readyjobs\">").append(_t("Ready/waiting jobs")).append(": ").append(readyJobs.size()).append("</h3><ol>");
ObjectCounter<String> counter = new ObjectCounter<String>();
for (int i = 0; i < readyJobs.size(); i++) {
Job j = readyJobs.get(i);
counter.increment(j.getName());
if (i >= MAX_JOBS)
continue;
buf.append("<li>[waiting ");
buf.append(DataHelper.formatDuration2(now - j.getTiming().getStartAfter()));
buf.append("]: ");
buf.append(j.toString()).append("</li>\n");
}
buf.append("</ol>\n");
getJobCounts(buf, counter);
out.write(buf.toString());
buf.setLength(0);
buf.append("<h3 id=\"scheduledjobs\">").append(_t("Scheduled jobs")).append(": ").append(timedJobs.size()).append("</h3><ol>");
long prev = Long.MIN_VALUE;
counter.clear();
for (int i = 0; i < timedJobs.size(); i++) {
Job j = timedJobs.get(i);
counter.increment(j.getName());
if (i >= MAX_JOBS)
continue;
long time = j.getTiming().getStartAfter() - now;
// translators: {0} is a job name, {1} is a time, e.g. 6 min
buf.append("<li>").append(_t("{0} will start in {1}", j.getName(), DataHelper.formatDuration2(time)));
// debug, don't bother translating
if (time < 0)
buf.append(" <b>DELAYED</b>");
if (time < prev)
buf.append(" <b>** OUT OF ORDER **</b>");
prev = time;
buf.append("</li>\n");
}
buf.append("</ol></div>\n");
getJobCounts(buf, counter);
out.write(buf.toString());
buf.setLength(0);
buf.append("<h3 id=\"totaljobstats\">").append(_t("Total Job Statistics")).append("</h3>\n");
getJobStats(buf);
out.write(buf.toString());
}
use of net.i2p.util.ObjectCounter in project i2p.i2p by i2p.
the class SybilRenderer method renderIPGroupsFamily.
private void renderIPGroupsFamily(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
buf.append("<h3 id=\"samefamily\" class=\"sybils\">Floodfills in the Same Declared Family</h3><div class=\"sybil_container\">");
ObjectCounter<String> oc = new ObjectCounter<String>();
for (RouterInfo info : ris) {
String fam = info.getOption("family");
if (fam == null)
continue;
oc.increment(fam);
}
List<String> foo = new ArrayList<String>(oc.objects());
Collections.sort(foo, new FoofComparator(oc));
FamilyKeyCrypto fkc = _context.router().getFamilyKeyCrypto();
String ourFamily = fkc != null ? fkc.getOurFamilyName() : null;
boolean found = false;
for (String s : foo) {
int count = oc.count(s);
String ss = DataHelper.escapeHTML(s);
if (count > 1) {
buf.append("<p class=\"family\"><b>").append(count).append(" floodfills in family: <a href=\"/netdb?fam=").append(ss).append("&sybil\">").append(ss).append("</a></b></p>");
}
for (RouterInfo info : ris) {
String fam = info.getOption("family");
if (fam == null)
continue;
if (!fam.equals(s))
continue;
found = true;
// limit display
// renderRouterInfo(buf, info, null, false, false);
double point = POINTS_FAMILY;
if (fkc != null && s.equals(ourFamily)) {
if (fkc.verifyOurFamily(info))
addPoints(points, info.getHash(), POINTS_OUR_FAMILY, "Our family \"" + DataHelper.escapeHTML(s) + "\" with " + (count - 1) + " other" + ((count > 2) ? "s" : ""));
else
addPoints(points, info.getHash(), POINTS_BAD_OUR_FAMILY, "Spoofed our family \"" + DataHelper.escapeHTML(s) + "\" with " + (count - 1) + " other" + ((count > 2) ? "s" : ""));
} else if (count > 1) {
addPoints(points, info.getHash(), point, "Same declared family \"" + DataHelper.escapeHTML(s) + "\" with " + (count - 1) + " other" + ((count > 2) ? "s" : ""));
} else {
addPoints(points, info.getHash(), point, "Declared family \"" + DataHelper.escapeHTML(s) + '"');
}
}
}
if (!found)
buf.append("<p class=\"notfound\">None</p>");
buf.append("</div>");
out.write(buf.toString());
out.flush();
buf.setLength(0);
}
use of net.i2p.util.ObjectCounter in project i2p.i2p by i2p.
the class SybilRenderer method renderIPGroups24.
private void renderIPGroups24(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
buf.append("<h3 id=\"same24\" class=\"sybils\">Floodfills in the Same /24 (2 minimum)</h3>");
ObjectCounter<Integer> oc = new ObjectCounter<Integer>();
for (RouterInfo info : ris) {
byte[] ip = getIP(info);
if (ip == null)
continue;
Integer x = Integer.valueOf((int) DataHelper.fromLong(ip, 0, 3));
oc.increment(x);
}
List<Integer> foo = new ArrayList<Integer>();
for (Integer ii : oc.objects()) {
int count = oc.count(ii);
if (count >= 2)
foo.add(ii);
}
Collections.sort(foo, new FooComparator(oc));
boolean found = false;
for (Integer ii : foo) {
int count = oc.count(ii);
int i = ii.intValue();
int i0 = i >> 16;
int i1 = (i >> 8) & 0xff;
int i2 = i & 0xff;
String sip = i0 + "." + i1 + '.' + i2 + ".0/24";
buf.append("<p class=\"sybil_info\"><b>").append(count).append(" floodfills with IP <a href=\"/netdb?ip=").append(sip).append("&sybil\">").append(sip).append("</a>:</b></p>");
for (RouterInfo info : ris) {
byte[] ip = getIP(info);
if (ip == null)
continue;
if ((ip[0] & 0xff) != i0)
continue;
if ((ip[1] & 0xff) != i1)
continue;
if ((ip[2] & 0xff) != i2)
continue;
found = true;
renderRouterInfo(buf, info, null, false, false);
double point = POINTS24 * (count - 1);
addPoints(points, info.getHash(), point, "Same /24 IP with " + (count - 1) + " other" + ((count > 2) ? "s" : ""));
}
}
if (!found)
buf.append("<p class=\"notfound\">None</p>");
out.write(buf.toString());
out.flush();
buf.setLength(0);
}
use of net.i2p.util.ObjectCounter in project i2p.i2p by i2p.
the class SybilRenderer method renderIPGroups16.
private void renderIPGroups16(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
buf.append("<h3 id=\"same16\" class=\"sybils\">Floodfills in the Same /16 (4 minimum)</h3>");
ObjectCounter<Integer> oc = new ObjectCounter<Integer>();
for (RouterInfo info : ris) {
byte[] ip = getIP(info);
if (ip == null)
continue;
Integer x = Integer.valueOf((int) DataHelper.fromLong(ip, 0, 2));
oc.increment(x);
}
List<Integer> foo = new ArrayList<Integer>();
for (Integer ii : oc.objects()) {
int count = oc.count(ii);
if (count >= 4)
foo.add(ii);
}
Collections.sort(foo, new FooComparator(oc));
boolean found = false;
for (Integer ii : foo) {
int count = oc.count(ii);
int i = ii.intValue();
int i0 = i >> 8;
int i1 = i & 0xff;
String sip = i0 + "." + i1 + ".0/16";
buf.append("<p class=\"sybil_info\"><b>").append(count).append(" floodfills with IP <a href=\"/netdb?ip=").append(sip).append("&sybil\">").append(sip).append("</a></b></p>");
for (RouterInfo info : ris) {
byte[] ip = getIP(info);
if (ip == null)
continue;
if ((ip[0] & 0xff) != i0)
continue;
if ((ip[1] & 0xff) != i1)
continue;
found = true;
// limit display
// renderRouterInfo(buf, info, null, false, false);
double point = POINTS16 * (count - 1);
addPoints(points, info.getHash(), point, "Same /16 IP with " + (count - 1) + " other" + ((count > 2) ? "s" : ""));
}
}
if (!found)
buf.append("<p class=\"notfound\">None</p>");
out.write(buf.toString());
out.flush();
buf.setLength(0);
}
use of net.i2p.util.ObjectCounter in project i2p.i2p by i2p.
the class SybilRenderer method renderIPGroups32.
private void renderIPGroups32(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
buf.append("<h3 id=\"sameIP\" class=\"sybils\">Floodfills with the Same IP</h3>");
ObjectCounter<Integer> oc = new ObjectCounter<Integer>();
for (RouterInfo info : ris) {
byte[] ip = getIP(info);
if (ip == null)
continue;
Integer x = Integer.valueOf((int) DataHelper.fromLong(ip, 0, 4));
oc.increment(x);
}
List<Integer> foo = new ArrayList<Integer>();
for (Integer ii : oc.objects()) {
int count = oc.count(ii);
if (count >= 2)
foo.add(ii);
}
Collections.sort(foo, new FooComparator(oc));
boolean found = false;
for (Integer ii : foo) {
int count = oc.count(ii);
int i = ii.intValue();
int i0 = (i >> 24) & 0xff;
int i1 = (i >> 16) & 0xff;
int i2 = (i >> 8) & 0xff;
int i3 = i & 0xff;
String sip = i0 + "." + i1 + '.' + i2 + '.' + i3;
buf.append("<p class=\"sybil_info\"><b>").append(count).append(" floodfills with IP <a href=\"/netdb?ip=").append(sip).append("&sybil\">").append(sip).append("</a>:</b></p>");
for (RouterInfo info : ris) {
byte[] ip = getIP(info);
if (ip == null)
continue;
if ((ip[0] & 0xff) != i0)
continue;
if ((ip[1] & 0xff) != i1)
continue;
if ((ip[2] & 0xff) != i2)
continue;
if ((ip[3] & 0xff) != i3)
continue;
found = true;
renderRouterInfo(buf, info, null, false, false);
double point = POINTS32 * (count - 1);
addPoints(points, info.getHash(), point, "Same IP with " + (count - 1) + " other" + ((count > 2) ? "s" : ""));
}
}
if (!found)
buf.append("<p class=\"notfound\">None</p>");
out.write(buf.toString());
out.flush();
buf.setLength(0);
}
Aggregations