add session options

This commit is contained in:
zzz
2015-11-27 13:44:07 +00:00
parent 31ace20256
commit e77c5bd05c
2 changed files with 31 additions and 17 deletions

View File

@@ -44,12 +44,13 @@ public class SAMStreamSend {
private static I2PSSLSocketFactory _sslSocketFactory; private static I2PSSLSocketFactory _sslSocketFactory;
private static final int STREAM=0, DG=1, V1DG=2, RAW=3, V1RAW=4; private static final int STREAM=0, DG=1, V1DG=2, RAW=3, V1RAW=4;
private static final String USAGE = "Usage: SAMStreamSend [-s] [-m mode] [-v version] [-b samHost] [-p samPort] [-u user] [-w password] peerDestFile dataDir\n" + private static final String USAGE = "Usage: SAMStreamSend [-s] [-m mode] [-v version] [-b samHost] [-p samPort] [-o opt=val] [-u user] [-w password] peerDestFile dataDir\n" +
" modes: stream: 0; datagram: 1; v1datagram: 2; raw: 3; v1raw: 4\n" + " modes: stream: 0; datagram: 1; v1datagram: 2; raw: 3; v1raw: 4\n" +
" -s: use SSL"; " -s: use SSL\n" +
" multiple -o session options are allowed";
public static void main(String args[]) { public static void main(String args[]) {
Getopt g = new Getopt("SAM", args, "sb:m:p:u:v:w:"); Getopt g = new Getopt("SAM", args, "sb:m:o:p:u:v:w:");
boolean isSSL = false; boolean isSSL = false;
int mode = STREAM; int mode = STREAM;
String version = "1.0"; String version = "1.0";
@@ -57,6 +58,7 @@ public class SAMStreamSend {
String port = "7656"; String port = "7656";
String user = null; String user = null;
String password = null; String password = null;
String opts = "";
int c; int c;
while ((c = g.getopt()) != -1) { while ((c = g.getopt()) != -1) {
switch (c) { switch (c) {
@@ -80,6 +82,10 @@ public class SAMStreamSend {
host = g.getOptarg(); host = g.getOptarg();
break; break;
case 'o':
opts = opts + ' ' + g.getOptarg();
break;
case 'p': case 'p':
port = g.getOptarg(); port = g.getOptarg();
break; break;
@@ -118,7 +124,7 @@ public class SAMStreamSend {
I2PAppContext ctx = I2PAppContext.getGlobalContext(); I2PAppContext ctx = I2PAppContext.getGlobalContext();
SAMStreamSend sender = new SAMStreamSend(ctx, host, port, SAMStreamSend sender = new SAMStreamSend(ctx, host, port,
args[startArgs], args[startArgs + 1]); args[startArgs], args[startArgs + 1]);
sender.startup(version, isSSL, mode, user, password); sender.startup(version, isSSL, mode, user, password, opts);
} }
public SAMStreamSend(I2PAppContext ctx, String samHost, String samPort, String destFile, String dataFile) { public SAMStreamSend(I2PAppContext ctx, String samHost, String samPort, String destFile, String dataFile) {
@@ -133,7 +139,7 @@ public class SAMStreamSend {
_remotePeers = new HashMap<String, Sender>(); _remotePeers = new HashMap<String, Sender>();
} }
public void startup(String version, boolean isSSL, int mode, String user, String password) { public void startup(String version, boolean isSSL, int mode, String user, String password, String sessionOpts) {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Starting up"); _log.debug("Starting up");
try { try {
@@ -144,7 +150,7 @@ public class SAMStreamSend {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Reader created"); _log.debug("Reader created");
OutputStream out = sock.getOutputStream(); OutputStream out = sock.getOutputStream();
String ourDest = handshake(out, version, true, eventHandler, mode, user, password); String ourDest = handshake(out, version, true, eventHandler, mode, user, password, sessionOpts);
if (ourDest == null) if (ourDest == null)
throw new IOException("handshake failed"); throw new IOException("handshake failed");
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
@@ -157,7 +163,7 @@ public class SAMStreamSend {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Reader2 created"); _log.debug("Reader2 created");
out = sock2.getOutputStream(); out = sock2.getOutputStream();
String ok = handshake(out, version, false, eventHandler, mode, user, password); String ok = handshake(out, version, false, eventHandler, mode, user, password, "");
if (ok == null) if (ok == null)
throw new IOException("2nd handshake failed"); throw new IOException("2nd handshake failed");
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
@@ -215,7 +221,8 @@ public class SAMStreamSend {
/** @return our b64 dest or null */ /** @return our b64 dest or null */
private String handshake(OutputStream samOut, String version, boolean isMaster, private String handshake(OutputStream samOut, String version, boolean isMaster,
SAMEventHandler eventHandler, int mode, String user, String password) { SAMEventHandler eventHandler, int mode, String user, String password,
String opts) {
synchronized (samOut) { synchronized (samOut) {
try { try {
if (user != null && password != null) if (user != null && password != null)
@@ -246,7 +253,7 @@ public class SAMStreamSend {
style = "DATAGRAM"; style = "DATAGRAM";
else else
style = "RAW"; style = "RAW";
String req = "SESSION CREATE STYLE=" + style + " DESTINATION=TRANSIENT " + _conOptions + "\n"; String req = "SESSION CREATE STYLE=" + style + " DESTINATION=TRANSIENT " + _conOptions + ' ' + opts + '\n';
samOut.write(req.getBytes()); samOut.write(req.getBytes());
samOut.flush(); samOut.flush();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))

View File

@@ -47,9 +47,10 @@ public class SAMStreamSink {
private static I2PSSLSocketFactory _sslSocketFactory; private static I2PSSLSocketFactory _sslSocketFactory;
private static final int STREAM=0, DG=1, V1DG=2, RAW=3, V1RAW=4; private static final int STREAM=0, DG=1, V1DG=2, RAW=3, V1RAW=4;
private static final String USAGE = "Usage: SAMStreamSink [-s] [-m mode] [-v version] [-b samHost] [-p samPort] [-u user] [-w password] myDestFile sinkDir\n" + private static final String USAGE = "Usage: SAMStreamSink [-s] [-m mode] [-v version] [-b samHost] [-p samPort] [-o opt=val] [-u user] [-w password] myDestFile sinkDir\n" +
" modes: stream: 0; datagram: 1; v1datagram: 2; raw: 3; v1raw: 4\n" + " modes: stream: 0; datagram: 1; v1datagram: 2; raw: 3; v1raw: 4\n" +
" -s: use SSL"; " -s: use SSL\n" +
" multiple -o session options are allowed";
public static void main(String args[]) { public static void main(String args[]) {
Getopt g = new Getopt("SAM", args, "sb:m:p:u:v:w:"); Getopt g = new Getopt("SAM", args, "sb:m:p:u:v:w:");
@@ -60,6 +61,7 @@ public class SAMStreamSink {
String port = "7656"; String port = "7656";
String user = null; String user = null;
String password = null; String password = null;
String opts = "";
int c; int c;
while ((c = g.getopt()) != -1) { while ((c = g.getopt()) != -1) {
switch (c) { switch (c) {
@@ -83,6 +85,10 @@ public class SAMStreamSink {
host = g.getOptarg(); host = g.getOptarg();
break; break;
case 'o':
opts = opts + ' ' + g.getOptarg();
break;
case 'p': case 'p':
port = g.getOptarg(); port = g.getOptarg();
break; break;
@@ -121,7 +127,7 @@ public class SAMStreamSink {
I2PAppContext ctx = I2PAppContext.getGlobalContext(); I2PAppContext ctx = I2PAppContext.getGlobalContext();
SAMStreamSink sink = new SAMStreamSink(ctx, host, port, SAMStreamSink sink = new SAMStreamSink(ctx, host, port,
args[startArgs], args[startArgs + 1]); args[startArgs], args[startArgs + 1]);
sink.startup(version, isSSL, mode, user, password); sink.startup(version, isSSL, mode, user, password, opts);
} }
public SAMStreamSink(I2PAppContext ctx, String samHost, String samPort, String destFile, String sinkDir) { public SAMStreamSink(I2PAppContext ctx, String samHost, String samPort, String destFile, String sinkDir) {
@@ -136,7 +142,7 @@ public class SAMStreamSink {
_remotePeers = new HashMap<String, Sink>(); _remotePeers = new HashMap<String, Sink>();
} }
public void startup(String version, boolean isSSL, int mode, String user, String password) { public void startup(String version, boolean isSSL, int mode, String user, String password, String sessionOpts) {
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Starting up"); _log.debug("Starting up");
try { try {
@@ -147,7 +153,7 @@ public class SAMStreamSink {
_reader.startReading(); _reader.startReading();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Reader created"); _log.debug("Reader created");
String ourDest = handshake(out, version, true, eventHandler, mode, user, password); String ourDest = handshake(out, version, true, eventHandler, mode, user, password, sessionOpts);
if (ourDest == null) if (ourDest == null)
throw new IOException("handshake failed"); throw new IOException("handshake failed");
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
@@ -165,7 +171,7 @@ public class SAMStreamSink {
_reader2.startReading(); _reader2.startReading();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Reader2 created"); _log.debug("Reader2 created");
String ok = handshake(out, version, false, eventHandler, mode, user, password); String ok = handshake(out, version, false, eventHandler, mode, user, password, "");
if (ok == null) if (ok == null)
throw new IOException("2nd handshake failed"); throw new IOException("2nd handshake failed");
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
@@ -393,7 +399,8 @@ public class SAMStreamSink {
/** @return our b64 dest or null */ /** @return our b64 dest or null */
private String handshake(OutputStream samOut, String version, boolean isMaster, private String handshake(OutputStream samOut, String version, boolean isMaster,
SAMEventHandler eventHandler, int mode, String user, String password) { SAMEventHandler eventHandler, int mode, String user, String password,
String sopts) {
synchronized (samOut) { synchronized (samOut) {
try { try {
if (user != null && password != null) if (user != null && password != null)
@@ -468,7 +475,7 @@ public class SAMStreamSink {
style = "DATAGRAM"; style = "DATAGRAM";
else else
style = "RAW"; style = "RAW";
String req = "SESSION CREATE STYLE=" + style + " DESTINATION=" + dest + " " + _conOptions + "\n"; String req = "SESSION CREATE STYLE=" + style + " DESTINATION=" + dest + ' ' + _conOptions + ' ' + sopts + '\n';
samOut.write(req.getBytes()); samOut.write(req.getBytes());
samOut.flush(); samOut.flush();
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))