Search in sources :

Example 71 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class SummaryHelper method reachability.

private NetworkStateMessage reachability() {
    if (_context.commSystem().isDummy())
        return new NetworkStateMessage(NetworkState.VMCOMM, "VM Comm System");
    if (_context.router().getUptime() > 60 * 1000 && (!_context.router().gracefulShutdownInProgress()) && !_context.clientManager().isAlive())
        // not a router problem but the user should know
        return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-Client Manager I2CP Error - check logs"));
    // Warn based on actual skew from peers, not update status, so if we successfully offset
    // the clock, we don't complain.
    // if (!_context.clock().getUpdatedSuccessfully())
    long skew = _context.commSystem().getFramedAveragePeerClockSkew(33);
    // Display the actual skew, not the offset
    if (Math.abs(skew) > 30 * 1000)
        return new NetworkStateMessage(NetworkState.CLOCKSKEW, _t("ERR-Clock Skew of {0}", DataHelper.formatDuration2(Math.abs(skew))));
    if (_context.router().isHidden())
        return new NetworkStateMessage(NetworkState.HIDDEN, _t("Hidden"));
    RouterInfo routerInfo = _context.router().getRouterInfo();
    if (routerInfo == null)
        return new NetworkStateMessage(NetworkState.TESTING, _t("Testing"));
    Status status = _context.commSystem().getStatus();
    NetworkState state = NetworkState.RUNNING;
    switch(status) {
        case OK:
        case IPV4_OK_IPV6_UNKNOWN:
        case IPV4_OK_IPV6_FIREWALLED:
        case IPV4_UNKNOWN_IPV6_OK:
        case IPV4_DISABLED_IPV6_OK:
        case IPV4_SNAT_IPV6_OK:
            RouterAddress ra = routerInfo.getTargetAddress("NTCP");
            if (ra == null)
                return new NetworkStateMessage(NetworkState.RUNNING, _t(status.toStatusString()));
            byte[] ip = ra.getIP();
            if (ip == null)
                return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-Unresolved TCP Address"));
            // TODO set IPv6 arg based on configuration?
            if (TransportUtil.isPubliclyRoutable(ip, true))
                return new NetworkStateMessage(NetworkState.RUNNING, _t(status.toStatusString()));
            return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-Private TCP Address"));
        case IPV4_SNAT_IPV6_UNKNOWN:
        case DIFFERENT:
            return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-SymmetricNAT"));
        case REJECT_UNSOLICITED:
            state = NetworkState.FIREWALLED;
        case IPV4_DISABLED_IPV6_FIREWALLED:
            if (routerInfo.getTargetAddress("NTCP") != null)
                return new NetworkStateMessage(NetworkState.WARN, _t("WARN-Firewalled with Inbound TCP Enabled"));
        // fall through...
        case IPV4_FIREWALLED_IPV6_OK:
        case IPV4_FIREWALLED_IPV6_UNKNOWN:
            if (((FloodfillNetworkDatabaseFacade) _context.netDb()).floodfillEnabled())
                return new NetworkStateMessage(NetworkState.WARN, _t("WARN-Firewalled and Floodfill"));
            // return new NetworkStateMessage(NetworkState.WARN, _t("WARN-Firewalled and Fast"));
            return new NetworkStateMessage(state, _t(status.toStatusString()));
        case DISCONNECTED:
            return new NetworkStateMessage(NetworkState.TESTING, _t("Disconnected - check network connection"));
        case HOSED:
            return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-UDP Port In Use - Set i2np.udp.internalPort=xxxx in advanced config and restart"));
        case UNKNOWN:
            state = NetworkState.TESTING;
        case IPV4_UNKNOWN_IPV6_FIREWALLED:
        case IPV4_DISABLED_IPV6_UNKNOWN:
        default:
            ra = routerInfo.getTargetAddress("SSU");
            if (ra == null && _context.router().getUptime() > 5 * 60 * 1000) {
                if (getActivePeers() <= 0)
                    return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-No Active Peers, Check Network Connection and Firewall"));
                else if (_context.getProperty(ConfigNetHelper.PROP_I2NP_NTCP_HOSTNAME) == null || _context.getProperty(ConfigNetHelper.PROP_I2NP_NTCP_PORT) == null)
                    return new NetworkStateMessage(NetworkState.ERROR, _t("ERR-UDP Disabled and Inbound TCP host/port not set"));
                else
                    return new NetworkStateMessage(NetworkState.WARN, _t("WARN-Firewalled with UDP Disabled"));
            }
            return new NetworkStateMessage(state, _t(status.toStatusString()));
    }
}
Also used : Status(net.i2p.router.CommSystemFacade.Status) FloodfillNetworkDatabaseFacade(net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade) RouterInfo(net.i2p.data.router.RouterInfo) RouterAddress(net.i2p.data.router.RouterAddress)

Example 72 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class SybilRenderer method renderRouterInfoHTML.

