I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit ebc3e05f authored by human's avatar human Committed by zzz
Browse files

* Made the SAM bridge aware of the new exceptions thrown by

  I2PSocketManager.connect(), with better error reporting to SAM clients;
* made SAMStreamSession destroy the associated I2PSocketManager when being
  closed.
(human)
parent 674ad899
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,8 @@ import java.io.InputStream; ...@@ -14,6 +14,8 @@ import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
...@@ -143,8 +145,16 @@ public class SAMStreamSession { ...@@ -143,8 +145,16 @@ public class SAMStreamSession {
* @param id Unique id for the connection * @param id Unique id for the connection
* @param dest Base64-encoded Destination to connect to * @param dest Base64-encoded Destination to connect to
* @param props Options to be used for connection * @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) { if (!canCreate) {
_log.debug("Trying to create an outgoing connection using a receive-only session"); _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"); throw new SAMInvalidDirectionException("Trying to create connections through a receive-only session");
...@@ -199,6 +209,7 @@ public class SAMStreamSession { ...@@ -199,6 +209,7 @@ public class SAMStreamSession {
} }
removeAllSocketHandlers(); removeAllSocketHandlers();
recv.stopStreamReceiving(); recv.stopStreamReceiving();
socketMgr.destroySocketManager();
} }
/** /**
......
...@@ -17,6 +17,8 @@ import java.io.IOException; ...@@ -17,6 +17,8 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.Socket; import java.net.Socket;
import java.net.ConnectException;
import java.net.NoRouteToHostException;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Properties; import java.util.Properties;
import java.util.StringTokenizer; import java.util.StringTokenizer;
...@@ -569,14 +571,26 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag ...@@ -569,14 +571,26 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag
_log.debug("Invalid destination in STREAM CONNECT message"); _log.debug("Invalid destination in STREAM CONNECT message");
return writeString("STREAM STATUS RESULT=INVALID_KEY ID=" return writeString("STREAM STATUS RESULT=INVALID_KEY ID="
+ id + "\n"); + 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) { } catch (SAMInvalidDirectionException e) {
_log.debug("STREAM CONNECT failed: " + e.getMessage()); _log.debug("STREAM CONNECT failed: " + e.getMessage());
return writeString("STREAM STATUS RESULT=INVALID_DIRECTION ID=" return writeString("STREAM STATUS RESULT=INVALID_DIRECTION ID="
+ id + "\n"); + 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")) { } else if (opcode.equals("CLOSE")) {
if (props == null) { if (props == null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment