forked from I2P_Developers/i2p.i2p
Add Destination.toBase32()
This commit is contained in:
@ -1247,11 +1247,10 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
|||||||
if(host.length() == 60 && host.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
|
if(host.length() == 60 && host.toLowerCase(Locale.US).endsWith(".b32.i2p")) {
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
Destination _dest = _context.namingService().lookup(host);
|
Destination dest = _context.namingService().lookup(host);
|
||||||
if(_dest == null) {
|
if (dest == null)
|
||||||
return "i2p";
|
return "i2p";
|
||||||
}
|
return dest.toBase32();
|
||||||
return Base32.encode(_dest.calculateHash().getData()) + ".b32.i2p";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String DEFAULT_JUMP_SERVERS =
|
public static final String DEFAULT_JUMP_SERVERS =
|
||||||
|
@ -30,7 +30,6 @@ import net.i2p.util.ByteCache;
|
|||||||
import net.i2p.util.EventDispatcher;
|
import net.i2p.util.EventDispatcher;
|
||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.data.Base32;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple extension to the I2PTunnelServer that filters the HTTP
|
* 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, 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());
|
addEntry(headers, DEST64_HEADER, socket.getPeerDestination().toBase64());
|
||||||
|
|
||||||
// Port-specific spoofhost
|
// Port-specific spoofhost
|
||||||
|
@ -10,7 +10,6 @@ import java.util.StringTokenizer;
|
|||||||
|
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
import net.i2p.client.streaming.I2PSocketAddress;
|
import net.i2p.client.streaming.I2PSocketAddress;
|
||||||
import net.i2p.data.Base32;
|
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.i2ptunnel.irc.DCCClientManager;
|
import net.i2p.i2ptunnel.irc.DCCClientManager;
|
||||||
@ -239,7 +238,7 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getB32Hostname() {
|
public String getB32Hostname() {
|
||||||
return Base32.encode(sockMgr.getSession().getMyDestination().calculateHash().getData()) + ".b32.i2p";
|
return sockMgr.getSession().getMyDestination().toBase32();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getLocalAddress() {
|
public byte[] getLocalAddress() {
|
||||||
|
@ -14,7 +14,6 @@ import net.i2p.client.I2PClient;
|
|||||||
import net.i2p.client.I2PClientFactory;
|
import net.i2p.client.I2PClientFactory;
|
||||||
import net.i2p.client.I2PSession;
|
import net.i2p.client.I2PSession;
|
||||||
import net.i2p.crypto.SigType;
|
import net.i2p.crypto.SigType;
|
||||||
import net.i2p.data.Base32;
|
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.i2ptunnel.socks.I2PSOCKSTunnel;
|
import net.i2p.i2ptunnel.socks.I2PSOCKSTunnel;
|
||||||
import net.i2p.util.FileUtil;
|
import net.i2p.util.FileUtil;
|
||||||
@ -156,7 +155,7 @@ public class TunnelController implements Logging {
|
|||||||
log("Private key created and saved in " + keyFile.getAbsolutePath());
|
log("Private key created and saved in " + keyFile.getAbsolutePath());
|
||||||
log("You should backup this file in a secure place.");
|
log("You should backup this file in a secure place.");
|
||||||
log("New destination: " + destStr);
|
log("New destination: " + destStr);
|
||||||
String b32 = Base32.encode(dest.calculateHash().getData()) + ".b32.i2p";
|
String b32 = dest.toBase32();
|
||||||
log("Base32: " + b32);
|
log("Base32: " + b32);
|
||||||
File backupDir = new SecureFile(I2PAppContext.getGlobalContext().getConfigDir(), KEY_BACKUP_DIR);
|
File backupDir = new SecureFile(I2PAppContext.getGlobalContext().getConfigDir(), KEY_BACKUP_DIR);
|
||||||
if (backupDir.isDirectory() || backupDir.mkdir()) {
|
if (backupDir.isDirectory() || backupDir.mkdir()) {
|
||||||
@ -633,6 +632,9 @@ public class TunnelController implements Logging {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return "{52 chars}.b32.i2p" or null
|
||||||
|
*/
|
||||||
public String getMyDestHashBase32() {
|
public String getMyDestHashBase32() {
|
||||||
if (_tunnel != null) {
|
if (_tunnel != null) {
|
||||||
List<I2PSession> sessions = _tunnel.getSessions();
|
List<I2PSession> sessions = _tunnel.getSessions();
|
||||||
@ -640,7 +642,7 @@ public class TunnelController implements Logging {
|
|||||||
I2PSession session = sessions.get(i);
|
I2PSession session = sessions.get(i);
|
||||||
Destination dest = session.getMyDestination();
|
Destination dest = session.getMyDestination();
|
||||||
if (dest != null)
|
if (dest != null)
|
||||||
return Base32.encode(dest.calculateHash().getData());
|
return dest.toBase32();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.i2p.i2ptunnel.socks;
|
package net.i2p.i2ptunnel.socks;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.data.Base32;
|
|
||||||
import net.i2p.data.Destination;
|
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[] 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,
|
* Make a dummy header from a dest,
|
||||||
@ -52,11 +51,11 @@ public class SOCKSHeader {
|
|||||||
* Unused for now.
|
* Unused for now.
|
||||||
*/
|
*/
|
||||||
public SOCKSHeader(Destination dest) {
|
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);
|
System.arraycopy(this.header, 0, beg, 0, beg.length);
|
||||||
String b32 = Base32.encode(dest.calculateHash().getData());
|
String b32 = dest.toBase32();
|
||||||
System.arraycopy(this.header, beg.length, b32.getBytes(), 0, 52);
|
System.arraycopy(this.header, beg.length, b32.getBytes(), 0, 60);
|
||||||
System.arraycopy(this.header, beg.length + 52, end, 0, end.length);
|
System.arraycopy(this.header, beg.length + 60, end, 0, end.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
|
@ -25,7 +25,6 @@ import net.i2p.I2PAppContext;
|
|||||||
import net.i2p.app.ClientAppManager;
|
import net.i2p.app.ClientAppManager;
|
||||||
import net.i2p.app.Outproxy;
|
import net.i2p.app.Outproxy;
|
||||||
import net.i2p.client.I2PClient;
|
import net.i2p.client.I2PClient;
|
||||||
import net.i2p.data.Base32;
|
|
||||||
import net.i2p.data.Certificate;
|
import net.i2p.data.Certificate;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.data.PrivateKeyFile;
|
import net.i2p.data.PrivateKeyFile;
|
||||||
@ -649,6 +648,9 @@ public class IndexBean {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return "{52 chars}.b32.i2p" or ""
|
||||||
|
*/
|
||||||
public String getDestHashBase32(int tunnel) {
|
public String getDestHashBase32(int tunnel) {
|
||||||
TunnelController tun = getController(tunnel);
|
TunnelController tun = getController(tunnel);
|
||||||
if (tun != null) {
|
if (tun != null) {
|
||||||
@ -1127,7 +1129,7 @@ public class IndexBean {
|
|||||||
return "Modification failed: " + e;
|
return "Modification failed: " + e;
|
||||||
}
|
}
|
||||||
return "Destination modified - " +
|
return "Destination modified - " +
|
||||||
"New Base32 is " + Base32.encode(newdest.calculateHash().getData()) + ".b32.i2p " +
|
"New Base32 is " + newdest.toBase32() +
|
||||||
"New Destination is " + newdest.toBase64();
|
"New Destination is " + newdest.toBase64();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +440,7 @@ input.default { width: 1px; height: 1px; visibility: hidden; }
|
|||||||
</div>
|
</div>
|
||||||
<div id="destinationField" class="rowItem">
|
<div id="destinationField" class="rowItem">
|
||||||
<label><%=intl._("Local Base 32")%>:</label>
|
<label><%=intl._("Local Base 32")%>:</label>
|
||||||
<%=editBean.getDestHashBase32(curTunnel)%>.b32.i2p
|
<%=editBean.getDestHashBase32(curTunnel)%>
|
||||||
</div>
|
</div>
|
||||||
<% } // if destb64 %>
|
<% } // if destb64 %>
|
||||||
|
|
||||||
|
@ -134,10 +134,10 @@
|
|||||||
<%
|
<%
|
||||||
if (("httpserver".equals(indexBean.getInternalType(curServer)) || ("httpbidirserver".equals(indexBean.getInternalType(curServer)))) && indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) {
|
if (("httpserver".equals(indexBean.getInternalType(curServer)) || ("httpbidirserver".equals(indexBean.getInternalType(curServer)))) && indexBean.getTunnelStatus(curServer) == IndexBean.RUNNING) {
|
||||||
%><label><%=intl._("Preview")%>:</label>
|
%><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) {
|
} 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 {
|
} else {
|
||||||
%><span class="comment"><%=intl._("No Preview")%></span>
|
%><span class="comment"><%=intl._("No Preview")%></span>
|
||||||
|
@ -24,7 +24,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import net.i2p.data.Base32;
|
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.data.Hash;
|
import net.i2p.data.Hash;
|
||||||
@ -172,7 +171,7 @@ public class NetDbRenderer {
|
|||||||
median = dist;
|
median = dist;
|
||||||
}
|
}
|
||||||
buf.append(" Dist: <b>").append(fmt.format(biLog2(dist))).append("</b><br>");
|
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("Sig type: ").append(dest.getSigningPublicKey().getType()).append("<br>");
|
||||||
buf.append("Routing Key: ").append(ls.getRoutingKey().toBase64());
|
buf.append("Routing Key: ").append(ls.getRoutingKey().toBase64());
|
||||||
buf.append("<br>");
|
buf.append("<br>");
|
||||||
|
@ -172,6 +172,19 @@ public class Destination extends KeysAndCert {
|
|||||||
return _cachedB64;
|
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.
|
* Clear the cache.
|
||||||
* @since 0.9.9
|
* @since 0.9.9
|
||||||
|
@ -427,7 +427,7 @@ public class PrivateKeyFile {
|
|||||||
s.append("Dest: ");
|
s.append("Dest: ");
|
||||||
s.append(this.dest != null ? this.dest.toBase64() : "null");
|
s.append(this.dest != null ? this.dest.toBase64() : "null");
|
||||||
s.append("\nB32: ");
|
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("\nContains: ");
|
||||||
s.append(this.dest);
|
s.append(this.dest);
|
||||||
s.append("\nPrivate Key: ");
|
s.append("\nPrivate Key: ");
|
||||||
|
Reference in New Issue
Block a user