* I2PTunnel: Deprecate destFromName()
This commit is contained in:
@ -1573,6 +1573,7 @@ public class I2PTunnel implements Logging, EventDispatcher {
|
|||||||
*
|
*
|
||||||
* Since file:<filename> isn't really used, this method is deprecated,
|
* Since file:<filename> isn't really used, this method is deprecated,
|
||||||
* just call context.namingService.lookup() directly.
|
* just call context.namingService.lookup() directly.
|
||||||
|
* @deprecated Don't use i2ptunnel for lookup! Use I2PAppContext.getGlobalContext().namingService().lookup(name) from i2p.jar
|
||||||
*/
|
*/
|
||||||
public static Destination destFromName(String name) throws DataFormatException {
|
public static Destination destFromName(String name) throws DataFormatException {
|
||||||
|
|
||||||
|
@ -42,15 +42,11 @@ public class I2PTunnelClient extends I2PTunnelClientBase {
|
|||||||
dests = new ArrayList(1);
|
dests = new ArrayList(1);
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
String destination = tok.nextToken();
|
String destination = tok.nextToken();
|
||||||
try {
|
Destination destN = _context.namingService().lookup(destination);
|
||||||
Destination destN = I2PTunnel.destFromName(destination);
|
if (destN == null)
|
||||||
if (destN == null)
|
l.log("Could not resolve " + destination);
|
||||||
l.log("Could not resolve " + destination);
|
else
|
||||||
else
|
dests.add(destN);
|
||||||
dests.add(destN);
|
|
||||||
} catch (DataFormatException dfe) {
|
|
||||||
l.log("Bad format parsing \"" + destination + "\"");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dests.isEmpty()) {
|
if (dests.isEmpty()) {
|
||||||
|
@ -278,7 +278,7 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Destination clientDest = I2PTunnel.destFromName(destination);
|
Destination clientDest = _context.namingService().lookup(destination);
|
||||||
if (clientDest == null) {
|
if (clientDest == null) {
|
||||||
String str;
|
String str;
|
||||||
byte[] header;
|
byte[] header;
|
||||||
|
@ -28,7 +28,6 @@ import net.i2p.client.streaming.I2PSocketManager;
|
|||||||
import net.i2p.client.streaming.I2PSocketOptions;
|
import net.i2p.client.streaming.I2PSocketOptions;
|
||||||
import net.i2p.data.Base32;
|
import net.i2p.data.Base32;
|
||||||
import net.i2p.data.Base64;
|
import net.i2p.data.Base64;
|
||||||
import net.i2p.data.DataFormatException;
|
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.util.EventDispatcher;
|
import net.i2p.util.EventDispatcher;
|
||||||
@ -431,11 +430,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
|||||||
// Host resolvable from database, verify addresshelper key
|
// Host resolvable from database, verify addresshelper key
|
||||||
// Silently bypass correct keys, otherwise alert
|
// Silently bypass correct keys, otherwise alert
|
||||||
String destB64 = null;
|
String destB64 = null;
|
||||||
try {
|
Destination _dest = _context.namingService().lookup(host);
|
||||||
Destination _dest = I2PTunnel.destFromName(host);
|
if (_dest != null)
|
||||||
if (_dest != null)
|
destB64 = _dest.toBase64();
|
||||||
destB64 = _dest.toBase64();
|
|
||||||
} catch (DataFormatException dfe) {}
|
|
||||||
if (destB64 != null && !destB64.equals(ahelperKey))
|
if (destB64 != null && !destB64.equals(ahelperKey))
|
||||||
{
|
{
|
||||||
// Conflict: handle when URL reconstruction done
|
// Conflict: handle when URL reconstruction done
|
||||||
@ -721,7 +718,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
|||||||
if ("i2p".equals(host))
|
if ("i2p".equals(host))
|
||||||
clientDest = null;
|
clientDest = null;
|
||||||
else
|
else
|
||||||
clientDest = I2PTunnel.destFromName(destination);
|
clientDest = _context.namingService().lookup(destination);
|
||||||
|
|
||||||
if (clientDest == null) {
|
if (clientDest == null) {
|
||||||
//l.log("Could not resolve " + destination + ".");
|
//l.log("Could not resolve " + destination + ".");
|
||||||
@ -814,17 +811,13 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
|||||||
* @return b32hash.b32.i2p, or "i2p" on lookup failure.
|
* @return b32hash.b32.i2p, or "i2p" on lookup failure.
|
||||||
* Prior to 0.7.12, returned b64 key
|
* Prior to 0.7.12, returned b64 key
|
||||||
*/
|
*/
|
||||||
private final static String getHostName(String host) {
|
private final String getHostName(String host) {
|
||||||
if (host == null) return null;
|
if (host == null) return null;
|
||||||
if (host.length() == 60 && host.toLowerCase().endsWith(".b32.i2p"))
|
if (host.length() == 60 && host.toLowerCase().endsWith(".b32.i2p"))
|
||||||
return host;
|
return host;
|
||||||
try {
|
Destination dest = _context.namingService().lookup(host);
|
||||||
Destination dest = I2PTunnel.destFromName(host);
|
if (dest == null) return "i2p";
|
||||||
if (dest == null) return "i2p";
|
return Base32.encode(dest.calculateHash().getData()) + ".b32.i2p";
|
||||||
return Base32.encode(dest.calculateHash().getData()) + ".b32.i2p";
|
|
||||||
} catch (DataFormatException dfe) {
|
|
||||||
return "i2p";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -947,12 +940,8 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
|||||||
// Skip jump servers we don't know
|
// Skip jump servers we don't know
|
||||||
String jumphost = jurl.substring(7); // "http://"
|
String jumphost = jurl.substring(7); // "http://"
|
||||||
jumphost = jumphost.substring(0, jumphost.indexOf('/'));
|
jumphost = jumphost.substring(0, jumphost.indexOf('/'));
|
||||||
try {
|
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(jumphost);
|
||||||
Destination dest = I2PTunnel.destFromName(jumphost);
|
if (dest == null) continue;
|
||||||
if (dest == null) continue;
|
|
||||||
} catch (DataFormatException dfe) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.write("<br><a href=\"".getBytes());
|
out.write("<br><a href=\"".getBytes());
|
||||||
out.write(jurl.getBytes());
|
out.write(jurl.getBytes());
|
||||||
@ -1014,7 +1003,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn
|
|||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
try {
|
try {
|
||||||
Destination d = I2PTunnel.destFromName(host);
|
Destination d = _context.namingService().lookup(host);
|
||||||
if (d == null) return false;
|
if (d == null) return false;
|
||||||
} catch (DataFormatException dfe) {
|
} catch (DataFormatException dfe) {
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import java.util.List;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import net.i2p.client.streaming.I2PSocket;
|
import net.i2p.client.streaming.I2PSocket;
|
||||||
import net.i2p.data.DataFormatException;
|
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.util.EventDispatcher;
|
import net.i2p.util.EventDispatcher;
|
||||||
import net.i2p.util.I2PAppThread;
|
import net.i2p.util.I2PAppThread;
|
||||||
@ -52,15 +51,11 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable
|
|||||||
dests = new ArrayList(2);
|
dests = new ArrayList(2);
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
String destination = tok.nextToken();
|
String destination = tok.nextToken();
|
||||||
try {
|
Destination destN = _context.namingService().lookup(destination);
|
||||||
Destination destN = I2PTunnel.destFromName(destination);
|
if (destN == null)
|
||||||
if (destN == null)
|
l.log("Could not resolve " + destination);
|
||||||
l.log("Could not resolve " + destination);
|
else
|
||||||
else
|
dests.add(destN);
|
||||||
dests.add(destN);
|
|
||||||
} catch (DataFormatException dfe) {
|
|
||||||
l.log("Bad format parsing \"" + destination + "\"");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dests.isEmpty()) {
|
if (dests.isEmpty()) {
|
||||||
|
@ -10,6 +10,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.I2PException;
|
import net.i2p.I2PException;
|
||||||
import net.i2p.client.streaming.I2PSocketManager;
|
import net.i2p.client.streaming.I2PSocketManager;
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
@ -200,7 +201,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Destination dest = I2PTunnel.destFromName(destination);
|
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(destination);
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
synchronized (lock) { // Logger is not thread safe
|
synchronized (lock) { // Logger is not thread safe
|
||||||
l.log("Unresolvable: " + destination + "");
|
l.log("Unresolvable: " + destination + "");
|
||||||
|
@ -204,7 +204,7 @@ public class SOCKS4aServer extends SOCKSServer {
|
|||||||
// Let's not due a new Dest for every request, huh?
|
// Let's not due a new Dest for every request, huh?
|
||||||
//I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
//I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
||||||
//destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
//destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
||||||
destSock = t.createI2PSocket(I2PTunnel.destFromName(connHostName));
|
destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName));
|
||||||
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
|
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
|
||||||
String err = "No localhost accesses allowed through the Socks Proxy";
|
String err = "No localhost accesses allowed through the Socks Proxy";
|
||||||
_log.error(err);
|
_log.error(err);
|
||||||
@ -237,7 +237,7 @@ public class SOCKS4aServer extends SOCKSServer {
|
|||||||
_log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
|
_log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
|
||||||
// this isn't going to work, these need to be socks outproxies so we need
|
// this isn't going to work, these need to be socks outproxies so we need
|
||||||
// to do a socks session to them?
|
// to do a socks session to them?
|
||||||
destSock = t.createI2PSocket(I2PTunnel.destFromName(proxy));
|
destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy));
|
||||||
}
|
}
|
||||||
confirmConnection();
|
confirmConnection();
|
||||||
_log.debug("connection confirmed - exchanging data...");
|
_log.debug("connection confirmed - exchanging data...");
|
||||||
|
@ -360,14 +360,14 @@ public class SOCKS5Server extends SOCKSServer {
|
|||||||
// Let's not due a new Dest for every request, huh?
|
// Let's not due a new Dest for every request, huh?
|
||||||
//I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
//I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
||||||
//destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
//destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
||||||
Destination dest = I2PTunnel.destFromName(connHostName);
|
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(connHostName);
|
||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
try {
|
try {
|
||||||
sendRequestReply(Reply.HOST_UNREACHABLE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
|
sendRequestReply(Reply.HOST_UNREACHABLE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out);
|
||||||
} catch (IOException ioe) {}
|
} catch (IOException ioe) {}
|
||||||
throw new SOCKSException("Host not found");
|
throw new SOCKSException("Host not found");
|
||||||
}
|
}
|
||||||
destSock = t.createI2PSocket(I2PTunnel.destFromName(connHostName));
|
destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(connHostName));
|
||||||
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
|
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
|
||||||
String err = "No localhost accesses allowed through the Socks Proxy";
|
String err = "No localhost accesses allowed through the Socks Proxy";
|
||||||
_log.error(err);
|
_log.error(err);
|
||||||
@ -455,10 +455,10 @@ public class SOCKS5Server extends SOCKSServer {
|
|||||||
Properties overrides = new Properties();
|
Properties overrides = new Properties();
|
||||||
overrides.setProperty("option.i2p.streaming.connectDelay", "1000");
|
overrides.setProperty("option.i2p.streaming.connectDelay", "1000");
|
||||||
I2PSocketOptions proxyOpts = tun.buildOptions(overrides);
|
I2PSocketOptions proxyOpts = tun.buildOptions(overrides);
|
||||||
Destination dest = I2PTunnel.destFromName(proxy);
|
Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(proxy);
|
||||||
if (dest == null)
|
if (dest == null)
|
||||||
throw new SOCKSException("Outproxy not found");
|
throw new SOCKSException("Outproxy not found");
|
||||||
I2PSocket destSock = tun.createI2PSocket(I2PTunnel.destFromName(proxy), proxyOpts);
|
I2PSocket destSock = tun.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy), proxyOpts);
|
||||||
try {
|
try {
|
||||||
DataOutputStream out = new DataOutputStream(destSock.getOutputStream());
|
DataOutputStream out = new DataOutputStream(destSock.getOutputStream());
|
||||||
boolean authAvail = Boolean.valueOf(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH)).booleanValue();
|
boolean authAvail = Boolean.valueOf(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH)).booleanValue();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.i2p.i2ptunnel.socks;
|
package net.i2p.i2ptunnel.socks;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.data.Base32;
|
import net.i2p.data.Base32;
|
||||||
import net.i2p.data.DataFormatException;
|
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
import net.i2p.i2ptunnel.I2PTunnel;
|
import net.i2p.i2ptunnel.I2PTunnel;
|
||||||
|
|
||||||
@ -74,11 +74,8 @@ public class SOCKSHeader {
|
|||||||
String name = getHost();
|
String name = getHost();
|
||||||
if (name == null)
|
if (name == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
// the naming service does caching (thankfully)
|
||||||
// the naming service does caching (thankfully)
|
return I2PAppContext.getGlobalContext().namingService().lookup(name);
|
||||||
return I2PTunnel.destFromName(name);
|
|
||||||
} catch (DataFormatException dfe) {}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getBytes() {
|
public byte[] getBytes() {
|
||||||
|
@ -117,9 +117,7 @@ import net.i2p.util.Log;
|
|||||||
|
|
||||||
// Setup the sink. Always send repliable datagrams.
|
// Setup the sink. Always send repliable datagrams.
|
||||||
if (destination != null && destination.length() > 0) {
|
if (destination != null && destination.length() > 0) {
|
||||||
try {
|
_otherDest = _context.namingService().lookup(destination);
|
||||||
_otherDest = I2PTunnel.destFromName(destination);
|
|
||||||
} catch (DataFormatException dfe) {}
|
|
||||||
if (_otherDest == null) {
|
if (_otherDest == null) {
|
||||||
l.log("Could not resolve " + destination);
|
l.log("Could not resolve " + destination);
|
||||||
throw new RuntimeException("failed to create session - could not resolve " + destination);
|
throw new RuntimeException("failed to create session - could not resolve " + destination);
|
||||||
|
Reference in New Issue
Block a user