From d945eb6fcfb3552b2d660129f8506d58d4f1e498 Mon Sep 17 00:00:00 2001 From: human Date: Mon, 19 Apr 2004 21:47:06 +0000 Subject: [PATCH] Made all the ministreaming-based apps aware of the new exceptions thrown by I2PSocketManager.connect() (human) --- .../net/i2p/i2ptunnel/I2PTunnelClient.java | 6 ++--- .../i2p/i2ptunnel/I2PTunnelClientBase.java | 13 ++++++++--- .../i2p/i2ptunnel/I2PTunnelHTTPClient.java | 22 +++++++++++++++---- .../net/i2p/i2ptunnel/socks/SOCKSServer.java | 16 ++++++++++++-- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java index b685fd72c..46588cfd7 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClient.java @@ -49,11 +49,11 @@ public class I2PTunnelClient extends I2PTunnelClientBase { try { I2PSocket i2ps = createI2PSocket(dest); new I2PTunnelRunner(s, i2ps, sockLock, null); - } catch (I2PException ex) { + } catch (Exception ex) { _log.info("Error connecting", ex); - l.log("Unable to reach peer"); + l.log(ex.getMessage()); // s has been initialized before the try block... closeSocket(s); } } -} \ No newline at end of file +} diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index eb80e9386..43bef4e26 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -4,7 +4,9 @@ package net.i2p.i2ptunnel; import java.io.IOException; +import java.net.ConnectException; import java.net.InetAddress; +import java.net.NoRouteToHostException; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; @@ -155,7 +157,7 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * @param dest The destination to connect to * @return a new I2PSocket */ - public I2PSocket createI2PSocket(Destination dest) throws I2PException { + public I2PSocket createI2PSocket(Destination dest) throws I2PException, ConnectException, NoRouteToHostException, InterruptedException { return createI2PSocket(dest, getDefaultOptions()); } @@ -167,8 +169,13 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * @param dest The destination to connect to * @param opt Option to be used to open when opening the socket * @return a new I2PSocket + * + * @throws ConnectException if the peer refuses the connection + * @throws NoRouteToHostException if the peer is not found or not reachable + * @throws InterruptedException if the connection timeouts + * @throws I2PException if there is some other I2P-related problem */ - public I2PSocket createI2PSocket(Destination dest, I2PSocketOptions opt) throws I2PException { + public I2PSocket createI2PSocket(Destination dest, I2PSocketOptions opt) throws I2PException, ConnectException, NoRouteToHostException, InterruptedException { I2PSocket i2ps; synchronized (sockLock) { @@ -283,4 +290,4 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * you do not override manageConnection() */ protected abstract void clientConnectionRun(Socket s); -} \ No newline at end of file +} diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 516d70d76..47a8c8aba 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; +import java.net.SocketException; import java.util.Date; import net.i2p.I2PException; @@ -188,15 +189,28 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable I2PTunnelRunner runner = new I2PTunnelRunner(s, i2ps, sockLock, data); timeoutThread = new InactivityTimeoutThread(runner, out, targetRequest, usingWWWProxy, s); timeoutThread.start(); + } catch (SocketException ex) { + if (timeoutThread != null) timeoutThread.disable(); + _log.info("Error trying to connect", ex); + l.log(ex.getMessage()); + handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, wwwProxy); + closeSocket(s); } catch (IOException ex) { if (timeoutThread != null) timeoutThread.disable(); - _log.error("Error sending syn", ex); + _log.info("Error trying to connect", ex); + l.log(ex.getMessage()); + handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, wwwProxy); + closeSocket(s); + } catch (InterruptedException ex) { + if (timeoutThread != null) timeoutThread.disable(); + _log.info("Error trying to connect", ex); + l.log(ex.getMessage()); handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, wwwProxy); closeSocket(s); } catch (I2PException ex) { if (timeoutThread != null) timeoutThread.disable(); - _log.info("Error sending syn", ex); - l.log("Unable to reach peer"); + _log.info("Error trying to connect", ex); + l.log(ex.getMessage()); handleHTTPClientException(ex, out, targetRequest, usingWWWProxy, wwwProxy); closeSocket(s); } @@ -342,4 +356,4 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable return protocol.equalsIgnoreCase("http://"); } -} \ No newline at end of file +} diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java index bf8b0889f..c150e84ca 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java @@ -6,7 +6,9 @@ */ package net.i2p.i2ptunnel.socks; +import java.io.IOException; import java.net.Socket; +import java.net.SocketException; import net.i2p.I2PException; import net.i2p.client.streaming.I2PSocket; @@ -88,10 +90,20 @@ public abstract class SOCKSServer { } } catch (DataFormatException e) { throw new SOCKSException("Error in destination format"); + } catch (SocketException e) { + throw new SOCKSException("Error connecting (" + + e.getMessage() + ")"); + } catch (IOException e) { + throw new SOCKSException("Error connecting (" + + e.getMessage() + ")"); + } catch (InterruptedException e) { + throw new SOCKSException("Error connecting (" + + e.getMessage() + ")"); } catch (I2PException e) { - throw new SOCKSException("I2P error (" + e.getMessage() + ")"); + throw new SOCKSException("Error connecting (" + + e.getMessage() + ")"); } return destSock; } -} \ No newline at end of file +}