diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 27077c320e26dda80b77451f947d9e6184aa41d5..625ae863aa2f20afb509c53b76580f4fd737746a 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -1247,11 +1247,10 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn if(host.length() == 60 && host.toLowerCase(Locale.US).endsWith(".b32.i2p")) { return host; } - Destination _dest = _context.namingService().lookup(host); - if(_dest == null) { + Destination dest = _context.namingService().lookup(host); + if (dest == null) return "i2p"; - } - return Base32.encode(_dest.calculateHash().getData()) + ".b32.i2p"; + return dest.toBase32(); } public static final String DEFAULT_JUMP_SERVERS = diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index c199b50752dedfc84541639398e7c34ee01f4e87..128b1565d3d032bbe6957156a7ed53045bc780ea 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -30,7 +30,6 @@ import net.i2p.util.ByteCache; import net.i2p.util.EventDispatcher; import net.i2p.util.I2PAppThread; import net.i2p.util.Log; -import net.i2p.data.Base32; /** * Simple extension to the I2PTunnelServer that filters the HTTP @@ -249,7 +248,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { } addEntry(headers, HASH_HEADER, peerHash.toBase64()); - addEntry(headers, DEST32_HEADER, Base32.encode(peerHash.getData()) + ".b32.i2p"); + addEntry(headers, DEST32_HEADER, socket.getPeerDestination().toBase32()); addEntry(headers, DEST64_HEADER, socket.getPeerDestination().toBase64()); // Port-specific spoofhost diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java index c74dad2666039b8ba375a5c3478acf77695dbd23..3915ae68850bbec3a02fee007d3ce7b4290ad707 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java @@ -10,7 +10,6 @@ import java.util.StringTokenizer; import net.i2p.client.streaming.I2PSocket; import net.i2p.client.streaming.I2PSocketAddress; -import net.i2p.data.Base32; import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.i2ptunnel.irc.DCCClientManager; @@ -239,7 +238,7 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase { } public String getB32Hostname() { - return Base32.encode(sockMgr.getSession().getMyDestination().calculateHash().getData()) + ".b32.i2p"; + return sockMgr.getSession().getMyDestination().toBase32(); } public byte[] getLocalAddress() { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java index 8488c1e5aa66ea7244bd2a515234b63b1c7b14d8..96fab6213b945d43f3543016472f4fff6fbc4eec 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java @@ -14,7 +14,6 @@ import net.i2p.client.I2PClient; import net.i2p.client.I2PClientFactory; import net.i2p.client.I2PSession; import net.i2p.crypto.SigType; -import net.i2p.data.Base32; import net.i2p.data.Destination; import net.i2p.i2ptunnel.socks.I2PSOCKSTunnel; import net.i2p.util.FileUtil; @@ -156,7 +155,7 @@ public class TunnelController implements Logging { log("Private key created and saved in " + keyFile.getAbsolutePath()); log("You should backup this file in a secure place."); log("New destination: " + destStr); - String b32 = Base32.encode(dest.calculateHash().getData()) + ".b32.i2p"; + String b32 = dest.toBase32(); log("Base32: " + b32); File backupDir = new SecureFile(I2PAppContext.getGlobalContext().getConfigDir(), KEY_BACKUP_DIR); if (backupDir.isDirectory() || backupDir.mkdir()) { @@ -633,6 +632,9 @@ public class TunnelController implements Logging { return null; } + /** + * @return "{52 chars}.b32.i2p" or null + */ public String getMyDestHashBase32() { if (_tunnel != null) { List<I2PSession> sessions = _tunnel.getSessions(); @@ -640,7 +642,7 @@ public class TunnelController implements Logging { I2PSession session = sessions.get(i); Destination dest = session.getMyDestination(); if (dest != null) - return Base32.encode(dest.calculateHash().getData()); + return dest.toBase32(); } } return null; diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSHeader.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSHeader.java index f2b35a34db1440f5c67fd0fc3a664774e42de95f..e2e7edc72978acc66c8adb9aec14893a05caa1e1 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSHeader.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSHeader.java @@ -1,7 +1,6 @@ package net.i2p.i2ptunnel.socks; import net.i2p.I2PAppContext; -import net.i2p.data.Base32; import net.i2p.data.Destination; /** @@ -44,7 +43,7 @@ public class SOCKSHeader { } private static final byte[] beg = {0,0,0,3,60}; - private static final byte[] end = {'.','b','3','2','.','i','2','p',0,0}; + private static final byte[] end = {0,0}; /** * Make a dummy header from a dest, @@ -52,11 +51,11 @@ public class SOCKSHeader { * Unused for now. */ public SOCKSHeader(Destination dest) { - this.header = new byte[beg.length + 52 + end.length]; + this.header = new byte[beg.length + 60 + end.length]; System.arraycopy(this.header, 0, beg, 0, beg.length); - String b32 = Base32.encode(dest.calculateHash().getData()); - System.arraycopy(this.header, beg.length, b32.getBytes(), 0, 52); - System.arraycopy(this.header, beg.length + 52, end, 0, end.length); + String b32 = dest.toBase32(); + System.arraycopy(this.header, beg.length, b32.getBytes(), 0, 60); + System.arraycopy(this.header, beg.length + 60, end, 0, end.length); } public String getHost() { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java index 698c3cd427b0519a7e395888b05254640a123971..fc5ca687b70af7efa8447264bd47aaa4ebb1c5fb 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/web/IndexBean.java @@ -25,7 +25,6 @@ import net.i2p.I2PAppContext; import net.i2p.app.ClientAppManager; import net.i2p.app.Outproxy; import net.i2p.client.I2PClient; -import net.i2p.data.Base32; import net.i2p.data.Certificate; import net.i2p.data.Destination; import net.i2p.data.PrivateKeyFile; @@ -649,6 +648,9 @@ public class IndexBean { return ""; } + /** + * @return "{52 chars}.b32.i2p" or "" + */ public String getDestHashBase32(int tunnel) { TunnelController tun = getController(tunnel); if (tun != null) { @@ -1127,7 +1129,7 @@ public class IndexBean { return "Modification failed: " + e; } return "Destination modified - " + - "New Base32 is " + Base32.encode(newdest.calculateHash().getData()) + ".b32.i2p " + + "New Base32 is " + newdest.toBase32() + "New Destination is " + newdest.toBase64(); } diff --git a/apps/i2ptunnel/jsp/editClient.jsp b/apps/i2ptunnel/jsp/editClient.jsp index 1762da29ac678082d86b3558ea53342268e3f9bf..6ac65d76f20b38d43177a170b1188ecaacde2cd9 100644 --- a/apps/i2ptunnel/jsp/editClient.jsp +++ b/apps/i2ptunnel/jsp/editClient.jsp @@ -440,7 +440,7 @@ input.default { width: 1px; height: 1px; visibility: hidden; } </div> <div id="destinationField" class="rowItem"> <label><%=intl._("Local Base 32")%>:</label> - <%=editBean.getDestHashBase32(curTunnel)%>.b32.i2p + <%=editBean.getDestHashBase32(curTunnel)%> </div> <% } // if destb64 %> diff --git a/apps/i2ptunnel/jsp/index.jsp b/apps/i2ptunnel/jsp/index.jsp index 4f59fde0a7cf67123ab2279b85db8ee3e010667b..5f7140a21d8f4f77cf3e16871e7c8695aa8f2e7d 100644 --- a/apps/i2ptunnel/jsp/index.jsp +++ b/apps/i2ptunnel/jsp/index.jsp @@ -134,10 +134,10 @@ <% if (("httpserver".equals(indexBean.getInternalType(curServer)) || ("httpbidirserver".equals(indexBean.getInternalType(curServer)))) && indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) { %><label><%=intl._("Preview")%>:</label> - <a class="control" title="Test HTTP server through I2P" href="http://<%=indexBean.getDestHashBase32(curServer)%>.b32.i2p" target="_top"><%=intl._("Preview")%></a> + <a class="control" title="Test HTTP server through I2P" href="http://<%=indexBean.getDestHashBase32(curServer)%>" target="_top"><%=intl._("Preview")%></a> <% } else if (indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) { - %><span class="text"><%=intl._("Base32 Address")%>:<br /><%=indexBean.getDestHashBase32(curServer)%>.b32.i2p</span> + %><span class="text"><%=intl._("Base32 Address")%>:<br /><%=indexBean.getDestHashBase32(curServer)%></span> <% } else { %><span class="comment"><%=intl._("No Preview")%></span> diff --git a/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java index e2b480ef54094ed37ecff3da9acac6c0ce77fed0..9fae3ab935a7bedce85f1dc42224368013084e36 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/NetDbRenderer.java @@ -24,7 +24,6 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; -import net.i2p.data.Base32; import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.data.Hash; @@ -172,7 +171,7 @@ public class NetDbRenderer { median = dist; } buf.append(" Dist: <b>").append(fmt.format(biLog2(dist))).append("</b><br>"); - buf.append(Base32.encode(key.getData())).append(".b32.i2p<br>"); + buf.append(dest.toBase32()).append("<br>"); buf.append("Sig type: ").append(dest.getSigningPublicKey().getType()).append("<br>"); buf.append("Routing Key: ").append(ls.getRoutingKey().toBase64()); buf.append("<br>"); diff --git a/core/java/src/net/i2p/data/Destination.java b/core/java/src/net/i2p/data/Destination.java index 491e738f871fb3892d5998bd2d426eeb2e859d27..07bf1ad6ce706ae86be020fa6d5f280a190232a0 100644 --- a/core/java/src/net/i2p/data/Destination.java +++ b/core/java/src/net/i2p/data/Destination.java @@ -172,6 +172,19 @@ public class Destination extends KeysAndCert { return _cachedB64; } + /** + * For convenience. + * @return "{52 chars}.b32.i2p" or null if fields not set. + * @since 0.9.14 + */ + public String toBase32() { + try { + return Base32.encode(getHash().getData()) + ".b32.i2p"; + } catch (IllegalStateException ise) { + return null; + } + } + /** * Clear the cache. * @since 0.9.9 diff --git a/core/java/src/net/i2p/data/PrivateKeyFile.java b/core/java/src/net/i2p/data/PrivateKeyFile.java index 6d5eb403b317770bd9b514f260eeb1141f24dd3f..e1cdb4b76184e4c5912b24d149060d18fd2191cf 100644 --- a/core/java/src/net/i2p/data/PrivateKeyFile.java +++ b/core/java/src/net/i2p/data/PrivateKeyFile.java @@ -427,7 +427,7 @@ public class PrivateKeyFile { s.append("Dest: "); s.append(this.dest != null ? this.dest.toBase64() : "null"); s.append("\nB32: "); - s.append(this.dest != null ? Base32.encode(this.dest.calculateHash().getData()) + ".b32.i2p" : "null"); + s.append(this.dest != null ? this.dest.toBase32() : "null"); s.append("\nContains: "); s.append(this.dest); s.append("\nPrivate Key: ");