Search in sources :

Example 1 with DBHistory

use of net.i2p.router.peermanager.DBHistory in project i2p.i2p by i2p.

the class ProfileOrganizerRenderer method renderStatusHTML.

/**
 *  @param mode 0 = high cap; 1 = all; 2 = floodfill
 */
public void renderStatusHTML(Writer out, int mode) throws IOException {
    boolean full = mode == 1;
    Set<Hash> peers = _organizer.selectAllPeers();
    long now = _context.clock().now();
    long hideBefore = now - 90 * 60 * 1000;
    Set<PeerProfile> order = new TreeSet<PeerProfile>(mode == 2 ? new HashComparator() : new ProfileComparator());
    int older = 0;
    int standard = 0;
    for (Hash peer : peers) {
        if (_organizer.getUs().equals(peer))
            continue;
        PeerProfile prof = _organizer.getProfileNonblocking(peer);
        if (prof == null)
            continue;
        if (mode == 2) {
            RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
            if (info != null && info.getCapabilities().indexOf('f') >= 0)
                order.add(prof);
            continue;
        }
        if (prof.getLastSendSuccessful() <= hideBefore) {
            older++;
            continue;
        }
        if ((!full) && !_organizer.isHighCapacity(peer)) {
            standard++;
            continue;
        }
        order.add(prof);
    }
    int fast = 0;
    int reliable = 0;
    int integrated = 0;
    StringBuilder buf = new StringBuilder(16 * 1024);
    // //
    if (mode < 2) {
        // buf.append("<h2>").append(_t("Peer Profiles")).append("</h2>\n<p>");
        buf.append("<p id=\"profiles_overview\" class=\"infohelp\">");
        buf.append(ngettext("Showing 1 recent profile.", "Showing {0} recent profiles.", order.size())).append('\n');
        if (older > 0)
            buf.append(ngettext("Hiding 1 older profile.", "Hiding {0} older profiles.", older)).append('\n');
        if (standard > 0)
            buf.append("<a href=\"/profiles?f=1\">").append(ngettext("Hiding 1 standard profile.", "Hiding {0} standard profiles.", standard)).append("</a>\n");
        buf.append("</p>");
        buf.append("<div class=\"widescroll\"><table id=\"profilelist\">");
        buf.append("<tr>");
        buf.append("<th>").append(_t("Peer")).append("</th>");
        buf.append("<th>").append(_t("Groups")).append("</th>");
        buf.append("<th>").append(_t("Caps")).append("</th>");
        buf.append("<th>").append(_t("Version")).append("</th>");
        buf.append("<th>").append(_t("Speed")).append("</th>");
        buf.append("<th>").append(_t("Capacity")).append("</th>");
        buf.append("<th>").append(_t("Integration")).append("</th>");
        buf.append("<th>").append(_t("Status")).append("</th>");
        buf.append("<th>").append(_t("View/Edit")).append("</th>");
        buf.append("</tr>");
        int prevTier = 1;
        for (PeerProfile prof : order) {
            Hash peer = prof.getPeer();
            int tier = 0;
            boolean isIntegrated = false;
            if (_organizer.isFast(peer)) {
                tier = 1;
                fast++;
                reliable++;
            } else if (_organizer.isHighCapacity(peer)) {
                tier = 2;
                reliable++;
            } else if (_organizer.isFailing(peer)) {
            } else {
                tier = 3;
            }
            if (_organizer.isWellIntegrated(peer)) {
                isIntegrated = true;
                integrated++;
            }
            if (tier != prevTier)
                buf.append("<tr><td colspan=\"9\"><hr></td></tr>\n");
            prevTier = tier;
            buf.append("<tr><td align=\"center\" nowrap>");
            buf.append(_context.commSystem().renderPeerHTML(peer));
            // debug
            // if(prof.getIsExpandedDB())
            // buf.append(" ** ");
            buf.append("</td><td align=\"center\">");
            switch(tier) {
                case 1:
                    buf.append(_t("Fast, High Capacity"));
                    break;
                case 2:
                    buf.append(_t("High Capacity"));
                    break;
                case 3:
                    buf.append(_t("Standard"));
                    break;
                default:
                    buf.append(_t("Failing"));
                    break;
            }
            if (isIntegrated)
                buf.append(", ").append(_t("Integrated"));
            RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
            if (info != null) {
                // prevent HTML injection in the caps and version
                buf.append("<td align=\"right\">").append(DataHelper.stripHTML(info.getCapabilities()));
            } else {
                buf.append("<td align=\"right\"><i>").append(_t("unknown")).append("</i></td>");
            }
            buf.append("<td align=\"right\">");
            String v = info != null ? info.getOption("router.version") : null;
            if (v != null)
                buf.append(DataHelper.stripHTML(v));
            buf.append("</td><td align=\"right\">").append(num(prof.getSpeedValue()));
            long bonus = prof.getSpeedBonus();
            if (bonus != 0) {
                if (bonus > 0)
                    buf.append(" (+");
                else
                    buf.append(" (");
                buf.append(bonus).append(')');
            }
            buf.append("</td><td align=\"right\">").append(num(prof.getCapacityValue()));
            bonus = prof.getCapacityBonus();
            if (bonus != 0) {
                if (bonus > 0)
                    buf.append(" (+");
                else
                    buf.append(" (");
                buf.append(bonus).append(')');
            }
            buf.append("</td><td align=\"right\">").append(num(prof.getIntegrationValue()));
            buf.append("</td><td align=\"center\">");
            boolean ok = true;
            if (_context.banlist().isBanlisted(peer)) {
                buf.append(_t("Banned"));
                ok = false;
            }
            if (prof.getIsFailing()) {
                buf.append(' ').append(_t("Failing"));
                ok = false;
            }
            if (_context.commSystem().wasUnreachable(peer)) {
                buf.append(' ').append(_t("Unreachable"));
                ok = false;
            }
            RateAverages ra = RateAverages.getTemp();
            Rate failed = prof.getTunnelHistory().getFailedRate().getRate(30 * 60 * 1000);
            long fails = failed.computeAverages(ra, false).getTotalEventCount();
            if (ok && fails == 0) {
                buf.append(_t("OK"));
            } else if (fails > 0) {
                Rate accepted = prof.getTunnelCreateResponseTime().getRate(30 * 60 * 1000);
                long total = fails + accepted.computeAverages(ra, false).getTotalEventCount();
                if (// hide if < 10%
                total / fails <= 10)
                    buf.append(' ').append(fails).append('/').append(total).append(' ').append(_t("Test Fails"));
            }
            buf.append("&nbsp;</td>");
            // buf.append("<td nowrap align=\"center\"><a target=\"_blank\" href=\"dumpprofile.jsp?peer=")
            // .append(peer.toBase64().substring(0,6)).append("\">").append(_t("profile")).append("</a>");
            buf.append("<td nowrap align=\"center\"><a href=\"viewprofile?peer=").append(peer.toBase64()).append("\">").append(_t("profile")).append("</a>");
            buf.append("&nbsp;<a title=\"").append(_t("Configure peer")).append("\" href=\"configpeer?peer=").append(peer.toBase64()).append("\">+-</a></td>\n");
            buf.append("</tr>");
            // let's not build the whole page in memory (~500 bytes per peer)
            out.write(buf.toString());
            buf.setLength(0);
        }
        buf.append("</table></div>");
    // //
    // // don't bother reindenting
    // //
    } else {
        // buf.append("<h2><a name=\"flood\"></a>").append(_t("Floodfill and Integrated Peers"))
        // .append(" (").append(integratedPeers.size()).append(")</h2>\n");
        buf.append("<div class=\"widescroll\"><table id=\"floodfills\">");
        buf.append("<tr class=\"smallhead\">");
        buf.append("<th>").append(_t("Peer")).append("</th>");
        buf.append("<th>").append(_t("Caps")).append("</th>");
        buf.append("<th>").append(_t("Integ. Value")).append("</th>");
        buf.append("<th>").append(_t("Last Heard About")).append("</th>");
        buf.append("<th>").append(_t("Last Heard From")).append("</th>");
        buf.append("<th>").append(_t("Last Good Send")).append("</th>");
        buf.append("<th>").append(_t("Last Bad Send")).append("</th>");
        buf.append("<th>").append(_t("10m Resp. Time")).append("</th>");
        buf.append("<th>").append(_t("1h Resp. Time")).append("</th>");
        buf.append("<th>").append(_t("1d Resp. Time")).append("</th>");
        buf.append("<th>").append(_t("Last Good Lookup")).append("</th>");
        buf.append("<th>").append(_t("Last Bad Lookup")).append("</th>");
        buf.append("<th>").append(_t("Last Good Store")).append("</th>");
        buf.append("<th>").append(_t("Last Bad Store")).append("</th>");
        buf.append("<th>").append(_t("1h Fail Rate")).append("</th>");
        buf.append("<th>").append(_t("1d Fail Rate")).append("</th>");
        buf.append("</tr>");
        RateAverages ra = RateAverages.getTemp();
        for (PeerProfile prof : order) {
            Hash peer = prof.getPeer();
            buf.append("<tr><td align=\"center\" nowrap>");
            buf.append(_context.commSystem().renderPeerHTML(peer));
            buf.append("</td>");
            RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
            if (info != null)
                buf.append("<td align=\"center\">").append(DataHelper.stripHTML(info.getCapabilities())).append("</td>");
            else
                buf.append("<td>&nbsp;</td>");
            buf.append("<td align=\"right\">").append(num(prof.getIntegrationValue())).append("</td>");
            buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastHeardAbout())).append("</td>");
            buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastHeardFrom())).append("</td>");
            buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastSendSuccessful())).append("</td>");
            buf.append("<td align=\"right\">").append(formatInterval(now, prof.getLastSendFailed())).append("</td>");
            buf.append("<td align=\"right\">").append(avg(prof, 10 * 60 * 1000l, ra)).append("</td>");
            buf.append("<td align=\"right\">").append(avg(prof, 60 * 60 * 1000l, ra)).append("</td>");
            buf.append("<td align=\"right\">").append(avg(prof, 24 * 60 * 60 * 1000l, ra)).append("</td>");
            DBHistory dbh = prof.getDBHistory();
            if (dbh != null) {
                buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastLookupSuccessful())).append("</td>");
                buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastLookupFailed())).append("</td>");
                buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastStoreSuccessful())).append("</td>");
                buf.append("<td align=\"right\">").append(formatInterval(now, dbh.getLastStoreFailed())).append("</td>");
                buf.append("<td align=\"right\">").append(davg(dbh, 60 * 60 * 1000l, ra)).append("</td>");
                buf.append("<td align=\"right\">").append(davg(dbh, 24 * 60 * 60 * 1000l, ra)).append("</td>");
            } else {
                for (int i = 0; i < 6; i++) buf.append("<td align=\"right\">").append(_t(NA));
            }
            buf.append("</tr>\n");
        }
        buf.append("</table></div>");
    // //
    // // don't bother reindenting
    // //
    }
    if (mode < 2) {
        buf.append("<h3 class=\"tabletitle\">").append(_t("Thresholds")).append("</h3>\n").append("<table id=\"thresholds\"><tbody>").append("<tr><th><b>").append(_t("Speed")).append(": </b>").append(num(_organizer.getSpeedThreshold())).append("</th><th><b>").append(_t("Capacity")).append(": </b>").append(num(_organizer.getCapacityThreshold())).append("</th><th><b>").append(_t("Integration")).append(": </b>").append(num(_organizer.getIntegrationThreshold())).append("</th></tr><tr><td>").append(fast).append(' ').append(_t("fast peers")).append("</td><td>").append(reliable).append(' ').append(_t("high capacity peers")).append("</td><td>").append(integrated).append(' ').append(_t(" well integrated peers")).append("</td></tr></tbody></table>\n");
        buf.append("<h3 class=\"tabletitle\">").append(_t("Definitions")).append("</h3>\n").append("<table id=\"profile_defs\"><tbody>");
        buf.append("<tr><td><b>").append(_t("groups")).append(":</b></td><td>").append(_t("as determined by the profile organizer")).append("</td></tr>");
        buf.append("<tr><td><b>").append(_t("caps")).append(":</b></td><td>").append(_t("capabilities in the netDb, not used to determine profiles")).append("</td></tr>");
        buf.append("<tr id=\"capabilities_key\"><td colspan=\"2\"><table><tbody>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>B</b></td><td>").append(_t("SSU Testing")).append("</td>").append("<td><b>C</b></td><td>").append(_t("SSU Introducer")).append("</td>").append("<td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>f</b></td><td>").append(_t("Floodfill")).append("</td>").append("<td><b>H</b></td><td>").append(_t("Hidden")).append("</td>").append("<td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>K</b></td><td>").append(_t("Under {0} shared bandwidth", Router.MIN_BW_L + " KBps")).append("</td>").append("<td><b>L</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_L, Router.MIN_BW_M))).append("</td>").append("<td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>M</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_M, Router.MIN_BW_N))).append("</td>").append("<td><b>N</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_N, Router.MIN_BW_O))).append("</td>").append("<td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>O</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_O, Router.MIN_BW_P))).append("</td>").append("<td><b>P</b></td><td>").append(_t("{0} shared bandwidth", range(Router.MIN_BW_P, Router.MIN_BW_X))).append("</td>").append("<td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>R</b></td><td>").append(_t("Reachable")).append("</td>").append("<td><b>U</b></td><td>").append(_t("Unreachable")).append("</td>").append("<td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td>").append("<td><b>X</b></td><td>").append(_t("Over {0} shared bandwidth", Math.round(Router.MIN_BW_X * 1.024f) + " KBps")).append("</td>").append("<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>");
        buf.append("<tr><td>&nbsp;</td><td colspan=\"5\">").append(_t("Note: For P and X bandwidth tiers, O is included for the purpose of backward compatibility in the NetDB.")).append("</tr>");
        // profile_defs
        buf.append("</tbody></table></td></tr>");
        buf.append("<tr><td><b>").append(_t("speed")).append(":</b></td><td>").append(_t("peak throughput (bytes per second) over a 1 minute period that the peer has sustained in a single tunnel")).append("</td></tr>");
        buf.append("<tr><td><b>").append(_t("capacity")).append(":</b></td><td>").append(_t("how many tunnels can we ask them to join in an hour?")).append("</td></tr>");
        buf.append("<tr><td><b>").append(_t("integration")).append(":</b></td><td>").append(_t("how many new peers have they told us about lately?")).append("</td></tr>");
        buf.append("<tr><td><b>").append(_t("status")).append(":</b></td><td>").append(_t("is the peer banned, or unreachable, or failing tunnel tests?")).append("</td></tr>");
        // thresholds
        buf.append("</tbody></table>\n");
    // //
    // // don't bother reindenting
    // //
    }
    // mode < 2
    out.write(buf.toString());
    out.flush();
}
Also used : DBHistory(net.i2p.router.peermanager.DBHistory) RouterInfo(net.i2p.data.router.RouterInfo) Rate(net.i2p.stat.Rate) Hash(net.i2p.data.Hash) TreeSet(java.util.TreeSet) PeerProfile(net.i2p.router.peermanager.PeerProfile) RateAverages(net.i2p.stat.RateAverages)

