Search in sources :

Example 1 with DhtPeerStats

use of i2p.bote.network.DhtPeerStats in project i2p.i2p-bote by i2p.

the class NetworkInfoFragment method setupKademliaPeers.

private void setupKademliaPeers() {
    DhtPeerStats dhtStats = I2PBote.getInstance().getDhtStats(new AndroidPeerStatsRenderer());
    if (dhtStats != null) {
        if (dhtStats.getData().size() == 0) {
            Segment n = new Segment("", 100);
            SegmentFormatter nf = new SegmentFormatter(getResources().getColor(android.R.color.darker_gray));
            setupSegmentFormatter(nf);
            mKademliaPie.addSeries(n, nf);
        } else {
            int reachable = 0;
            for (DhtPeerStatsRow row : dhtStats.getData()) {
                if (row.isReachable())
                    reachable += 1;
            }
            int unreachable = dhtStats.getData().size() - reachable;
            mKademliaPeers.setText("" + dhtStats.getData().size());
            if (reachable > 0) {
                Segment r = new Segment(getString(R.string.reachable), reachable);
                SegmentFormatter rf = new SegmentFormatter(getResources().getColor(R.color.green));
                setupSegmentFormatter(rf);
                mKademliaPie.addSeries(r, rf);
            }
            if (unreachable > 0) {
                Segment u = new Segment(getString(R.string.unreachable), dhtStats.getData().size() - reachable);
                SegmentFormatter uf = new SegmentFormatter(getResources().getColor(R.color.error_color));
                setupSegmentFormatter(uf);
                mKademliaPie.addSeries(u, uf);
            }
        }
    }
    mKademliaPie.getBorderPaint().setColor(Color.TRANSPARENT);
    mKademliaPie.getBackgroundPaint().setColor(Color.TRANSPARENT);
}
Also used : DhtPeerStats(i2p.bote.network.DhtPeerStats) SegmentFormatter(com.androidplot.pie.SegmentFormatter) DhtPeerStatsRow(i2p.bote.network.DhtPeerStatsRow) Segment(com.androidplot.pie.Segment)

Example 2 with DhtPeerStats

use of i2p.bote.network.DhtPeerStats in project i2p.i2p-bote by i2p.

the class PeerInfoTag method doTag.

@Override
public void doTag() {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {
        // Print DHT peer info
        DhtPeerStats dhtStats = I2PBote.getInstance().getDhtStats(new WebappPeerStatsRenderer());
        if (dhtStats == null)
            return;
        int numDhtPeers = dhtStats.getData().size();
        // Get a sorted list of relay peers
        RelayPeer[] relayPeers = I2PBote.getInstance().getRelayPeers().toArray(new RelayPeer[0]);
        Arrays.sort(relayPeers, new Comparator<RelayPeer>() {

            @Override
            public int compare(RelayPeer peer1, RelayPeer peer2) {
                return peer2.getReachability() - peer1.getReachability();
            }
        });
        // Print charts
        out.println("<div class=\"network-charts\">");
        out.println("<div class=\"chart\">");
        out.println("<img src=\"displayChart?filename=" + createDhtChart(dhtStats) + "\"/>");
        out.println("<div class=\"chart-text\">" + numDhtPeers + "</div>");
        out.println("</div>");
        out.println("<div class=\"chart\">");
        out.println("<img src=\"displayChart?filename=" + createRelayChart(relayPeers) + "\"/>");
        out.println("<div class=\"chart-text\">" + relayPeers.length + "</div>");
        out.println("</div>");
        out.println("</div>");
        out.println("<br>");
        out.println("<span class=\"subheading\">" + _t("Kademlia Peers:") + " " + numDhtPeers + "</span>");
        if (numDhtPeers > 0) {
            out.println("<table");
            // header
            out.println("<tr>");
            for (String columnHeader : dhtStats.getHeader()) out.println("<th>" + columnHeader + "</th>");
            out.println("</tr>");
            // data
            for (DhtPeerStatsRow row : dhtStats.getData()) {
                out.println("<tr>");
                for (String cellData : row.toStrings()) out.println("<td class=\"ellipsis\">" + cellData + "</td>");
                out.println("</tr>");
            }
            out.println("</table>");
        }
        out.println("<br/>");
        // Print relay peer info
        out.println("<span class=\"subheading\">" + _t("Relay Peers:") + " " + relayPeers.length + "</span>");
        if (relayPeers.length > 0) {
            out.println("<table");
            out.println("<tr>");
            out.println("<th>" + _t("Peer") + "</th>");
            out.println("<th>" + _t("I2P Destination") + "</th>");
            out.println("<th>" + _t("Reachability %") + "</th>");
            out.println("</tr>");
            int i = 1;
            for (RelayPeer peer : relayPeers) {
                out.println("<tr>");
                out.println("<td>" + i + "</td>");
                out.println("<td class=\"ellipsis\">" + Util.toBase32(peer) + "</td>");
                int reachability = peer.getReachability();
                out.println("<td>" + (reachability == 0 ? _t("Untested") : reachability) + "</td>");
                out.println("</tr>");
                i++;
            }
            out.println("</table>");
        }
        out.println("<br/>");
        // List banned peers
        Collection<BannedPeer> bannedPeers = I2PBote.getInstance().getBannedPeers();
        out.println("<span class=\"subheading\">" + _t("Banned Peers:") + " " + bannedPeers.size() + "</span>");
        if (bannedPeers.size() > 0) {
            out.println("<table>");
            out.println("<tr>");
            out.println("<th>" + _t("Peer") + "</th>");
            out.println("<th>" + _t("Destination Hash") + "</th>");
            out.println("<th>" + _t("Ban Reason") + "</th>");
            out.println("</tr>");
            int peerIndex = 1;
            for (BannedPeer peer : bannedPeers) {
                out.println("<tr>");
                out.println("<td>" + peerIndex++ + "</td>");
                out.println("<td class=\"ellipsis\">" + Util.toBase32(peer.getDestination()) + "</td>");
                out.println("<td>" + getBanReason(peer) + "</td>");
                out.println("</tr>");
            }
            out.println("</table>");
        }
    } catch (IOException e) {
        log.error("Can't write output to HTML page", e);
    }
}
Also used : DhtPeerStatsRow(i2p.bote.network.DhtPeerStatsRow) RelayPeer(i2p.bote.network.RelayPeer) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) BannedPeer(i2p.bote.network.BannedPeer) DhtPeerStats(i2p.bote.network.DhtPeerStats) PageContext(javax.servlet.jsp.PageContext)

Aggregations

DhtPeerStats (i2p.bote.network.DhtPeerStats)2 DhtPeerStatsRow (i2p.bote.network.DhtPeerStatsRow)2 Segment (com.androidplot.pie.Segment)1 SegmentFormatter (com.androidplot.pie.SegmentFormatter)1 BannedPeer (i2p.bote.network.BannedPeer)1 RelayPeer (i2p.bote.network.RelayPeer)1 IOException (java.io.IOException)1 JspWriter (javax.servlet.jsp.JspWriter)1 PageContext (javax.servlet.jsp.PageContext)1