From 9ba86e86aa1f320a9ddbb644e09afcdf0d1b01ba Mon Sep 17 00:00:00 2001 From: zzz 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 ec38052cc..75a276aa0 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: 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 435b30947..053fc61ce 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 574f723fe..e151d733d 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 1301fcd2c..8288e702f 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("
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);