diff --git a/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java b/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java index a223b49f56bf0ebbdc9ed7e52b7b4bc2015852c0..42edac0b5890f034012418ae520b4f9cdea6f190 100644 --- a/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java +++ b/apps/sam/java/src/net/i2p/sam/SAMStreamSession.java @@ -364,11 +364,11 @@ class SAMStreamSession implements SAMMessageSess { /** * Unsupported - * @throws DataFormatException always + * @throws I2PSessionException always * @since 0.9.25 moved from subclass SAMv3StreamSession to implement SAMMessageSess */ - public boolean sendBytes(String s, byte[] b, int pr, int fp, int tp) throws DataFormatException { - throw new DataFormatException(null); + public boolean sendBytes(String s, byte[] b, int pr, int fp, int tp) throws I2PSessionException { + throw new I2PSessionException("Unsupported in stream or master session"); } /** diff --git a/apps/sam/java/src/net/i2p/sam/client/SAMStreamSend.java b/apps/sam/java/src/net/i2p/sam/client/SAMStreamSend.java index df2156d5de55a76103a75248e2973956716ae1c0..e1a475a938962ef2c00b6830cc03c1b6f39220ed 100644 --- a/apps/sam/java/src/net/i2p/sam/client/SAMStreamSend.java +++ b/apps/sam/java/src/net/i2p/sam/client/SAMStreamSend.java @@ -56,18 +56,20 @@ public class SAMStreamSend { private static final int STREAM=0, DG=1, V1DG=2, RAW=3, V1RAW=4; private static final int MASTER=8; - private static final String USAGE = "Usage: SAMStreamSend [-s] [-x] [-m mode] [-v version] [-b samHost] [-p samPort] [-o opt=val] [-u user] [-w password] peerDestFile dataDir\n" + + private static final String USAGE = "Usage: SAMStreamSend [-s] [-x] [-m mode] [-v version] [-b samHost] [-p samPort]\n" + + " [-o opt=val] [-u user] [-w password] peerDestFile dataDir\n" + " modes: stream: 0; datagram: 1; v1datagram: 2; raw: 3; v1raw: 4\n" + + " default is stream\n" + " -s: use SSL\n" + " -x: use master session (forces -v 3.3)\n" + " multiple -o session options are allowed"; public static void main(String args[]) { - Getopt g = new Getopt("SAM", args, "sxb:m:o:p:u:v:w:"); + Getopt g = new Getopt("SAM", args, "sxhb:m:o:p:u:v:w:"); boolean isSSL = false; boolean isMaster = false; int mode = STREAM; - String version = "1.0"; + String version = "3.3"; String host = "127.0.0.1"; String port = "7656"; String user = null; @@ -292,10 +294,12 @@ public class SAMStreamSend { style = "STREAM"; else if (mode == DG || mode == V1DG) style = "DATAGRAM"; - else + else // RAW or V1RAW style = "RAW"; if (masterMode) { + if (mode == V1DG || mode == V1RAW) + throw new IllegalArgumentException("v1 dg/raw incompatible with master session"); String req = "SESSION CREATE DESTINATION=TRANSIENT STYLE=MASTER ID=masterSend " + opts + '\n'; samOut.write(req.getBytes("UTF-8")); samOut.flush(); @@ -306,6 +310,9 @@ public class SAMStreamSend { throw new IOException("SESSION CREATE STYLE=MASTER failed"); if (_log.shouldLog(Log.DEBUG)) _log.debug("SESSION CREATE STYLE=MASTER reply found: " + ok); + // PORT required even if we aren't listening for this test + if (mode != STREAM) + opts += " PORT=9999"; } String req = "SESSION " + command + " STYLE=" + style + ' ' + _conOptions + ' ' + opts + '\n'; samOut.write(req.getBytes("UTF-8")); diff --git a/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java b/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java index ebeabe326a93794b5c04737f98bbb9e1bee3d33e..a0d5d15607de7ed691844f992494612370276f1e 100644 --- a/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java +++ b/apps/sam/java/src/net/i2p/sam/client/SAMStreamSink.java @@ -64,6 +64,7 @@ public class SAMStreamSink { " modes: stream: 0; datagram: 1; v1datagram: 2;\n" + " raw: 3; v1raw: 4; raw-with-headers: 5;\n" + " stream-forward: 6; stream-forward-ssl: 7\n" + + " default is stream\n" + " -s: use SSL to connect to bridge\n" + " -x: use master session (forces -v 3.3)\n" + " multiple -o session options are allowed"; @@ -71,11 +72,11 @@ public class SAMStreamSink { private static final int V3DGPORT=9999; public static void main(String args[]) { - Getopt g = new Getopt("SAM", args, "sxb:m:p:u:v:w:"); + Getopt g = new Getopt("SAM", args, "sxhb:m:p:u:v:w:"); boolean isSSL = false; boolean isMaster = false; int mode = STREAM; - String version = "1.0"; + String version = "3.3"; String host = "127.0.0.1"; String port = "7656"; String user = null; @@ -682,6 +683,8 @@ public class SAMStreamSink { style = "RAW HEADER=true PORT=" + V3DGPORT; if (masterMode) { + if (mode == V1DG || mode == V1RAW) + throw new IllegalArgumentException("v1 dg/raw incompatible with master session"); String req = "SESSION CREATE DESTINATION=" + dest + " STYLE=MASTER ID=masterSink " + sopts + '\n'; samOut.write(req.getBytes("UTF-8")); samOut.flush();