Search in sources :

Example 1 with BannedPeer

use of i2p.bote.network.BannedPeer 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

BannedPeer (i2p.bote.network.BannedPeer)1 DhtPeerStats (i2p.bote.network.DhtPeerStats)1 DhtPeerStatsRow (i2p.bote.network.DhtPeerStatsRow)1 RelayPeer (i2p.bote.network.RelayPeer)1 IOException (java.io.IOException)1 JspWriter (javax.servlet.jsp.JspWriter)1 PageContext (javax.servlet.jsp.PageContext)1