diff --git a/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java b/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java index 1be21a9df2f60fd513bde301fc09be61544d55a4..ff9a1bc004a88ab1c0152fd52c00c3bf0442669c 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java @@ -14,6 +14,8 @@ import java.io.InputStream; import java.io.IOException; import java.util.HashMap; import java.io.OutputStream; +import java.net.ConnectException; +import java.net.NoRouteToHostException; import java.util.Iterator; import java.util.Properties; import java.util.Set; @@ -143,8 +145,16 @@ public class SAMStreamSession { * @param id Unique id for the connection * @param dest Base64-encoded Destination to connect to * @param props Options to be used for connection + * + * @throws DataFormatException if the destination is not valid + * @throws SAMInvalidDirectionException if trying to connect through a + * receive-only session + * @throws ConnectException if the destination refuses connections + * @throws NoRouteToHostException if the destination can't be reached + * @throws InterruptedException if the connection timeouts + * @throws I2PException if there's another I2P-related error */ - public boolean connect(int id, String dest, Properties props) throws I2PException, DataFormatException, SAMInvalidDirectionException { + public boolean connect(int id, String dest, Properties props) throws I2PException, ConnectException, NoRouteToHostException, DataFormatException, InterruptedException, SAMInvalidDirectionException { if (!canCreate) { _log.debug("Trying to create an outgoing connection using a receive-only session"); throw new SAMInvalidDirectionException("Trying to create connections through a receive-only session"); @@ -199,6 +209,7 @@ public class SAMStreamSession { } removeAllSocketHandlers(); recv.stopStreamReceiving(); + socketMgr.destroySocketManager(); } /** diff --git a/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java b/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java index cc45e7b667f58153ba850e7d199fd5e2b2b54736..b020ed86df645f20b0225b60cb30ba2703d0b1d4 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java @@ -17,6 +17,8 @@ import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.Socket; +import java.net.ConnectException; +import java.net.NoRouteToHostException; import java.util.Enumeration; import java.util.Properties; import java.util.StringTokenizer; @@ -569,14 +571,26 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag _log.debug("Invalid destination in STREAM CONNECT message"); return writeString("STREAM STATUS RESULT=INVALID_KEY ID=" + id + "\n"); - } catch (I2PException e) { - _log.debug("STREAM CONNECT failed: " + e.getMessage()); - return writeString("STREAM STATUS RESULT=I2P_ERROR ID=" - + id + "\n"); } catch (SAMInvalidDirectionException e) { _log.debug("STREAM CONNECT failed: " + e.getMessage()); return writeString("STREAM STATUS RESULT=INVALID_DIRECTION ID=" + id + "\n"); + } catch (ConnectException e) { + _log.debug("STREAM CONNECT failed: " + e.getMessage()); + return writeString("STREAM STATUS RESULT=CONNECTION_REFUSED ID=" + + id + "\n"); + } catch (NoRouteToHostException e) { + _log.debug("STREAM CONNECT failed: " + e.getMessage()); + return writeString("STREAM STATUS RESULT=CANT_REACH_PEER ID=" + + id + "\n"); + } catch (InterruptedException e) { + _log.debug("STREAM CONNECT failed: " + e.getMessage()); + return writeString("STREAM STATUS RESULT=TIMEOUT ID=" + + id + "\n"); + } catch (I2PException e) { + _log.debug("STREAM CONNECT failed: " + e.getMessage()); + return writeString("STREAM STATUS RESULT=I2P_ERROR ID=" + + id + "\n"); } } else if (opcode.equals("CLOSE")) { if (props == null) {