Example 2 with DBHistory

use of net.i2p.router.peermanager.DBHistory in project i2p.i2p by i2p.

the class SybilRenderer method renderRouterInfo.

/**
 *  Be careful to use stripHTML for any displayed routerInfo data
 *  to prevent vulnerabilities
 *
 *  @param us ROUTING KEY or null
 *  @param full ignored
 *  @return distance to us if non-null, else 0
 */
private double renderRouterInfo(StringBuilder buf, RouterInfo info, Hash us, boolean isUs, boolean full) {
    String hash = info.getIdentity().getHash().toBase64();
    buf.append("<a name=\"").append(hash.substring(0, 6)).append("\"></a><table class=\"sybil_routerinfo\"><tr>");
    double distance = 0;
    if (isUs) {
        buf.append("<th colspan=\"2\"><a name=\"our-info\" ></a><b>" + _t("Our info") + ":</b> <code>").append(hash).append("</code></th></tr>\n<tr><td class=\"sybilinfo_params\" colspan=\"2\"><div class=\"sybilinfo_container\">");
    } else {
        buf.append("<th><b>" + _t("Router") + ":</b> <code>").append(hash).append("</code>\n");
        String country = _context.commSystem().getCountry(info.getIdentity().getHash());
        buf.append("</th><th>");
        if (country != null) {
            buf.append("<a href=\"/netdb?c=").append(country).append("\">");
            buf.append("<img height=\"11\" width=\"16\" alt=\"").append(country.toUpperCase(Locale.US)).append('\"');
            buf.append(" title=\"").append(getTranslatedCountry(country)).append('\"');
            buf.append(" src=\"/flags.jsp?c=").append(country).append("\"> ").append("</a>");
        }
        if (!full) {
            buf.append("<a title=\"View extended router info\" class=\"viewfullentry\" href=\"netdb?r=").append(hash.substring(0, 6)).append("\" >[").append(_t("Full entry")).append("]</a></th><th>");
        }
        if (_context.portMapper().getPort("imagegen") > 0)
            buf.append("<img src=\"/imagegen/id?s=32&amp;c=" + hash.replace("=", "%3d") + "\" height=\"32\" width=\"32\"> ");
        buf.append("</th></tr>\n<tr><td class=\"sybilinfo_params\" colspan=\"3\"><div class=\"sybilinfo_container\">");
        if (us != null) {
            BigInteger dist = HashDistance.getDistance(us, info.getHash());
            distance = biLog2(dist);
            buf.append("<p><b>Hash Distance:</b> ").append(fmt.format(distance)).append("</p>\n");
        }
    }
    buf.append("<p><b>Version:</b> ").append(DataHelper.stripHTML(info.getVersion())).append("</p>\n");
    buf.append("<p><b>Caps:</b> ").append(DataHelper.stripHTML(info.getCapabilities())).append("</p>\n");
    String kr = info.getOption("netdb.knownRouters");
    ;
    if (kr != null) {
        buf.append("<p><b>Routers:</b> ").append(DataHelper.stripHTML(kr)).append("</p>");
    } else {
        buf.append("<p class=\"sybil_filler\"><b>Routers:</b> ").append(_t("n/a")).append("</p>");
    }
    String kls = info.getOption("netdb.knownLeaseSets");
    if (kls != null) {
        buf.append("<p class=\"sybilinfo_leasesets\"><b>Lease Sets:</b> ").append(DataHelper.stripHTML(kls)).append("</p>\n");
    } else {
        buf.append("<p class=\"sybilinfo_leasesets filler\"><b>Lease Sets:</b> ").append(_t("n/a")).append("</p>");
    }
    String fam = info.getOption("family");
    if (fam != null) {
        buf.append("<p><b>Family:</b> <span class=\"sybilinfo_familyname\">").append(DataHelper.escapeHTML(fam)).append("</span></p>\n");
    }
    long now = _context.clock().now();
    if (!isUs) {
        PeerProfile prof = _context.profileOrganizer().getProfileNonblocking(info.getHash());
        if (prof != null) {
            long heard = prof.getFirstHeardAbout();
            if (heard > 0) {
                long age = Math.max(now - heard, 1);
                buf.append("<p><b>First heard about:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>");
            } else {
                buf.append("<p class=\"sybil_filler\"><b>First heard about:</b> ").append(_t("n/a")).append("</p>");
            }
            heard = prof.getLastHeardAbout();
            if (heard > 0) {
                long age = Math.max(now - heard, 1);
                buf.append("<p><b>Last heard about:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>");
            } else {
                buf.append("<p class=\"sybil_filler\"><b>Last heard about:</b> ").append(_t("n/a")).append("</p>");
            }
            heard = prof.getLastHeardFrom();
            if (heard > 0) {
                long age = Math.max(now - heard, 1);
                buf.append("<p><b>Last heard from:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>\n");
            } else {
                buf.append("<p class=\"sybil_filler\"><b>Last heard from:</b> ").append(_t("n/a")).append("</p>");
            }
            DBHistory dbh = prof.getDBHistory();
            if (dbh != null) {
                heard = dbh.getLastLookupSuccessful();
                if (heard > 0) {
                    long age = Math.max(now - heard, 1);
                    buf.append("<p><b>Last lookup successful:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>");
                } else {
                    buf.append("<p class=\"sybil_filler\"><b>Last lookup successful:</b> ").append(_t("n/a")).append("</p>");
                }
                heard = dbh.getLastLookupFailed();
                if (heard > 0) {
                    long age = Math.max(now - heard, 1);
                    buf.append("<p><b>Last lookup failed:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>");
                } else {
                    buf.append("<p class=\"sybil_filler\"><b>Last lookup failed:</b> ").append(_t("n/a")).append("</p>");
                }
                heard = dbh.getLastStoreSuccessful();
                if (heard > 0) {
                    long age = Math.max(now - heard, 1);
                    buf.append("<p><b>Last store successful:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>");
                } else {
                    buf.append("<p class=\"sybil_filler\"><b>Last store successful:</b> ").append(_t("n/a")).append("</p>");
                }
                heard = dbh.getLastStoreFailed();
                if (heard > 0) {
                    long age = Math.max(now - heard, 1);
                    buf.append("<p><b>Last store failed:</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>");
                } else {
                    buf.append("<p class=\"sybil_filler\"><b>Last store failed:</b> ").append(_t("n/a")).append("</p>");
                }
            }
        // any other profile stuff?
        }
    }
    long age = Math.max(now - info.getPublished(), 1);
    if (isUs && _context.router().isHidden()) {
        buf.append("<p><b>").append(_t("Hidden")).append(", ").append(_t("Updated")).append(":</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>\n");
    } else {
        buf.append("<p><b>").append(_t("Published")).append(":</b> ").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</p>\n");
    }
    buf.append("<p><b>").append(_t("Signing Key")).append(":</b> ").append(info.getIdentity().getSigningPublicKey().getType().toString()).append("</p>\n");
    buf.append("<p class=\"sybil_filler\">&nbsp;</p>");
    buf.append("</div></td></tr><tr><td class=\"sybil_addresses\" colspan=\"3\"><table><tr><td><b>" + _t("Addresses") + ":</b></td><td>");
    for (RouterAddress addr : info.getAddresses()) {
        String style = addr.getTransportStyle();
        buf.append("<br><b class=\"netdb_transport\">").append(DataHelper.stripHTML(style)).append(":</b> ");
        Map<Object, Object> p = addr.getOptionsMap();
        for (Map.Entry<Object, Object> e : p.entrySet()) {
            String name = (String) e.getKey();
            if (name.equals("key") || name.startsWith("ikey") || name.startsWith("itag") || name.startsWith("iport") || name.equals("mtu"))
                continue;
            String val = (String) e.getValue();
            buf.append(" <span class=\"nowrap\"><span class=\"netdb_name\">").append(_t(DataHelper.stripHTML(name))).append(":</span> <span class=\"netdb_info\">");
            buf.append(DataHelper.stripHTML(val));
            buf.append("</span></span>&nbsp;");
        }
    }
    buf.append("</table></td></tr>\n");
    buf.append("</table>\n");
    return distance;
}
Also used : DBHistory(net.i2p.router.peermanager.DBHistory) BigInteger(java.math.BigInteger) PeerProfile(net.i2p.router.peermanager.PeerProfile) RouterAddress(net.i2p.data.router.RouterAddress) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with DBHistory

