forked from I2P_Developers/i2p.i2p
2004-11-16 jrandom
* Clean up the propogation of i2psocket options so that various streaming libs can honor them more precisely
This commit is contained in:
@ -185,8 +185,10 @@ public abstract class I2PTunnelClientBase extends I2PTunnelTask implements Runna
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private I2PSocketOptions getDefaultOptions() {
|
private I2PSocketOptions getDefaultOptions() {
|
||||||
I2PSocketOptions opts = new I2PSocketOptions();
|
Properties defaultOpts = getTunnel().getClientOptions();
|
||||||
opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);
|
I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
|
||||||
|
if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT))
|
||||||
|
opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);
|
||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ public abstract class SOCKSServer {
|
|||||||
if (connHostName.toLowerCase().endsWith(".i2p")) {
|
if (connHostName.toLowerCase().endsWith(".i2p")) {
|
||||||
_log.debug("connecting to " + connHostName + "...");
|
_log.debug("connecting to " + connHostName + "...");
|
||||||
I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
I2PSocketManager sm = I2PSocketManagerFactory.createManager();
|
||||||
destSock = sm.connect(I2PTunnel.destFromName(connHostName), new I2PSocketOptions());
|
destSock = sm.connect(I2PTunnel.destFromName(connHostName), null);
|
||||||
confirmConnection();
|
confirmConnection();
|
||||||
_log.debug("connection confirmed - exchanging data...");
|
_log.debug("connection confirmed - exchanging data...");
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,6 +50,9 @@ public interface I2PSocketManager {
|
|||||||
public I2PSocketOptions getDefaultOptions();
|
public I2PSocketOptions getDefaultOptions();
|
||||||
public I2PServerSocket getServerSocket();
|
public I2PServerSocket getServerSocket();
|
||||||
|
|
||||||
|
public I2PSocketOptions buildOptions();
|
||||||
|
public I2PSocketOptions buildOptions(Properties opts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new connected socket (block until the socket is created)
|
* Create a new connected socket (block until the socket is created)
|
||||||
*
|
*
|
||||||
|
@ -106,7 +106,10 @@ public class I2PSocketManagerFactory {
|
|||||||
try {
|
try {
|
||||||
I2PSession session = client.createSession(myPrivateKeyStream, opts);
|
I2PSession session = client.createSession(myPrivateKeyStream, opts);
|
||||||
session.connect();
|
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) {
|
} catch (I2PSessionException ise) {
|
||||||
_log.error("Error creating session for socket manager", ise);
|
_log.error("Error creating session for socket manager", ise);
|
||||||
return null;
|
return null;
|
||||||
@ -117,7 +120,7 @@ public class I2PSocketManagerFactory {
|
|||||||
if (false) {
|
if (false) {
|
||||||
I2PSocketManagerImpl mgr = new I2PSocketManagerImpl();
|
I2PSocketManagerImpl mgr = new I2PSocketManagerImpl();
|
||||||
mgr.setSession(session);
|
mgr.setSession(session);
|
||||||
mgr.setDefaultOptions(new I2PSocketOptions());
|
//mgr.setDefaultOptions(new I2PSocketOptions());
|
||||||
return mgr;
|
return mgr;
|
||||||
} else {
|
} else {
|
||||||
String classname = opts.getProperty(PROP_MANAGER, DEFAULT_MANAGER);
|
String classname = opts.getProperty(PROP_MANAGER, DEFAULT_MANAGER);
|
||||||
|
@ -77,7 +77,7 @@ public class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListene
|
|||||||
_outSockets = new HashMap(16);
|
_outSockets = new HashMap(16);
|
||||||
_acceptTimeout = ACCEPT_TIMEOUT_DEFAULT;
|
_acceptTimeout = ACCEPT_TIMEOUT_DEFAULT;
|
||||||
setSession(session);
|
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.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.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 });
|
_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 });
|
||||||
@ -434,6 +434,11 @@ public class I2PSocketManagerImpl implements I2PSocketManager, I2PSessionListene
|
|||||||
return _defaultOptions;
|
return _defaultOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public I2PSocketOptions buildOptions() { return buildOptions(null); }
|
||||||
|
public I2PSocketOptions buildOptions(Properties opts) {
|
||||||
|
return new I2PSocketOptionsImpl(opts);
|
||||||
|
}
|
||||||
|
|
||||||
public I2PServerSocket getServerSocket() {
|
public I2PServerSocket getServerSocket() {
|
||||||
if (_serverSocket == null) {
|
if (_serverSocket == null) {
|
||||||
_serverSocket = new I2PServerSocketImpl(this);
|
_serverSocket = new I2PServerSocketImpl(this);
|
||||||
|
@ -1,98 +1,43 @@
|
|||||||
package net.i2p.client.streaming;
|
package net.i2p.client.streaming;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the configuration for streaming and verifying data on the socket.
|
* Define the configuration for streaming and verifying data on the socket.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class I2PSocketOptions {
|
public interface 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 static final String PROP_BUFFER_SIZE = "i2p.streaming.bufferSize";
|
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_CONNECT_TIMEOUT = "i2p.streaming.connectTimeout";
|
||||||
public static final String PROP_READ_TIMEOUT = "i2p.streaming.readTimeout";
|
public static final String PROP_READ_TIMEOUT = "i2p.streaming.readTimeout";
|
||||||
public static final String PROP_WRITE_TIMEOUT = "i2p.streaming.writeTimeout";
|
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.
|
* How long we will wait for the ACK from a SYN, in milliseconds.
|
||||||
*
|
*
|
||||||
* @return milliseconds to wait, or -1 if we will wait indefinitely
|
* @return milliseconds to wait, or -1 if we will wait indefinitely
|
||||||
*/
|
*/
|
||||||
public long getConnectTimeout() {
|
public long getConnectTimeout();
|
||||||
return _connectTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define how long we will wait for the ACK from a SYN, in milliseconds.
|
* Define how long we will wait for the ACK from a SYN, in milliseconds.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void setConnectTimeout(long ms) {
|
public void setConnectTimeout(long ms);
|
||||||
_connectTimeout = ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What is the longest we'll block on the input stream while waiting
|
* What is the longest we'll block on the input stream while waiting
|
||||||
* for more data. If this value is exceeded, the read() throws
|
* for more data. If this value is exceeded, the read() throws
|
||||||
* InterruptedIOException
|
* InterruptedIOException
|
||||||
*/
|
*/
|
||||||
public long getReadTimeout() {
|
public long getReadTimeout();
|
||||||
return _readTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What is the longest we'll block on the input stream while waiting
|
* What is the longest we'll block on the input stream while waiting
|
||||||
* for more data. If this value is exceeded, the read() throws
|
* for more data. If this value is exceeded, the read() throws
|
||||||
* InterruptedIOException
|
* InterruptedIOException
|
||||||
*/
|
*/
|
||||||
public void setReadTimeout(long ms) {
|
public void setReadTimeout(long ms);
|
||||||
_readTimeout = ms;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much data will we accept that hasn't been written out yet. After
|
* 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
|
* @return buffer size limit, in bytes
|
||||||
*/
|
*/
|
||||||
public int getMaxBufferSize() {
|
public int getMaxBufferSize();
|
||||||
return _maxBufferSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How much data will we accept that hasn't been written out yet. After
|
* 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)
|
* less than or equal to zero, there is no limit (warning: can eat ram)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void setMaxBufferSize(int numBytes) {
|
public void setMaxBufferSize(int numBytes);
|
||||||
_maxBufferSize = numBytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What is the longest we'll block on the output stream while waiting
|
* 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
|
* InterruptedIOException. If this is less than or equal to zero, there
|
||||||
* is no timeout.
|
* is no timeout.
|
||||||
*/
|
*/
|
||||||
public long getWriteTimeout() {
|
public long getWriteTimeout();
|
||||||
return _writeTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* What is the longest we'll block on the output stream while waiting
|
* 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
|
* InterruptedIOException. If this is less than or equal to zero, there
|
||||||
* is no timeout.
|
* is no timeout.
|
||||||
*/
|
*/
|
||||||
public void setWriteTimeout(long ms) {
|
public void setWriteTimeout(long ms);
|
||||||
_writeTimeout = ms;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
2004-11-16 jrandom
|
||||||
* Minor logging update
|
* Minor logging update
|
||||||
|
@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RouterVersion {
|
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 String VERSION = "0.4.1.4";
|
||||||
public final static long BUILD = 5;
|
public final static long BUILD = 6;
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
System.out.println("I2P Router version: " + VERSION);
|
System.out.println("I2P Router version: " + VERSION);
|
||||||
System.out.println("Router ID: " + RouterVersion.ID);
|
System.out.println("Router ID: " + RouterVersion.ID);
|
||||||
|
Reference in New Issue
Block a user