* 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

@ -122,7 +122,7 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer {
Properties opts = getTunnel().getClientOptions();
String spoofHost;
int ourPort = socket.getLocalPort();
if (ourPort != 80 && ourPort > 0 && ourPort < 65535 && opts != null) {
if (ourPort != 80 && ourPort > 0 && ourPort <= 65535 && opts != null) {
String portSpoof = opts.getProperty("spoofedHost." + ourPort);
if (portSpoof != null)
spoofHost = portSpoof.trim();

View File

@ -111,7 +111,7 @@ public class I2PSocketEepGet extends EepGet {
if ("http".equals(url.getProtocol())) {
String host = url.getHost();
int port = url.getPort();
if (port <= 0 || port >= 65535)
if (port <= 0 || port > 65535)
port = 80;
// HTTP Proxy compatibility http://i2p/B64KEY/blah

View File

@ -105,6 +105,9 @@ public interface I2PSocketOptions {
/**
* The local port.
* Zero (default) means you will receive traffic on all ports.
* Nonzero means you will get traffic ONLY for that port, use with care,
* as most applications do not specify a remote port.
* @param port 0 - 65535
* @since 0.8.9
*/

View File

@ -200,6 +200,9 @@ class I2PSocketOptionsImpl implements I2PSocketOptions {
/**
* The local port.
* Zero (default) means you will receive traffic on all ports.
* Nonzero means you will get traffic ONLY for that port, use with care,
* as most applications do not specify a remote port.
* @param port 0 - 65535
* @since 0.8.9
*/

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?
*

View File

@ -38,6 +38,9 @@ public interface I2PSession {
/** Send a new message to the given destination, containing the specified
* payload, returning true if the router feels confident that the message
* was delivered.
*
* WARNING: It is recommended that you use a method that specifies the protocol and ports.
*
* @param dest location to send the message
* @param payload body of the message to be sent (unencrypted)
* @return whether it was accepted by the router for delivery or not
@ -149,6 +152,9 @@ public interface I2PSession {
public void reportAbuse(int msgId, int severity) throws I2PSessionException;
/** Instruct the I2PSession where it should send event notifications
*
* WARNING: It is recommended that you use a method that specifies the protocol and ports.
*
* @param lsnr listener to retrieve events
*/
public void setSessionListener(I2PSessionListener lsnr);