use of i2p.bote.network.DhtPeerStatsRow 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);
}
}
use of i2p.bote.network.DhtPeerStatsRow in project i2p.i2p-bote by i2p.
the class PeerInfoTag method createDhtChart.
private String createDhtChart(DhtPeerStats dhtStats) throws IOException {
RingPlot plot;
int numDhtPeers = dhtStats.getData().size();
if (numDhtPeers == 0) {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("", 100);
plot = new RingPlot(dataset);
plot.setSectionPaint("", Color.gray);
} else {
int reachable = 0;
for (DhtPeerStatsRow row : dhtStats.getData()) {
if (row.isReachable())
reachable += 1;
}
int unreachable = numDhtPeers - reachable;
DefaultPieDataset dataset = new DefaultPieDataset();
if (reachable > 0)
dataset.setValue(_t("Reachable"), reachable);
if (unreachable > 0)
dataset.setValue(_t("Unreachable"), unreachable);
plot = new RingPlot(dataset);
plot.setSectionPaint(_t("Reachable"), Color.green);
plot.setSectionPaint(_t("Unreachable"), Color.red);
}
plot.setLabelGenerator(null);
plot.setShadowGenerator(null);
JFreeChart dhtChart = new JFreeChart(_t("Kademlia Peers:"), JFreeChart.DEFAULT_TITLE_FONT, plot, numDhtPeers == 0 ? false : true);
return ServletUtilities.saveChartAsPNG(dhtChart, 400, 300, null);
}
use of i2p.bote.network.DhtPeerStatsRow 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);
}
Aggregations