Search in sources :

Example 1 with FamilyKeyCrypto

use of net.i2p.router.crypto.FamilyKeyCrypto 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: &nbsp;<a href=\"/netdb?fam=").append(ss).append("&amp;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);
}
Also used : ObjectCounter(net.i2p.util.ObjectCounter) RouterInfo(net.i2p.data.router.RouterInfo) FamilyKeyCrypto(net.i2p.router.crypto.FamilyKeyCrypto) ArrayList(java.util.ArrayList)

Example 2 with FamilyKeyCrypto

use of net.i2p.router.crypto.FamilyKeyCrypto in project i2p.i2p by i2p.

the class StatisticsManager method publishStatistics.

/**
 *  Retrieve a snapshot of the statistics that should be published.
 *
 *  This includes all standard options (as of 0.9.24, network ID and caps)
 *
 *  @param h current router hash, non-null
 *  @since 0.9.24
 */
public Properties publishStatistics(Hash h) {
    Properties stats = new Properties();
    stats.setProperty("router.version", RouterVersion.VERSION);
    // never used
    // stats.setProperty("coreVersion", CoreVersion.VERSION);
    stats.setProperty(RouterInfo.PROP_NETWORK_ID, _networkID);
    stats.setProperty(RouterInfo.PROP_CAPABILITIES, _context.router().getCapabilities());
    if (_context.getBooleanPropertyDefaultTrue(PROP_PUBLISH_RANKINGS) && _context.random().nextInt(RANDOM_INCLUDE_STATS) == 0) {
        // long publishedUptime = _context.router().getUptime();
        // Don't publish these for first hour
        // Disabled in 0.9
        // if (publishedUptime > 62*60*1000)
        // includeAverageThroughput(stats);
        // includeRate("router.invalidMessageTime", stats, new long[] { 10*60*1000 });
        // includeRate("router.duplicateMessageId", stats, new long[] { 24*60*60*1000 });
        // includeRate("tunnel.duplicateIV", stats, new long[] { 24*60*60*1000 });
        // includeRate("tunnel.fragmentedDropped", stats, new long[] { 10*60*1000, 3*60*60*1000 });
        // includeRate("tunnel.fullFragments", stats, new long[] { 10*60*1000, 3*60*60*1000 });
        // includeRate("tunnel.smallFragments", stats, new long[] { 10*60*1000, 3*60*60*1000 });
        // includeRate("tunnel.testFailedTime", stats, new long[] { 10*60*1000 });
        // includeRate("tunnel.batchDelaySent", stats, new long[] { 10*60*1000, 60*60*1000 });
        // includeRate("tunnel.batchMultipleCount", stats, new long[] { 10*60*1000, 60*60*1000 });
        // includeRate("tunnel.corruptMessage", stats, new long[] { 60*60*1000l, 3*60*60*1000l });
        // includeRate("router.throttleTunnelProbTestSlow", stats, new long[] { 60*60*1000 });
        // includeRate("router.throttleTunnelProbTooFast", stats, new long[] { 60*60*1000 });
        // includeRate("router.throttleTunnelProcessingTime1m", stats, new long[] { 60*60*1000 });
        // includeRate("router.fastPeers", stats, new long[] { 60*60*1000 });
        // includeRate("udp.statusOK", stats, new long[] { 20*60*1000 });
        // includeRate("udp.statusDifferent", stats, new long[] { 20*60*1000 });
        // includeRate("udp.statusReject", stats, new long[] { 20*60*1000 });
        // includeRate("udp.statusUnknown", stats, new long[] { 20*60*1000 });
        // includeRate("udp.statusKnownCharlie", stats, new long[] { 1*60*1000, 10*60*1000 });
        // includeRate("udp.addressUpdated", stats, new long[] { 1*60*1000 });
        // includeRate("udp.addressTestInsteadOfUpdate", stats, new long[] { 1*60*1000 });
        // includeRate("clock.skew", stats, new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*1000 });
        // includeRate("transport.sendProcessingTime", stats, new long[] { 60*60*1000 });
        // includeRate("jobQueue.jobRunSlow", stats, new long[] { 10*60*1000l, 60*60*1000l });
        // includeRate("crypto.elGamal.encrypt", stats, new long[] { 60*60*1000 });
        // total event count can be used to track uptime
        includeRate("tunnel.participatingTunnels", stats, new long[] { 60 * 60 * 1000 }, true);
        // includeRate("tunnel.testSuccessTime", stats, new long[] { 10*60*1000l });
        // includeRate("client.sendAckTime", stats, new long[] { 60*60*1000 }, true);
        // includeRate("udp.sendConfirmTime", stats, new long[] { 10*60*1000 });
        // includeRate("udp.sendVolleyTime", stats, new long[] { 10*60*1000 });
        // includeRate("udp.ignoreRecentDuplicate", stats, new long[] { 60*1000 });
        // includeRate("udp.congestionOccurred", stats, new long[] { 10*60*1000 });
        // includeRate("stream.con.sendDuplicateSize", stats, new long[] { 60*60*1000 });
        // includeRate("stream.con.receiveDuplicateSize", stats, new long[] { 60*60*1000 });
        // stats.setProperty("stat__rateKey", "avg;maxAvg;pctLifetime;[sat;satLim;maxSat;maxSatLim;][num;lifetimeFreq;maxFreq]");
        // includeRate("tunnel.decryptRequestTime", stats, new long[] { 60*1000, 10*60*1000 });
        // includeRate("udp.packetDequeueTime", stats, new long[] { 60*1000 });
        // includeRate("udp.packetVerifyTime", stats, new long[] { 60*1000 });
        // includeRate("tunnel.buildRequestTime", stats, new long[] { 10*60*1000 });
        long rate = 60 * 60 * 1000;
        // includeTunnelRates("Client", stats, rate);
        includeTunnelRates("Exploratory", stats, rate);
    // includeRate("tunnel.rejectTimeout", stats, new long[] { 10*60*1000 });
    // includeRate("tunnel.rejectOverloaded", stats, new long[] { 10*60*1000 });
    // includeRate("tunnel.acceptLoad", stats, new long[] { 10*60*1000 });
    }
    // stats.setProperty("stat_uptime", "90m");
    if (FloodfillNetworkDatabaseFacade.isFloodfill(_context.router().getRouterInfo())) {
        int ri = _context.router().getUptime() > 30 * 60 * 1000 ? _context.netDb().getKnownRouters() : // so it isn't obvious we restarted
        3000 + _context.random().nextInt(1000);
        stats.setProperty("netdb.knownRouters", String.valueOf(ri));
        int ls = _context.router().getUptime() > 30 * 60 * 1000 ? _context.netDb().getKnownLeaseSets() : // so it isn't obvious we restarted
        30 + _context.random().nextInt(40);
        stats.setProperty("netdb.knownLeaseSets", String.valueOf(ls));
    }
    String contact = _context.getProperty(PROP_CONTACT_NAME);
    if (contact != null)
        stats.setProperty("contact", contact);
    String family = _context.getProperty(FamilyKeyCrypto.PROP_FAMILY_NAME);
    if (family != null) {
        stats.setProperty(FamilyKeyCrypto.OPT_NAME, family);
        String sig = null;
        String key = null;
        RouterInfo oldRI = _context.router().getRouterInfo();
        if (oldRI != null) {
            // don't do it if family changed
            if (family.equals(oldRI.getOption(FamilyKeyCrypto.OPT_NAME))) {
                // copy over the pubkey and signature
                key = oldRI.getOption(FamilyKeyCrypto.OPT_KEY);
                if (key != null) {
                    if (key.contains(";")) {
                        // we changed the separator from ';' to ':'
                        key = null;
                    } else {
                        stats.setProperty(FamilyKeyCrypto.OPT_KEY, key);
                        sig = oldRI.getOption(FamilyKeyCrypto.OPT_SIG);
                        if (sig != null)
                            stats.setProperty(FamilyKeyCrypto.OPT_SIG, sig);
                    }
                }
            }
        }
        if (sig == null || key == null) {
            FamilyKeyCrypto fkc = _context.router().getFamilyKeyCrypto();
            if (fkc != null) {
                try {
                    stats.putAll(fkc.sign(family, h));
                } catch (GeneralSecurityException gse) {
                    _log.error("Failed to sign router family", gse);
                    stats.remove(FamilyKeyCrypto.OPT_KEY);
                    stats.remove(FamilyKeyCrypto.OPT_SIG);
                }
            }
        }
    }
    return stats;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) FamilyKeyCrypto(net.i2p.router.crypto.FamilyKeyCrypto) GeneralSecurityException(java.security.GeneralSecurityException) Properties(java.util.Properties)

Aggregations

RouterInfo (net.i2p.data.router.RouterInfo)2 FamilyKeyCrypto (net.i2p.router.crypto.FamilyKeyCrypto)2 GeneralSecurityException (java.security.GeneralSecurityException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 ObjectCounter (net.i2p.util.ObjectCounter)1