Search in sources :

Example 1 with RouterAddress

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

the class NetDbRenderer method classifyTransports.

/**
 *  what transport types
 */
private static int classifyTransports(RouterInfo info) {
    int rv = 0;
    for (RouterAddress addr : info.getAddresses()) {
        String style = addr.getTransportStyle();
        if (style.equals("NTCP")) {
            rv |= NTCP;
        } else if (style.equals("SSU")) {
            if (addr.getOption("iport0") != null)
                rv |= SSUI;
            else
                rv |= SSU;
        }
        String host = addr.getHost();
        if (host != null && host.contains(":"))
            rv |= IPV6;
    }
    return rv;
}
Also used : RouterAddress(net.i2p.data.router.RouterAddress)

Example 2 with RouterAddress

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

the class NetDbRenderer method renderRouterInfo.

/**
 *  Be careful to use stripHTML for any displayed routerInfo data
 *  to prevent vulnerabilities
 */
private void renderRouterInfo(StringBuilder buf, RouterInfo info, boolean isUs, boolean full) {
    String hash = info.getIdentity().getHash().toBase64();
    buf.append("<table class=\"netdbentry\">").append("<tr><th colspan=\"2\"><a name=\"").append(hash.substring(0, 6)).append("\" ></a>");
    if (isUs) {
        buf.append("<a name=\"our-info\" ></a><b>" + _t("Our info") + ":</b>&nbsp;<code>").append(hash).append("</code></th><th>");
    } else {
        buf.append("<b>" + _t("Peer info for") + ":</b>&nbsp;<code>").append(hash).append("</code></th><th>");
        String country = _context.commSystem().getCountry(info.getIdentity().getHash());
        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=\"").append(_t("View extended router info")).append("\" class=\"viewfullentry\" href=\"netdb?r=").append(hash.substring(0, 6)).append("\" >[").append(_t("Full entry")).append("]</a>");
        }
    }
    buf.append("</th></tr>\n<tr>");
    long age = _context.clock().now() - info.getPublished();
    if (isUs && _context.router().isHidden()) {
        buf.append("<td><b>").append(_t("Hidden")).append(", ").append(_t("Updated")).append(":</b></td>").append("<td colspan=\"2\"><span class=\"netdb_info\">").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</span>&nbsp;&nbsp;");
    } else if (age > 0) {
        buf.append("<td><b>").append(_t("Published")).append(":</b></td>").append("<td colspan=\"2\"><span class=\"netdb_info\">").append(_t("{0} ago", DataHelper.formatDuration2(age))).append("</span>&nbsp;&nbsp;");
    } else {
        // shouldnt happen
        buf.append("<td><b>").append(_t("Published")).append("</td><td colspan=\"2\">:</b> in ").append(DataHelper.formatDuration2(0 - age)).append("<span class=\"netdb_info\">???</span>&nbsp;&nbsp;");
    }
    buf.append("<b>").append(_t("Signing Key")).append(":</b> ").append(info.getIdentity().getSigningPublicKey().getType().toString());
    buf.append("</td></tr>\n<tr>").append("<td><b>" + _t("Addresses") + ":</b></td>").append("<td colspan=\"2\" class=\"netdb_addresses\">");
    Collection<RouterAddress> addrs = info.getAddresses();
    if (addrs.isEmpty()) {
        buf.append(_t("none"));
    } else {
        for (RouterAddress addr : info.getAddresses()) {
            String style = addr.getTransportStyle();
            buf.append("<br><b class=\"netdb_transport\">").append(DataHelper.stripHTML(style)).append(":</b>");
            int cost = addr.getCost();
            if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10)))
                buf.append("&nbsp;<span class=\"netdb_name\">").append(_t("cost")).append("</span>: <span class=\"netdb_info\">").append("" + cost).append("</span>&nbsp;");
            Map<Object, Object> p = addr.getOptionsMap();
            for (Map.Entry<Object, Object> e : p.entrySet()) {
                String name = (String) e.getKey();
                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\">").append(DataHelper.stripHTML(val)).append("</span></span>&nbsp;");
            }
        }
    }
    buf.append("</td></tr>\n");
    if (full) {
        buf.append("<tr><td><b>" + _t("Stats") + ":</b><td colspan=\"2\"><code>");
        Map<Object, Object> p = info.getOptionsMap();
        for (Map.Entry<Object, Object> e : p.entrySet()) {
            String key = (String) e.getKey();
            String val = (String) e.getValue();
            buf.append(DataHelper.stripHTML(key)).append(" = ").append(DataHelper.stripHTML(val)).append("<br>\n");
        }
        buf.append("</code></td></tr>\n");
    }
    buf.append("</table>\n");
}
Also used : RouterAddress(net.i2p.data.router.RouterAddress) Map(java.util.Map)

