Add Destination.toBase32()

This commit is contained in:
zzz
2014-06-23 20:06:03 +00:00
parent 69e56f8f6b
commit 8b1abc08db
11 changed files with 37 additions and 25 deletions

View File

@ -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 =

View File

@ -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

View File

@ -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() {

View File

@ -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;

View File

@ -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() {

View File

@ -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();
}

View File

@ -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 %>

View File

@ -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>

View File

@ -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>");

View File

@ -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

View File

@ -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: ");