forked from I2P_Developers/i2p.i2p
Console: Support remote lookup of full router hash from search form
This commit is contained in:
@ -28,6 +28,7 @@ import java.util.TreeSet;
|
||||
|
||||
import net.i2p.crypto.EncType;
|
||||
import net.i2p.crypto.SigType;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.DatabaseEntry;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.data.Destination;
|
||||
@ -38,6 +39,7 @@ import net.i2p.data.LeaseSet2;
|
||||
import net.i2p.data.PublicKey;
|
||||
import net.i2p.data.router.RouterAddress;
|
||||
import net.i2p.data.router.RouterInfo;
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
import net.i2p.router.util.HashDistance; // debug
|
||||
@ -113,6 +115,38 @@ class NetDbRenderer {
|
||||
.append(_t("Never reveal your router identity to anyone, as it is uniquely linked to your IP address in the network database."))
|
||||
.append("</td></tr></table>");
|
||||
renderRouterInfo(buf, _context.router().getRouterInfo(), true, true);
|
||||
} else if (routerPrefix != null && routerPrefix.length() >= 44) {
|
||||
// easy way, full hash
|
||||
byte[] h = Base64.decode(routerPrefix);
|
||||
if (h != null && h.length == Hash.HASH_LENGTH) {
|
||||
Hash hash = new Hash(h);
|
||||
RouterInfo ri = _context.netDb().lookupRouterInfoLocally(hash);
|
||||
if (ri == null) {
|
||||
// remote lookup
|
||||
LookupWaiter lw = new LookupWaiter();
|
||||
_context.netDb().lookupRouterInfo(hash, lw, lw, 8*1000);
|
||||
// just wait right here in the middle of the rendering, sure
|
||||
synchronized(lw) {
|
||||
try { lw.wait(9*1000); } catch (InterruptedException ie) {}
|
||||
}
|
||||
ri = _context.netDb().lookupRouterInfoLocally(hash);
|
||||
}
|
||||
if (ri != null) {
|
||||
renderRouterInfo(buf, ri, false, true);
|
||||
} else {
|
||||
buf.append("<div class=\"netdbnotfound\">");
|
||||
buf.append(_t("Router")).append(' ');
|
||||
if (routerPrefix != null)
|
||||
buf.append(routerPrefix);
|
||||
buf.append(' ').append(_t("not found in network database"));
|
||||
buf.append("</div>");
|
||||
}
|
||||
} else {
|
||||
buf.append("<div class=\"netdbnotfound\">");
|
||||
buf.append("Bad Base64 router hash").append(' ');
|
||||
buf.append(DataHelper.escapeHTML(routerPrefix));
|
||||
buf.append("</div>");
|
||||
}
|
||||
} else {
|
||||
StringBuilder ubuf = new StringBuilder();
|
||||
if (routerPrefix != null)
|
||||
@ -369,6 +403,19 @@ class NetDbRenderer {
|
||||
SybilRenderer.renderSybilHTML(out, _context, sybils, sybil);
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.48
|
||||
*/
|
||||
private class LookupWaiter extends JobImpl {
|
||||
public LookupWaiter() { super(_context); }
|
||||
public void runJob() {
|
||||
synchronized(this) {
|
||||
notifyAll();
|
||||
}
|
||||
}
|
||||
public String getName() { return "Console netdb lookup"; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Special handling for 'O' cap
|
||||
* @param caps non-null
|
||||
|
Reference in New Issue
Block a user