diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java index ce528bacb0012ad9681bad64fd4bc7d565e122dd..08ac271b76c59ffcadc1dcd08351e2529c5dfe30 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelClientBase.java @@ -185,8 +185,10 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna * */ private I2PSocketOptions getDefaultOptions() { - I2PSocketOptions opts = new I2PSocketOptions(); - opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); + Properties defaultOpts = getTunnel().getClientOptions(); + I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts); + if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT)) + opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT); return opts; } diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java index cc2fcf1ab8b69755511663bb78175b2c45a0c67b..e17c09d06ceffbbb1ef0cb9d0082056673172a12 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/socks/SOCKSServer.java @@ -81,7 +81,7 @@ public abstract class SOCKSServer { if (connHostName.toLowerCase().endsWith(".i2p")) { _log.debug("connecting to " + connHostName + "..."); I2PSocketManager sm = I2PSocketManagerFactory.createManager(); - destSock = sm.connect(I2PTunnel.destFromName(connHostName), new I2PSocketOptions()); + destSock = sm.connect(I2PTunnel.destFromName(connHostName), null); confirmConnection(); _log.debug("connection confirmed - exchanging data..."); } else { diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManager.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManager.java index 8111d8c74678934d7bc9cf68e3e75d68f890429c..d14957c2d93b1b19f5de042a69e359af39b96e6f 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManager.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManager.java @@ -49,6 +49,9 @@ public interface I2PSocketManager { public void setDefaultOptions(I2PSocketOptions options); public I2PSocketOptions getDefaultOptions(); public I2PServerSocket getServerSocket(); + + public I2PSocketOptions buildOptions(); + public I2PSocketOptions buildOptions(Properties opts); /** * Create a new connected socket (block until the socket is created) diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java index af032c05edcd3ab89b1fe3983e19be4a114086ff..2300189c17c7eca320c1f2171708571007937e45 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerFactory.java @@ -106,7 +106,10 @@ public class I2PSocketManagerFactory { try { I2PSession session = client.createSession(myPrivateKeyStream, opts); session.connect(); - return createManager(session, opts, "manager"); + I2PSocketManager sockMgr = createManager(session, opts, "manager"); + if (sockMgr != null) + sockMgr.setDefaultOptions(sockMgr.buildOptions(opts)); + return sockMgr; } catch (I2PSessionException ise) { _log.error("Error creating session for socket manager", ise); return null; @@ -117,7 +120,7 @@ public class I2PSocketManagerFactory { if (false) { I2PSocketManagerImpl mgr = new I2PSocketManagerImpl(); mgr.setSession(session); - mgr.setDefaultOptions(new I2PSocketOptions()); + //mgr.setDefaultOptions(new I2PSocketOptions()); return mgr; } else { String classname = opts.getProperty(PROP_MANAGER, DEFAULT_MANAGER); diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerImpl.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerImpl.java index 3bfb656a85aaea01bb518d54f27954221da8e284..4af292085e16563f4d647af9285027eb40ccc754 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerImpl.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketManagerImpl.java @@ -77,7 +77,7 @@ public class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListene _outSockets = new HashMap(16); _acceptTimeout = ACCEPT_TIMEOUT_DEFAULT; setSession(session); - setDefaultOptions(new I2PSocketOptions()); + setDefaultOptions(buildOptions(opts)); _context.statManager().createRateStat("streaming.lifetime", "How long before the socket is closed?", "streaming", new long[] { 10*60*1000, 60*60*1000, 24*60*60*1000 }); _context.statManager().createRateStat("streaming.sent", "How many bytes are sent in the stream?", "streaming", new long[] { 10*60*1000, 60*60*1000, 24*60*60*1000 }); _context.statManager().createRateStat("streaming.received", "How many bytes are received in the stream?", "streaming", new long[] { 10*60*1000, 60*60*1000, 24*60*60*1000 }); @@ -433,6 +433,11 @@ public class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListene public I2PSocketOptions getDefaultOptions() { return _defaultOptions; } + + public I2PSocketOptions buildOptions() { return buildOptions(null); } + public I2PSocketOptions buildOptions(Properties opts) { + return new I2PSocketOptionsImpl(opts); + } public I2PServerSocket getServerSocket() { if (_serverSocket == null) { diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java index 288a6e4d42c5ae0b5ed4a1c69a40a5aa1cadd301..a19cbd192c1bf5e3d3b50e7215073151f0d8db05 100644 --- a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptions.java @@ -1,98 +1,43 @@ package net.i2p.client.streaming; -import java.util.Iterator; import java.util.Properties; /** * Define the configuration for streaming and verifying data on the socket. * */ -public class I2PSocketOptions { - private long _connectTimeout; - private long _readTimeout; - private long _writeTimeout; - private int _maxBufferSize; - - public static final int DEFAULT_BUFFER_SIZE = 1024*64; - public static final int DEFAULT_WRITE_TIMEOUT = 60*1000; - public static final int DEFAULT_CONNECT_TIMEOUT = 60*1000; - +public interface I2PSocketOptions { public static final String PROP_BUFFER_SIZE = "i2p.streaming.bufferSize"; public static final String PROP_CONNECT_TIMEOUT = "i2p.streaming.connectTimeout"; public static final String PROP_READ_TIMEOUT = "i2p.streaming.readTimeout"; public static final String PROP_WRITE_TIMEOUT = "i2p.streaming.writeTimeout"; - public I2PSocketOptions() { - this(System.getProperties()); - } - - public I2PSocketOptions(I2PSocketOptions opts) { - this(System.getProperties()); - _connectTimeout = opts.getConnectTimeout(); - _readTimeout = opts.getReadTimeout(); - _writeTimeout = opts.getWriteTimeout(); - _maxBufferSize = opts.getMaxBufferSize(); - } - - public I2PSocketOptions(Properties opts) { - init(opts); - } - - protected void init(Properties opts) { - _maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE); - _connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT); - _readTimeout = getInt(opts, PROP_READ_TIMEOUT, -1); - _writeTimeout = getInt(opts, PROP_WRITE_TIMEOUT, DEFAULT_WRITE_TIMEOUT); - } - - protected int getInt(Properties opts, String name, int defaultVal) { - if (opts == null) return defaultVal; - String val = opts.getProperty(name); - if (val == null) { - return defaultVal; - } else { - try { - return Integer.parseInt(val); - } catch (NumberFormatException nfe) { - return defaultVal; - } - } - } - /** * How long we will wait for the ACK from a SYN, in milliseconds. * * @return milliseconds to wait, or -1 if we will wait indefinitely */ - public long getConnectTimeout() { - return _connectTimeout; - } + public long getConnectTimeout(); /** * Define how long we will wait for the ACK from a SYN, in milliseconds. * */ - public void setConnectTimeout(long ms) { - _connectTimeout = ms; - } + public void setConnectTimeout(long ms); /** * What is the longest we'll block on the input stream while waiting * for more data. If this value is exceeded, the read() throws * InterruptedIOException */ - public long getReadTimeout() { - return _readTimeout; - } + public long getReadTimeout(); /** * What is the longest we'll block on the input stream while waiting * for more data. If this value is exceeded, the read() throws * InterruptedIOException */ - public void setReadTimeout(long ms) { - _readTimeout = ms; - } + public void setReadTimeout(long ms); /** * How much data will we accept that hasn't been written out yet. After @@ -102,9 +47,7 @@ public class I2PSocketOptions { * * @return buffer size limit, in bytes */ - public int getMaxBufferSize() { - return _maxBufferSize; - } + public int getMaxBufferSize(); /** * How much data will we accept that hasn't been written out yet. After @@ -113,9 +56,7 @@ public class I2PSocketOptions { * less than or equal to zero, there is no limit (warning: can eat ram) * */ - public void setMaxBufferSize(int numBytes) { - _maxBufferSize = numBytes; - } + public void setMaxBufferSize(int numBytes); /** * What is the longest we'll block on the output stream while waiting @@ -123,9 +64,7 @@ public class I2PSocketOptions { * InterruptedIOException. If this is less than or equal to zero, there * is no timeout. */ - public long getWriteTimeout() { - return _writeTimeout; - } + public long getWriteTimeout(); /** * What is the longest we'll block on the output stream while waiting @@ -133,7 +72,5 @@ public class I2PSocketOptions { * InterruptedIOException. If this is less than or equal to zero, there * is no timeout. */ - public void setWriteTimeout(long ms) { - _writeTimeout = ms; - } + public void setWriteTimeout(long ms); } diff --git a/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptionsImpl.java b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptionsImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..e8700a01a2f4050e1535cd099ee8e970296cecf2 --- /dev/null +++ b/apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketOptionsImpl.java @@ -0,0 +1,136 @@ +package net.i2p.client.streaming; + +import java.util.Iterator; +import java.util.Properties; + +/** + * Define the configuration for streaming and verifying data on the socket. + * + */ +public class I2PSocketOptionsImpl implements I2PSocketOptions { + private long _connectTimeout; + private long _readTimeout; + private long _writeTimeout; + private int _maxBufferSize; + + public static final int DEFAULT_BUFFER_SIZE = 1024*64; + public static final int DEFAULT_WRITE_TIMEOUT = 60*1000; + public static final int DEFAULT_CONNECT_TIMEOUT = 60*1000; + + public I2PSocketOptionsImpl() { + this(System.getProperties()); + } + + public I2PSocketOptionsImpl(I2PSocketOptions opts) { + this(System.getProperties()); + if (opts != null) { + _connectTimeout = opts.getConnectTimeout(); + _readTimeout = opts.getReadTimeout(); + _writeTimeout = opts.getWriteTimeout(); + _maxBufferSize = opts.getMaxBufferSize(); + } + } + + public I2PSocketOptionsImpl(Properties opts) { + init(opts); + } + + protected void init(Properties opts) { + _maxBufferSize = getInt(opts, PROP_BUFFER_SIZE, DEFAULT_BUFFER_SIZE); + _connectTimeout = getInt(opts, PROP_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT); + _readTimeout = getInt(opts, PROP_READ_TIMEOUT, -1); + _writeTimeout = getInt(opts, PROP_WRITE_TIMEOUT, DEFAULT_WRITE_TIMEOUT); + } + + protected int getInt(Properties opts, String name, int defaultVal) { + if (opts == null) return defaultVal; + String val = opts.getProperty(name); + if (val == null) { + return defaultVal; + } else { + try { + return Integer.parseInt(val); + } catch (NumberFormatException nfe) { + return defaultVal; + } + } + } + + /** + * How long we will wait for the ACK from a SYN, in milliseconds. + * + * @return milliseconds to wait, or -1 if we will wait indefinitely + */ + public long getConnectTimeout() { + return _connectTimeout; + } + + /** + * Define how long we will wait for the ACK from a SYN, in milliseconds. + * + */ + public void setConnectTimeout(long ms) { + _connectTimeout = ms; + } + + /** + * What is the longest we'll block on the input stream while waiting + * for more data. If this value is exceeded, the read() throws + * InterruptedIOException + */ + public long getReadTimeout() { + return _readTimeout; + } + + /** + * What is the longest we'll block on the input stream while waiting + * for more data. If this value is exceeded, the read() throws + * InterruptedIOException + */ + public void setReadTimeout(long ms) { + _readTimeout = ms; + } + + /** + * How much data will we accept that hasn't been written out yet. After + * this amount has been exceeded, subsequent .write calls will block until + * either some data is removed or the connection is closed. If this is + * less than or equal to zero, there is no limit (warning: can eat ram) + * + * @return buffer size limit, in bytes + */ + public int getMaxBufferSize() { + return _maxBufferSize; + } + + /** + * How much data will we accept that hasn't been written out yet. After + * this amount has been exceeded, subsequent .write calls will block until + * either some data is removed or the connection is closed. If this is + * less than or equal to zero, there is no limit (warning: can eat ram) + * + */ + public void setMaxBufferSize(int numBytes) { + _maxBufferSize = numBytes; + } + + /** + * What is the longest we'll block on the output stream while waiting + * for the data to flush. If this value is exceeded, the write() throws + * InterruptedIOException. If this is less than or equal to zero, there + * is no timeout. + */ + public long getWriteTimeout() { + return _writeTimeout; + } + + /** + * What is the longest we'll block on the output stream while waiting + * for the data to flush. If this value is exceeded, the write() throws + * InterruptedIOException. If this is less than or equal to zero, there + * is no timeout. + */ + public void setWriteTimeout(long ms) { + _writeTimeout = ms; + } +} diff --git a/history.txt b/history.txt index c0ad0c5274a0d8e9b09e50b180a9518fad3a597b..b7f1041b1d776382415be881e1ff7970ada4b125 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,8 @@ -$Id: history.txt,v 1.71 2004/11/15 09:35:18 jrandom Exp $ +$Id: history.txt,v 1.72 2004/11/16 08:45:40 jrandom Exp $ + +2004-11-16 jrandom + * Clean up the propogation of i2psocket options so that various streaming + libs can honor them more precisely 2004-11-16 jrandom * Minor logging update diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index cc4e7317121f2394b483d51dd7cec9893260073d..5c4c9f7460a007d3db8071ef6a46fbffce638a7f 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -15,9 +15,9 @@ import net.i2p.CoreVersion; * */ public class RouterVersion { - public final static String ID = "$Revision: 1.76 $ $Date: 2004/11/15 09:35:18 $"; + public final static String ID = "$Revision: 1.77 $ $Date: 2004/11/16 08:45:40 $"; public final static String VERSION = "0.4.1.4"; - public final static long BUILD = 5; + public final static long BUILD = 6; public static void main(String args[]) { System.out.println("I2P Router version: " + VERSION); System.out.println("Router ID: " + RouterVersion.ID);