* Streaming:

- Listen only on local port if set
   - Listen only for streaming protocol if configured (new option)
   - Javadocs re: ports
This commit is contained in:
zzz
2012-06-19 20:26:46 +00:00
parent 48f29ff1b8
commit 129b16d93d
7 changed files with 43 additions and 3 deletions

View File

@ -67,7 +67,10 @@ class ConnectionManager {
// TODO change proto to PROTO_STREAMING someday.
// Right now we get everything, and rely on Datagram to specify PROTO_UDP.
// PacketQueue has sent PROTO_STREAMING since the beginning of mux support (0.7.1)
_session.addMuxedSessionListener(_messageHandler, I2PSession.PROTO_ANY, I2PSession.PORT_ANY);
// As of 0.9.1, new option to enforce streaming protocol, off by default
// As of 0.9.1, listen on configured port (default 0 = all)
int protocol = defaultOptions.getEnforceProtocol() ? I2PSession.PROTO_STREAMING : I2PSession.PROTO_ANY;
_session.addMuxedSessionListener(_messageHandler, protocol, defaultOptions.getLocalPort());
_outboundQueue = new PacketQueue(_context, _session, this);
/** Socket timeout for accept() */
_soTimeout = -1;

View File

@ -19,6 +19,7 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
private int _connectDelay;
private boolean _fullySigned;
private boolean _answerPings;
private boolean _enforceProto;
private volatile int _windowSize;
private int _receiveWindow;
private int _profile;
@ -87,6 +88,8 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
public static final String PROP_MAX_TOTAL_CONNS_MIN = "i2p.streaming.maxTotalConnsPerMinute";
public static final String PROP_MAX_TOTAL_CONNS_HOUR = "i2p.streaming.maxTotalConnsPerHour";
public static final String PROP_MAX_TOTAL_CONNS_DAY = "i2p.streaming.maxTotalConnsPerDay";
/** @since 0.9.1 */
public static final String PROP_ENFORCE_PROTO = "i2p.streaming.enforceProtocol";
private static final int TREND_COUNT = 3;
static final int INITIAL_WINDOW_SIZE = 6;
@ -95,6 +98,11 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
public static final int DEFAULT_INITIAL_ACK_DELAY = 2*1000;
static final int MIN_WINDOW_SIZE = 1;
private static final boolean DEFAULT_ANSWER_PINGS = true;
/**
* If PROTO is enforced, we cannot communicate with destinations earlier than version 0.7.1.
* @since 0.9.1
*/
private static final boolean DEFAULT_ENFORCE_PROTO = true;
// Syncronization fix, but doing it this way causes NPE...
// FIXME private final int _trend[] = new int[TREND_COUNT]; FIXME
@ -284,6 +292,7 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
//setWriteTimeout(opts.getWriteTimeout());
//setReadTimeout(opts.getReadTimeout());
setAnswerPings(opts.getAnswerPings());
setEnforceProtocol(opts.getEnforceProtocol());
initLists(opts);
_maxConnsPerMinute = opts.getMaxConnsPerMinute();
_maxConnsPerHour = opts.getMaxConnsPerHour();
@ -317,6 +326,7 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
// overrides default in super()
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
setEnforceProtocol(getBool(opts, PROP_ENFORCE_PROTO, DEFAULT_ENFORCE_PROTO));
initLists(opts);
_maxConnsPerMinute = getInt(opts, PROP_MAX_CONNS_MIN, 0);
_maxConnsPerHour = getInt(opts, PROP_MAX_CONNS_HOUR, 0);
@ -371,6 +381,8 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
if (opts.containsKey(PROP_ANSWER_PINGS))
setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
if (opts.containsKey(PROP_ENFORCE_PROTO))
setEnforceProtocol(getBool(opts, PROP_ENFORCE_PROTO, DEFAULT_ENFORCE_PROTO));
initLists(opts);
if (opts.containsKey(PROP_MAX_CONNS_MIN))
_maxConnsPerMinute = getInt(opts, PROP_MAX_CONNS_MIN, 0);
@ -420,6 +432,19 @@ class ConnectionOptions extends I2PSocketOptionsImpl {
public boolean getAnswerPings() { return _answerPings; }
public void setAnswerPings(boolean yes) { _answerPings = yes; }
/**
* Do we receive all traffic, or only traffic marked with I2PSession.PROTO_STREAMING (6) ?
* Default false.
* If PROTO is enforced, we cannot communicate with destinations earlier than version 0.7.1
* (released March 2009), which is when streaming started sending the PROTO_STREAMING indication.
* Set to true if you are running multiple protocols on a single Destination.
*
* @return if we do
* @since 0.9.1
*/
public boolean getEnforceProtocol() { return _enforceProto; }
public void setEnforceProtocol(boolean yes) { _enforceProto = yes; }
/**
* How many messages will we send before waiting for an ACK?
*