diff --git a/apps/sam/java/src/net/i2p/sam/SAMv3DatagramSession.java b/apps/sam/java/src/net/i2p/sam/SAMv3DatagramSession.java index dcca03c141c5a6d41296fa49392a5fda29383322..c933e77cc341e23081c34c1d801f7bde5475f9e5 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv3DatagramSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv3DatagramSession.java @@ -61,10 +61,9 @@ public class SAMv3DatagramSession extends SAMDatagramSession implements SAMv3Han int port = Integer.parseInt(portStr); String host = props.getProperty("HOST"); - if ( host==null ) { - _log.debug("no host specified. Take from the client socket"); - + if ( host==null ) { host = rec.getHandler().getClientIP(); + _log.debug("no host specified. Taken from the client socket : " + host+':'+port); } diff --git a/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java b/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java index b629cc09a1e75e2b98d8ca4760c54b94cfa9cf73..b6a03a9ebfcd39faaae787eaff89875046486222 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java @@ -323,6 +323,8 @@ public class SAMv3Handler extends SAMv1Handler boolean stolenSocket = false ; + boolean streamForwardingSocket = false ; + public void stealSocket() { stolenSocket = true ; @@ -414,6 +416,20 @@ public class SAMv3Handler extends SAMv1Handler _log.error("Error closing socket: " + e.getMessage()); } } + if (streamForwardingSocket) + { + if (this.streamSession!=null) { + try { + this.streamSession.stopForwardingIncoming(); + } catch (SAMException e) { + _log.error("Error while stopping forwarding connections: " + e.getMessage()); + } catch (InterruptedIOException e) { + _log.error("Interrupted while stopping forwarding connections: " + e.getMessage()); + } + } + } + + die(); } @@ -692,9 +708,10 @@ public class SAMv3Handler extends SAMv1Handler protected boolean execStreamForwardIncoming( Properties props ) { try { try { + streamForwardingSocket = true ; streamSession.startForwardingIncoming(props); notifyStreamResult( true, "OK", null ); - return false ; + return true ; } catch (SAMException e) { _log.debug("Forwarding STREAM connections failed: " + e.getMessage()); notifyStreamResult ( true, "I2P_ERROR", "Forwarding failed : " + e.getMessage() ); diff --git a/apps/sam/java/src/net/i2p/sam/SAMv3RawSession.java b/apps/sam/java/src/net/i2p/sam/SAMv3RawSession.java index 1bf7d18a0bea571947a7cdc2f925ec3a90665573..085293565a6b0bf278b79867382cf27bd87d5c67 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv3RawSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv3RawSession.java @@ -63,9 +63,9 @@ public class SAMv3RawSession extends SAMRawSession implements SAMv3Handler.Sess String host = props.getProperty("HOST"); if ( host==null ) { - _log.debug("no host specified. Take from the client socket"); - host = rec.getHandler().getClientIP(); + + _log.debug("no host specified. Taken from the client socket : " + host +':'+port); } diff --git a/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java b/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java index f02591bb6eb6e03b97557381513c57af63c0574b..0c2922fb1930d0e492e7e40af8091834e50ee24c 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv3StreamSession.java @@ -230,9 +230,8 @@ public class SAMv3StreamSession extends SAMStreamSession implements SAMv3Handle String host = props.getProperty("HOST"); if ( host==null ) { - _log.debug("no host specified. Take from the client socket"); - host = rec.getHandler().getClientIP(); + _log.debug("no host specified. Taken from the client socket : " + host +':'+port); } @@ -368,7 +367,32 @@ public class SAMv3StreamSession extends SAMStreamSession implements SAMv3Handle } } - + /** + * + * @param props + * @throws SAMException + * @throws InterruptedIOException + */ + public void stopForwardingIncoming() throws SAMException, InterruptedIOException + { + SAMv3Handler.SessionRecord rec = SAMv3Handler.sSessionsHash.get(nick); + + if ( rec==null ) throw new InterruptedIOException() ; + + I2PServerSocket server = null ; + synchronized( this.socketServerLock ) + { + if (this.socketServer==null) { + _log.debug("no socket server is defined for this destination"); + throw new SAMException("no socket server is defined for this destination"); + } + server = this.socketServer ; + this.socketServer = null ; + } + try { + server.close(); + } catch ( I2PException e) {} + } /** * Close the stream session