Example 3 with RouterAddress

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

the class ProofHelper method getProof.

public String getProof() {
    StringBuilder buf = new StringBuilder(512);
    RouterInfo us = _context.router().getRouterInfo();
    buf.append("Hash: ").append(us.getIdentity().calculateHash().toBase64()).append('\n');
    // buf.append("Ident: ").append(us.getIdentity().toBase64()).append('\n');
    for (RouterAddress addr : us.getAddresses()) {
        buf.append(addr.getTransportStyle()).append(": ").append(addr.getHost()).append('\n');
    }
    buf.append("Caps: ").append(us.getCapabilities()).append('\n');
    // no trailing newline
    buf.append("Date: ").append(new Date());
    String msg = buf.toString();
    byte[] data = DataHelper.getUTF8(msg);
    Signature sig = _context.dsa().sign(data, _context.keyManager().getSigningPrivateKey());
    buf.setLength(0);
    buf.append("---BEGIN I2P SIGNED MESSAGE---\n");
    buf.append(msg);
    buf.append("\n---BEGIN I2P SIGNATURE---\n");
    buf.append(sig.toBase64());
    buf.append("\n---END I2P SIGNATURE---");
    return buf.toString();
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) Signature(net.i2p.data.Signature) RouterAddress(net.i2p.data.router.RouterAddress) Date(java.util.Date)

Example 4 with RouterAddress

use of net.i2p.data.router.RouterAddress 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 5 with RouterAddress

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

the class ConfigNetHelper method getUdpIP.

/**
 * @return host or "unknown"
 */
public String getUdpIP() {
    String rv = _context.getProperty(UDPTransport.PROP_IP);
    if (rv != null)
        return rv;
    RouterAddress addr = _context.router().getRouterInfo().getTargetAddress("SSU");
    if (addr != null) {
        rv = addr.getHost();
        if (rv != null)
            return rv;
    }
    addr = _context.router().getRouterInfo().getTargetAddress("NTCP");
    if (addr != null) {
        rv = addr.getHost();
        if (rv != null)
            return rv;
    }
    return _t("unknown");
}
Also used : RouterAddress(net.i2p.data.router.RouterAddress)

Aggregations

RouterAddress (net.i2p.data.router.RouterAddress)42 RouterInfo (net.i2p.data.router.RouterInfo)17 Hash (net.i2p.data.Hash)11 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 OrderedProperties (net.i2p.util.OrderedProperties)6 InetAddress (java.net.InetAddress)5 Map (java.util.Map)5 RouterIdentity (net.i2p.data.router.RouterIdentity)5 UnknownHostException (java.net.UnknownHostException)4 HashMap (java.util.HashMap)4 DataFormatException (net.i2p.data.DataFormatException)4 ServerSocketChannel (java.nio.channels.ServerSocketChannel)3 Date (java.util.Date)3 Status (net.i2p.router.CommSystemFacade.Status)3 OutNetMessage (net.i2p.router.OutNetMessage)3 File (java.io.File)2 InetSocketAddress (java.net.InetSocketAddress)2 Properties (java.util.Properties)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2