diff --git a/apps/sam/doc/sam.3.0-protocol.txt b/apps/sam/doc/sam.3.0-protocol.txt index 7d8871dca..d2133ba53 100644 --- a/apps/sam/doc/sam.3.0-protocol.txt +++ b/apps/sam/doc/sam.3.0-protocol.txt @@ -297,6 +297,8 @@ address (leaving up to 1KB for header material). This FROM address is authenticated internally by SAM (making use of the destination's signing key to verify the source) and includes replay prevention. +** First method : + After establishing a SAM session with STYLE=DATAGRAM, the client can send datagrams through SAM's UDP port (7655). @@ -314,6 +316,12 @@ following format : The first line will be discarded by SAM before sending the remaining of the message to the specified destination. +** Second method : + +Datagrams can also be sent through the socket from which the datagram +session was opened. See the "DATAGRAM SEND" command of SAM versions 1 +and 2. + ---------------------------------------------------------------------- SAM repliable datagrams : receiving a datagram ---------------------------------------------------------------------- diff --git a/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java b/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java index 7734ea574..4e6bd5dc7 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv1Handler.java @@ -178,8 +178,8 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag if (getDatagramSession() != null) { getDatagramSession().close(); } - if (streamSession != null) { - streamSession.close(); + if (getStreamSession() != null) { + getStreamSession().close(); } } } @@ -192,7 +192,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag try{ if (opcode.equals("CREATE")) { if ((getRawSession() != null) || (getDatagramSession() != null) - || (streamSession != null)) { + || (getStreamSession() != null)) { _log.debug("Trying to create a session, but one still exists"); return writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"Session already exists\"\n"); } @@ -408,7 +408,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag in.readFully(data); - if (!datagramSession.sendBytes(dest, data)) { + if (!getDatagramSession().sendBytes(dest, data)) { _log.error("DATAGRAM SEND failed"); return true; } @@ -507,7 +507,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag /* Parse and execute a STREAM message */ protected boolean execStreamMessage(String opcode, Properties props) { - if (streamSession == null) { + if (getStreamSession() == null) { _log.error("STREAM message received, but no STREAM session exists"); return false; } @@ -567,11 +567,11 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag } try { - if (!streamSession.sendBytes(id, getClientSocket().socket().getInputStream(), size)) { // data)) { + if (!getStreamSession().sendBytes(id, getClientSocket().socket().getInputStream(), size)) { // data)) { if (_log.shouldLog(Log.WARN)) _log.warn("STREAM SEND [" + size + "] failed"); boolean rv = writeString("STREAM CLOSED RESULT=CANT_REACH_PEER ID=" + id + " MESSAGE=\"Send of " + size + " bytes failed\"\n"); - streamSession.closeConnection(id); + getStreamSession().closeConnection(id); return rv; } @@ -622,7 +622,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag try { try { - if (!streamSession.connect(id, dest, props)) { + if (!getStreamSession().connect(id, dest, props)) { _log.debug("STREAM connection failed"); return false; } @@ -673,7 +673,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag } } - boolean closed = streamSession.closeConnection(id); + boolean closed = getStreamSession().closeConnection(id); if ( (!closed) && (_log.shouldLog(Log.WARN)) ) _log.warn("Stream unable to be closed, but this is non fatal"); return true; @@ -765,7 +765,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag public void streamSendAnswer( int id, String result, String bufferState ) throws IOException { - if ( streamSession == null ) + if ( getStreamSession() == null ) { _log.error ( "BUG! Want to answer to stream SEND, but session is null!" ); throw new NullPointerException ( "BUG! STREAM session is null!" ); @@ -783,7 +783,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag public void notifyStreamSendBufferFree( int id ) throws IOException { - if ( streamSession == null ) + if ( getStreamSession() == null ) { _log.error ( "BUG! Stream outgoing buffer is free, but session is null!" ); throw new NullPointerException ( "BUG! STREAM session is null!" ); @@ -797,7 +797,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag public void notifyStreamIncomingConnection(int id, Destination d) throws IOException { - if (streamSession == null) { + if (getStreamSession() == null) { _log.error("BUG! Received stream connection, but session is null!"); throw new NullPointerException("BUG! STREAM session is null!"); } @@ -811,7 +811,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag public void notifyStreamOutgoingConnection ( int id, String result, String msg ) throws IOException { - if ( streamSession == null ) + if ( getStreamSession() == null ) { _log.error ( "BUG! Received stream connection, but session is null!" ); throw new NullPointerException ( "BUG! STREAM session is null!" ); @@ -832,7 +832,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag } public void receiveStreamBytes(int id, ByteBuffer data) throws IOException { - if (streamSession == null) { + if (getStreamSession() == null) { _log.error("Received stream bytes, but session is null!"); throw new NullPointerException("BUG! STREAM session is null!"); } @@ -852,7 +852,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag } public void notifyStreamDisconnection(int id, String result, String msg) throws IOException { - if (streamSession == null) { + if (getStreamSession() == null) { _log.error("BUG! Received stream disconnection, but session is null!"); throw new NullPointerException("BUG! STREAM session is null!"); } @@ -868,7 +868,7 @@ public class SAMv1Handler extends SAMHandler implements SAMRawReceiver, SAMDatag public void stopStreamReceiving() { _log.debug("stopStreamReceiving() invoked", new Exception("stopped")); - if (streamSession == null) { + if (getStreamSession() == null) { _log.error("BUG! Got stream receiving stop, but session is null!"); throw new NullPointerException("BUG! STREAM session is null!"); } diff --git a/apps/sam/java/src/net/i2p/sam/SAMv2Handler.java b/apps/sam/java/src/net/i2p/sam/SAMv2Handler.java index 0800e17e9..fe1f379b7 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv2Handler.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv2Handler.java @@ -72,7 +72,7 @@ public class SAMv2Handler extends SAMv1Handler implements SAMRawReceiver, SAMDat /* Parse and execute a STREAM message */ protected boolean execStreamMessage ( String opcode, Properties props ) { - if ( streamSession == null ) + if ( getStreamSession() == null ) { _log.error ( "STREAM message received, but no STREAM session exists" ); return false; @@ -173,7 +173,7 @@ public class SAMv2Handler extends SAMv1Handler implements SAMRawReceiver, SAMDat } } - streamSession.setReceiveLimit ( id, limit, nolimit ) ; + getStreamSession().setReceiveLimit ( id, limit, nolimit ) ; return true; } diff --git a/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java b/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java index b6a03a9eb..c4da74fa3 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java +++ b/apps/sam/java/src/net/i2p/sam/SAMv3Handler.java @@ -390,6 +390,8 @@ public class SAMv3Handler extends SAMv1Handler canContinue = execDestMessage(opcode, props); } else if (domain.equals("NAMING")) { canContinue = execNamingMessage(opcode, props); + } else if (domain.equals("DATAGRAM")) { + canContinue = execDatagramMessage(opcode, props); } else { _log.debug("Unrecognized message domain: \"" + domain + "\""); @@ -418,7 +420,7 @@ public class SAMv3Handler extends SAMv1Handler } if (streamForwardingSocket) { - if (this.streamSession!=null) { + if (this.getStreamSession()!=null) { try { this.streamSession.stopForwardingIncoming(); } catch (SAMException e) { @@ -464,7 +466,7 @@ public class SAMv3Handler extends SAMv1Handler try{ if (opcode.equals("CREATE")) { if ((this.getRawSession()!= null) || (this.getDatagramSession() != null) - || (streamSession != null)) { + || (this.getStreamSession() != null)) { _log.debug("Trying to create a session, but one still exists"); return writeString("SESSION STATUS RESULT=I2P_ERROR MESSAGE=\"Session already exists\"\n"); } @@ -761,7 +763,7 @@ public class SAMv3Handler extends SAMv1Handler } public void notifyStreamIncomingConnection(Destination d) throws IOException { - if (streamSession == null) { + if (getStreamSession() == null) { _log.error("BUG! Received stream connection, but session is null!"); throw new NullPointerException("BUG! STREAM session is null!"); }