diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java index ec38052cc02159183759b6f081dfb7256b40be24..75a276aa00a939c8b7ae6ba154e742fda950ef3d 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java @@ -1573,6 +1573,7 @@ public class I2PTunnel implements Logging, EventDispatcher { * * Since file:<filename> isn't really used, this method is deprecated, * 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 { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java index 435b309479c7b5da628d1a7944bd3038376ab8cc..053fc61ceab5227bb5d7570f1a2a1e6d93f4a70e 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java @@ -42,15 +42,11 @@ public class I2PTunnelClient extends I2PTunnelClientBase { dests = new ArrayList(1); while (tok.hasMoreTokens()) { String destination = tok.nextToken(); - try { - Destination destN = I2PTunnel.destFromName(destination); - if (destN == null) - l.log("Could not resolve " + destination); - else - dests.add(destN); - } catch (DataFormatException dfe) { - l.log("Bad format parsing \"" + destination + "\""); - } + Destination destN = _context.namingService().lookup(destination); + if (destN == null) + l.log("Could not resolve " + destination); + else + dests.add(destN); } if (dests.isEmpty()) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java index 574f723feb1b4465bf9e72f43728afdeddaca706..e151d733d7d8b55d75bb9e9b8b81fd8b4845ea49 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelConnectClient.java @@ -278,7 +278,7 @@ public class I2PTunnelConnectClient extends I2PTunnelHTTPClientBase implements R return; } - Destination clientDest = I2PTunnel.destFromName(destination); + Destination clientDest = _context.namingService().lookup(destination); if (clientDest == null) { String str; byte[] header; diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 1301fcd2cb44bd3de4d33b57faa8cab2b699382e..8288e702fda131e109d611b363cf20fe5bf3cc2a 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -28,7 +28,6 @@ import net.i2p.client.streaming.I2PSocketManager; import net.i2p.client.streaming.I2PSocketOptions; import net.i2p.data.Base32; import net.i2p.data.Base64; -import net.i2p.data.DataFormatException; import net.i2p.data.DataHelper; import net.i2p.data.Destination; import net.i2p.util.EventDispatcher; @@ -431,11 +430,9 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn // Host resolvable from database, verify addresshelper key // Silently bypass correct keys, otherwise alert String destB64 = null; - try { - Destination _dest = I2PTunnel.destFromName(host); - if (_dest != null) - destB64 = _dest.toBase64(); - } catch (DataFormatException dfe) {} + Destination _dest = _context.namingService().lookup(host); + if (_dest != null) + destB64 = _dest.toBase64(); if (destB64 != null && !destB64.equals(ahelperKey)) { // Conflict: handle when URL reconstruction done @@ -721,7 +718,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn if ("i2p".equals(host)) clientDest = null; else - clientDest = I2PTunnel.destFromName(destination); + clientDest = _context.namingService().lookup(destination); if (clientDest == null) { //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. * 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.length() == 60 && host.toLowerCase().endsWith(".b32.i2p")) return host; - try { - Destination dest = I2PTunnel.destFromName(host); - if (dest == null) return "i2p"; - return Base32.encode(dest.calculateHash().getData()) + ".b32.i2p"; - } catch (DataFormatException dfe) { - return "i2p"; - } + Destination dest = _context.namingService().lookup(host); + if (dest == null) return "i2p"; + return Base32.encode(dest.calculateHash().getData()) + ".b32.i2p"; } /** @@ -947,12 +940,8 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn // Skip jump servers we don't know String jumphost = jurl.substring(7); // "http://" jumphost = jumphost.substring(0, jumphost.indexOf('/')); - try { - Destination dest = I2PTunnel.destFromName(jumphost); - if (dest == null) continue; - } catch (DataFormatException dfe) { - continue; - } + Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(jumphost); + if (dest == null) continue; out.write("<br><a href=\"".getBytes()); out.write(jurl.getBytes()); @@ -1014,7 +1003,7 @@ public class I2PTunnelHTTPClient extends I2PTunnelHTTPClientBase implements Runn if (!found) { try { - Destination d = I2PTunnel.destFromName(host); + Destination d = _context.namingService().lookup(host); if (d == null) return false; } catch (DataFormatException dfe) { } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelIRCClient.java index 6938a11ef58e5e72eae0ce2b483391a2b498084d..850a1fedc4650a2463e2b84f9ff0c6b4ddaa60c5 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.List; import java.util.StringTokenizer; import net.i2p.client.streaming.I2PSocket; -import net.i2p.data.DataFormatException; import net.i2p.data.Destination; import net.i2p.util.EventDispatcher; import net.i2p.util.I2PAppThread; @@ -52,15 +51,11 @@ public class I2PTunnelIRCClient extends I2PTunnelClientBase implements Runnable dests = new ArrayList(2); while (tok.hasMoreTokens()) { String destination = tok.nextToken(); - try { - Destination destN = I2PTunnel.destFromName(destination); - if (destN == null) - l.log("Could not resolve " + destination); - else - dests.add(destN); - } catch (DataFormatException dfe) { - l.log("Bad format parsing \"" + destination + "\""); - } + Destination destN = _context.namingService().lookup(destination); + if (destN == null) + l.log("Could not resolve " + destination); + else + dests.add(destN); } if (dests.isEmpty()) { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java index a3cd1ad992658f09d8c715c7512ab174ab8d8bbf..3da0ba275a8d4aa726b93148b71a89fe16971103 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2Ping.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import net.i2p.I2PAppContext; import net.i2p.I2PException; import net.i2p.client.streaming.I2PSocketManager; import net.i2p.data.Destination; @@ -200,7 +201,7 @@ public class I2Ping extends I2PTunnelTask implements Runnable { @Override public void run() { try { - Destination dest = I2PTunnel.destFromName(destination); + Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(destination); if (dest == null) { synchronized (lock) { // Logger is not thread safe l.log("Unresolvable: " + destination + ""); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java index 55feadf2189e8e004696355e2f54031bf3446fcc..865d089bfe4157389549df3b7fe51b9be6a4a9e4 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS4aServer.java @@ -204,7 +204,7 @@ public class SOCKS4aServer extends SOCKSServer { // Let's not due a new Dest for every request, huh? //I2PSocketManager sm = I2PSocketManagerFactory.createManager(); //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)) { String err = "No localhost accesses allowed through the Socks Proxy"; _log.error(err); @@ -237,7 +237,7 @@ public class SOCKS4aServer extends SOCKSServer { _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 // to do a socks session to them? - destSock = t.createI2PSocket(I2PTunnel.destFromName(proxy)); + destSock = t.createI2PSocket(I2PAppContext.getGlobalContext().namingService().lookup(proxy)); } confirmConnection(); _log.debug("connection confirmed - exchanging data..."); diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java index 427ca4b48fbe313956d749996753a350d27b9eb7..4625b7cd8e41af4caf301fac984e07c6f8d01b3d 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKS5Server.java @@ -360,14 +360,14 @@ public class SOCKS5Server extends SOCKSServer { // Let's not due a new Dest for every request, huh? //I2PSocketManager sm = I2PSocketManagerFactory.createManager(); //destSock = sm.connect(I2PTunnel.destFromName(connHostName), null); - Destination dest = I2PTunnel.destFromName(connHostName); + Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(connHostName); if (dest == null) { try { sendRequestReply(Reply.HOST_UNREACHABLE, AddressType.DOMAINNAME, null, "0.0.0.0", 0, out); } catch (IOException ioe) {} 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)) { String err = "No localhost accesses allowed through the Socks Proxy"; _log.error(err); @@ -455,10 +455,10 @@ public class SOCKS5Server extends SOCKSServer { Properties overrides = new Properties(); overrides.setProperty("option.i2p.streaming.connectDelay", "1000"); I2PSocketOptions proxyOpts = tun.buildOptions(overrides); - Destination dest = I2PTunnel.destFromName(proxy); + Destination dest = I2PAppContext.getGlobalContext().namingService().lookup(proxy); if (dest == null) 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 { DataOutputStream out = new DataOutputStream(destSock.getOutputStream()); boolean authAvail = Boolean.valueOf(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH)).booleanValue(); 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 763b9aa10a3f227d825d3d3fdb5a292d7d6d7538..32209301d461c3d7e981195cda138e5a89c19300 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,7 @@ package net.i2p.i2ptunnel.socks; +import net.i2p.I2PAppContext; import net.i2p.data.Base32; -import net.i2p.data.DataFormatException; import net.i2p.data.Destination; import net.i2p.i2ptunnel.I2PTunnel; @@ -74,11 +74,8 @@ public class SOCKSHeader { String name = getHost(); if (name == null) return null; - try { - // the naming service does caching (thankfully) - return I2PTunnel.destFromName(name); - } catch (DataFormatException dfe) {} - return null; + // the naming service does caching (thankfully) + return I2PAppContext.getGlobalContext().namingService().lookup(name); } public byte[] getBytes() { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udpTunnel/I2PTunnelUDPClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udpTunnel/I2PTunnelUDPClientBase.java index 4cecc28c3afddd8b87c2c5d837f5961aca175121..38c82a70c54f4a90d32302cffd683e75521cc049 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udpTunnel/I2PTunnelUDPClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/udpTunnel/I2PTunnelUDPClientBase.java @@ -117,9 +117,7 @@ import net.i2p.util.Log; // Setup the sink. Always send repliable datagrams. if (destination != null && destination.length() > 0) { - try { - _otherDest = I2PTunnel.destFromName(destination); - } catch (DataFormatException dfe) {} + _otherDest = _context.namingService().lookup(destination); if (_otherDest == null) { l.log("Could not resolve " + destination); throw new RuntimeException("failed to create session - could not resolve " + destination);