forked from I2P_Developers/i2p.i2p
Console: Convert NetDbHelper to a FormHandler,
change SybilRenderer forms to POST, only collect RIs on required Sybil tabs
This commit is contained in:
@ -6,9 +6,14 @@ import java.util.Locale;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.SystemVersion;
|
||||
import net.i2p.router.web.HelperBase;
|
||||
import net.i2p.router.web.FormHandler;
|
||||
|
||||
public class NetDbHelper extends HelperBase {
|
||||
/**
|
||||
* /netdb
|
||||
* A FormHandler since 0.9.38.
|
||||
* Most output is generated in NetDbRenderer and SybilRender.
|
||||
*/
|
||||
public class NetDbHelper extends FormHandler {
|
||||
private String _routerPrefix;
|
||||
private String _version;
|
||||
private String _country;
|
||||
@ -20,6 +25,8 @@ public class NetDbHelper extends HelperBase {
|
||||
private boolean _debug;
|
||||
private boolean _graphical;
|
||||
private SigType _type;
|
||||
private String _newNonce;
|
||||
private boolean _postOK;
|
||||
|
||||
private static final int DEFAULT_LIMIT = SystemVersion.isARM() ? 250 : 500;
|
||||
private static final int DEFAULT_PAGE = 0;
|
||||
@ -194,6 +201,25 @@ public class NetDbHelper extends HelperBase {
|
||||
public void allowGraphical() {
|
||||
_graphical = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override to save it
|
||||
* @since 0.9.38
|
||||
*/
|
||||
@Override
|
||||
public String getNewNonce() {
|
||||
_newNonce = super.getNewNonce();
|
||||
return _newNonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Now we're a FormHandler
|
||||
* @since 0.9.38
|
||||
*/
|
||||
protected void processForm() {
|
||||
_postOK = "Run new analysis".equals(_action) ||
|
||||
"Review analysis".equals(_action);
|
||||
}
|
||||
|
||||
/**
|
||||
* storeWriter() must be called previously
|
||||
@ -205,19 +231,24 @@ public class NetDbHelper extends HelperBase {
|
||||
if (_routerPrefix != null || _version != null || _country != null ||
|
||||
_family != null || _caps != null || _ip != null || _sybil != null ||
|
||||
_port != 0 || _type != null || _mtu != null || _ipv6 != null ||
|
||||
_ssucaps != null || _transport != null || _cost != 0)
|
||||
_ssucaps != null || _transport != null || _cost != 0) {
|
||||
renderer.renderRouterInfoHTML(_out, _limit, _page,
|
||||
_routerPrefix, _version, _country,
|
||||
_family, _caps, _ip, _sybil, _port, _type,
|
||||
_mtu, _ipv6, _ssucaps, _transport, _cost);
|
||||
else if (_lease)
|
||||
} else if (_lease) {
|
||||
renderer.renderLeaseSetHTML(_out, _debug);
|
||||
else if (_full == 3)
|
||||
(new SybilRenderer(_context)).getNetDbSummary(_out, _mode, _date);
|
||||
else if (_full == 4)
|
||||
} else if (_full == 3) {
|
||||
if (_mode == 12 && !_postOK)
|
||||
_mode = 0;
|
||||
else if (_mode == 13 && !_postOK)
|
||||
_mode = 14;
|
||||
(new SybilRenderer(_context)).getNetDbSummary(_out, _newNonce, _mode, _date);
|
||||
} else if (_full == 4) {
|
||||
renderLookupForm();
|
||||
else
|
||||
} else {
|
||||
renderer.renderStatusHTML(_out, _limit, _page, _full);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
@ -292,6 +323,7 @@ public class NetDbHelper extends HelperBase {
|
||||
*/
|
||||
private void renderLookupForm() throws IOException {
|
||||
_out.write("<form action=\"/netdb\" method=\"POST\">\n" +
|
||||
"<input type=\"hidden\" name=\"nonce\" value=\"" + _newNonce + "\" >\n" +
|
||||
"<table id=\"netdblookup\"><tr><th colspan=\"3\">Network Database Search</th></tr>\n" +
|
||||
"<tr><td colspan=\"3\" class=\"subheading\"><b>Enter one search field <i>only</i>:</b></td></tr>\n" +
|
||||
"<tr><td>Capabilities:</td><td><input type=\"text\" name=\"caps\"></td><td>e.g. f or XOfR</td></tr>\n" +
|
||||
|
@ -78,8 +78,8 @@ public class SybilRenderer {
|
||||
* @param mode what tab to show
|
||||
* @param date only for mode = 12
|
||||
*/
|
||||
public String getNetDbSummary(Writer out, int mode, long date) throws IOException {
|
||||
renderRouterInfoHTML(out, mode, date);
|
||||
public String getNetDbSummary(Writer out, String nonce, int mode, long date) throws IOException {
|
||||
renderRouterInfoHTML(out, nonce, mode, date);
|
||||
return "";
|
||||
}
|
||||
|
||||
@ -125,21 +125,24 @@ public class SybilRenderer {
|
||||
* @param mode what tab to show
|
||||
* @param date only for mode = 12
|
||||
*/
|
||||
private void renderRouterInfoHTML(Writer out, int mode, long date) throws IOException {
|
||||
private void renderRouterInfoHTML(Writer out, String nonce, int mode, long date) throws IOException {
|
||||
Hash us = _context.routerHash();
|
||||
Analysis analysis = Analysis.getInstance(_context);
|
||||
List<RouterInfo> ris = analysis.getFloodfills(us);
|
||||
if (ris.isEmpty()) {
|
||||
out.write("<h3 class=\"sybils\">No known floodfills</h3>");
|
||||
return;
|
||||
List<RouterInfo> ris = null;
|
||||
if (mode != 0 && mode != 12 && mode != 13 && mode != 14) {
|
||||
ris = analysis.getFloodfills(us);
|
||||
if (ris.isEmpty()) {
|
||||
out.write("<h3 class=\"sybils\">No known floodfills</h3>");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder buf = new StringBuilder(4*1024);
|
||||
buf.append("<p id=\"sybilinfo\"><b>This is an experimental network database tool for debugging and analysis. Do not panic even if you see warnings below. " +
|
||||
"Possible \"threats\" are summarized at the bottom, however these are unlikely to be real threats. " +
|
||||
"Possible \"threats\" are summarized, however these are unlikely to be real threats. " +
|
||||
"If you see anything you would like to discuss with the devs, contact us on IRC #i2p-dev.</b></p>" +
|
||||
"<div id=\"sybilnav\"><ul><li><a href=\"netdb?f=3\">Review stored analysis</a>" +
|
||||
"</li><li><a href=\"netdb?f=3&m=13\">Run new analysis</a>" +
|
||||
"</li><li><a href=\"netdb?f=3&m=14\">Run new analysis</a>" +
|
||||
"</li><li><a href=\"netdb?f=3&m=1\">Floodfill Summary</a>" +
|
||||
"</li><li><a href=\"netdb?f=3&m=2\">Same Family</a>" +
|
||||
"</li><li><a href=\"netdb?f=3&m=3\">IP close to us</a>" +
|
||||
@ -154,11 +157,14 @@ public class SybilRenderer {
|
||||
"</li></ul></div>");
|
||||
writeBuf(out, buf);
|
||||
|
||||
double avgMinDist = analysis.getAvgMinDist(ris);
|
||||
double avgMinDist = 0;
|
||||
if (mode == 1 || mode == 8 || mode == 9 || mode == 10 || mode == 11) {
|
||||
avgMinDist = analysis.getAvgMinDist(ris);
|
||||
}
|
||||
Map<Hash, Points> points = new HashMap<Hash, Points>(64);
|
||||
|
||||
if (mode == 0) {
|
||||
renderOverview(out, buf, analysis);
|
||||
renderOverview(out, buf, nonce, analysis);
|
||||
} else if (mode == 1) {
|
||||
renderFFSummary(out, buf, ris, avgMinDist);
|
||||
} else if (mode == 2) {
|
||||
@ -182,6 +188,7 @@ public class SybilRenderer {
|
||||
} else if (mode == 11) {
|
||||
renderDestSummary(out, buf, analysis, avgMinDist, ris, points);
|
||||
} else if (mode == 12) {
|
||||
// load stored analysis
|
||||
PersistSybil ps = analysis.getPersister();
|
||||
try {
|
||||
points = ps.load(date);
|
||||
@ -195,6 +202,7 @@ public class SybilRenderer {
|
||||
renderThreatsHTML(out, buf, date, points);
|
||||
}
|
||||
} else if (mode == 13) {
|
||||
// run analysis and store it
|
||||
long now = _context.clock().now();
|
||||
points = analysis.backgroundAnalysis();
|
||||
if (!points.isEmpty()) {
|
||||
@ -206,6 +214,9 @@ public class SybilRenderer {
|
||||
}
|
||||
}
|
||||
renderThreatsHTML(out, buf, now, points);
|
||||
} else if (mode == 14) {
|
||||
// show form
|
||||
renderRunForm(out, buf, nonce);
|
||||
} else {
|
||||
out.write("Unknown mode " + mode);
|
||||
}
|
||||
@ -215,15 +226,16 @@ public class SybilRenderer {
|
||||
/**
|
||||
* @since 0.9.38
|
||||
*/
|
||||
private void renderOverview(Writer out, StringBuilder buf, Analysis analysis) throws IOException {
|
||||
private void renderOverview(Writer out, StringBuilder buf, String nonce, Analysis analysis) throws IOException {
|
||||
PersistSybil ps = analysis.getPersister();
|
||||
List<Long> dates = ps.load();
|
||||
if (dates.isEmpty()) {
|
||||
out.write("No stored analysis");
|
||||
} else {
|
||||
buf.append("<form action=\"netdb\" method=\"GET\">\n" +
|
||||
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
||||
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
||||
"<input type=\"hidden\" name=\"m\" value=\"12\">\n" +
|
||||
"<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n" +
|
||||
"Select stored analysis: " +
|
||||
"<select name=\"date\">\n");
|
||||
boolean first = true;
|
||||
@ -241,7 +253,20 @@ public class SybilRenderer {
|
||||
"<input type=\"submit\" name=\"action\" class=\"go\" value=\"Review analysis\" />" +
|
||||
"</form>\n");
|
||||
}
|
||||
buf.append("<br><a href=\"netdb?f=3&m=13\">Run new analysis</a>");
|
||||
writeBuf(out, buf);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @since 0.9.38
|
||||
*/
|
||||
private void renderRunForm(Writer out, StringBuilder buf, String nonce) throws IOException {
|
||||
buf.append("<form action=\"netdb\" method=\"POST\">\n" +
|
||||
"<input type=\"hidden\" name=\"f\" value=\"3\">\n" +
|
||||
"<input type=\"hidden\" name=\"m\" value=\"13\">\n" +
|
||||
"<input type=\"hidden\" name=\"nonce\" value=\"" + nonce + "\" >\n" +
|
||||
"<input type=\"submit\" name=\"action\" class=\"go\" value=\"Run new analysis\" />" +
|
||||
"</form>\n");
|
||||
writeBuf(out, buf);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user