use of net.i2p.router.peermanager.DBHistory in project i2p.i2p by i2p.

the class SybilRenderer method addProfilePoints.

private void addProfilePoints(List<RouterInfo> ris, Map<Hash, Points> points) {
    long now = _context.clock().now();
    RateAverages ra = RateAverages.getTemp();
    for (RouterInfo info : ris) {
        Hash h = info.getHash();
        if (_context.banlist().isBanlisted(h))
            addPoints(points, h, POINTS_BANLIST, "Banlisted");
        PeerProfile prof = _context.profileOrganizer().getProfileNonblocking(h);
        if (prof != null) {
            long heard = prof.getFirstHeardAbout();
            if (heard > 0) {
                long age = Math.max(now - heard, 1);
                if (age < 2 * DAY) {
                    // (POINTS_NEW / 48) for every hour under 48, max POINTS_NEW
                    double point = Math.min(POINTS_NEW, (2 * DAY - age) / (2 * DAY / POINTS_NEW));
                    addPoints(points, h, point, "First heard about: " + _t("{0} ago", DataHelper.formatDuration2(age)));
                }
            }
            DBHistory dbh = prof.getDBHistory();
            if (dbh != null) {
                RateStat rs = dbh.getFailedLookupRate();
                if (rs != null) {
                    Rate r = rs.getRate(24 * 60 * 60 * 1000);
                    if (r != null) {
                        r.computeAverages(ra, false);
                        if (ra.getTotalEventCount() > 0) {
                            double avg = 100 * ra.getAverage();
                            if (avg > 40)
                                addPoints(points, h, (avg - 40) / 6.0, "Lookup fail rate " + ((int) avg) + '%');
                        }
                    }
                }
            }
        }
    }
}
Also used : RateStat(net.i2p.stat.RateStat) DBHistory(net.i2p.router.peermanager.DBHistory) RouterInfo(net.i2p.data.router.RouterInfo) Rate(net.i2p.stat.Rate) RateAverages(net.i2p.stat.RateAverages) PeerProfile(net.i2p.router.peermanager.PeerProfile) Hash(net.i2p.data.Hash) ConvertToHash(net.i2p.util.ConvertToHash)

Aggregations

DBHistory (net.i2p.router.peermanager.DBHistory)3 PeerProfile (net.i2p.router.peermanager.PeerProfile)3 Hash (net.i2p.data.Hash)2 RouterInfo (net.i2p.data.router.RouterInfo)2 Rate (net.i2p.stat.Rate)2 RateAverages (net.i2p.stat.RateAverages)2 BigInteger (java.math.BigInteger)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 RouterAddress (net.i2p.data.router.RouterAddress)1 RateStat (net.i2p.stat.RateStat)1 ConvertToHash (net.i2p.util.ConvertToHash)1