From 9ba86e86aa1f320a9ddbb644e09afcdf0d1b01ba Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Sun, 28 Nov 2010 04:00:02 +0000 Subject: [PATCH] * I2PTunnel: Deprecate destFromName() --- .../java/src/net/i2p/i2ptunnel/I2PTunnel.java | 1 + .../net/i2p/i2ptunnel/I2PTunnelClient.java | 14 +++----- .../i2p/i2ptunnel/I2PTunnelConnectClient.java | 2 +- .../i2p/i2ptunnel/I2PTunnelHTTPClient.java | 33 +++++++------------ .../net/i2p/i2ptunnel/I2PTunnelIRCClient.java | 15 +++------ .../java/src/net/i2p/i2ptunnel/I2Ping.java | 3 +- .../i2p/i2ptunnel/socks/SOCKS4aServer.java | 4 +-- .../net/i2p/i2ptunnel/socks/SOCKS5Server.java | 8 ++--- .../net/i2p/i2ptunnel/socks/SOCKSHeader.java | 9 ++--- .../udpTunnel/I2PTunnelUDPClientBase.java | 4 +-- 10 files changed, 35 insertions(+), 58 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnel.java index ec38052cc0..75a276aa00 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 435b309479..053fc61cea 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 574f723feb..e151d733d7 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 1301fcd2cb..8288e702fd 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 6938a11ef5..850a1fedc4 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 a3cd1ad992..3da0ba275a 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 55feadf218..865d089bfe 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 427ca4b48f..4625b7cd8e 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 763b9aa10a..32209301d4 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 4cecc28c3a..38c82a70c5 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); -- GitLab