private void renderRouterInfoHTML(Writer out, StringBuilder buf, Hash us, double avgMinDist, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
    Collections.sort(ris, new RouterInfoRoutingKeyComparator(us));
    double min = 256;
    double max = 0;
    double tot = 0;
    double median = 0;
    int count = Math.min(MAX, ris.size());
    boolean isEven = (count % 2) == 0;
    int medIdx = isEven ? (count / 2) - 1 : (count / 2);
    for (int i = 0; i < count; i++) {
        RouterInfo ri = ris.get(i);
        double dist = renderRouterInfo(buf, ri, us, false, false);
        if (dist < avgMinDist) {
            if (i == 0) {
            // buf.append("<p><b>Not to worry, but above router is closer than average minimum distance " + fmt.format(avgMinDist) + "</b></p>");
            } else if (i == 1) {
                buf.append("<p class=\"sybil_info\"><b>Not to worry, but above routers are closer than average minimum distance " + fmt.format(avgMinDist) + "</b></p>");
            } else if (i == 2) {
                buf.append("<p class=\"sybil_info\"><b>Possible Sybil Warning - above routers are closer than average minimum distance " + fmt.format(avgMinDist) + "</b></p>");
            } else {
                buf.append("<p class=\"sybil_info\"><b>Major Sybil Warning - above router is closer than average minimum distance " + fmt.format(avgMinDist) + "</b></p>");
            }
        }
        // this is dumb because they are already sorted
        if (dist < min)
            min = dist;
        if (dist > max)
            max = dist;
        tot += dist;
        if (i == medIdx)
            median = dist;
        else if (i == medIdx + 1 && isEven)
            median = (median + dist) / 2;
        double point = MIN_CLOSE - dist;
        if (point > 0) {
            point *= OUR_KEY_FACTOR;
            addPoints(points, ri.getHash(), point, "Very close (" + fmt.format(dist) + ") to our key " + us.toBase64());
        }
        if (i >= MAX - 1)
            break;
    }
    double avg = tot / count;
    buf.append("<p id=\"sybil_totals\"><b>Totals for " + count + " floodfills: &nbsp;</b><span class=\"netdb_name\">MIN:</span > " + fmt.format(min) + "&nbsp; <span class=\"netdb_name\">AVG:</span> " + fmt.format(avg) + "&nbsp; <span class=\"netdb_name\">MEDIAN:</span> " + fmt.format(median) + "&nbsp; <span class=\"netdb_name\">MAX:</span> " + fmt.format(max) + "</p>\n");
    out.write(buf.toString());
    out.flush();
    buf.setLength(0);
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Example 73 with RouterInfo

use of net.i2p.data.router.RouterInfo 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)

Example 74 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class SybilRenderer method renderIPGroupsUs.

private void renderIPGroupsUs(Writer out, StringBuilder buf, List<RouterInfo> ris, Map<Hash, Points> points) throws IOException {
    RouterInfo us = _context.router().getRouterInfo();
    byte[] ourIP = getIP(us);
    if (ourIP == null)
        return;
    buf.append("<h3 id=\"ourIP\" class=\"sybils\">Floodfills close to Our IP</h3>");
    boolean found = false;
    for (RouterInfo info : ris) {
        byte[] ip = getIP(info);
        if (ip == null)
            continue;
        if (ip[0] == ourIP[0] && ip[1] == ourIP[1]) {
            buf.append("<p id=\"sybil_info\"><b>");
            if (ip[2] == ourIP[2]) {
                if (ip[3] == ourIP[3]) {
                    buf.append("Same IP as us");
                    addPoints(points, info.getHash(), POINTS_US32, "Same IP as us");
                } else {
                    buf.append("Same /24 as us");
                    addPoints(points, info.getHash(), POINTS_US24, "Same /24 as us");
                }
            } else {
                buf.append("Same /16 as us");
                addPoints(points, info.getHash(), POINTS_US16, "Same /16 as us");
            }
            buf.append(":</b></p>");
            renderRouterInfo(buf, info, null, false, false);
            found = true;
        }
    }
    if (!found)
        buf.append("<p class=\"notfound\">None</p>");
    out.write(buf.toString());
    out.flush();
    buf.setLength(0);
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Example 75 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class RouterGenerator method createRouterInfo.

static RouterInfo createRouterInfo(int num) {
    RouterInfo info = new RouterInfo();
    try {
        info.setAddresses(createAddresses(num));
        // not necessary, in constructor
        // info.setOptions(new Properties());
        // info.setPeers(new HashSet());
        info.setPublished(Clock.getInstance().now());
        RouterIdentity ident = new RouterIdentity();
        BigInteger bv = new BigInteger("" + num);
        Certificate cert = new Certificate(Certificate.CERTIFICATE_TYPE_NULL, bv.toByteArray());
        ident.setCertificate(cert);
        ident.setPublicKey(pubkey);
        ident.setSigningPublicKey(signingPubKey);
        info.setIdentity(ident);
        info.sign(signingPrivKey);
    } catch (Exception e) {
        System.err.println("Error building router " + num + ": " + e.getMessage());
        e.printStackTrace();
    }
    return info;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) RouterIdentity(net.i2p.data.router.RouterIdentity) BigInteger(java.math.BigInteger) Certificate(net.i2p.data.Certificate)

Aggregations

RouterInfo (net.i2p.data.router.RouterInfo)95 Hash (net.i2p.data.Hash)45 ArrayList (java.util.ArrayList)18 RouterAddress (net.i2p.data.router.RouterAddress)17 DataFormatException (net.i2p.data.DataFormatException)11 IOException (java.io.IOException)10 RouterIdentity (net.i2p.data.router.RouterIdentity)10 DatabaseEntry (net.i2p.data.DatabaseEntry)9 OutNetMessage (net.i2p.router.OutNetMessage)9 File (java.io.File)8 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)8 Properties (java.util.Properties)7 LeaseSet (net.i2p.data.LeaseSet)6 BigInteger (java.math.BigInteger)5 Date (java.util.Date)5 SigType (net.i2p.crypto.SigType)5 TunnelId (net.i2p.data.TunnelId)5 TunnelInfo (net.i2p.router.TunnelInfo)5 FileOutputStream (java.io.FileOutputStream)4 HashMap (java.util.HashMap)4