* Streaming: New option i2p.streaming.answerPings (default true)

This commit is contained in:
zzz
2009-08-02 14:51:06 +00:00
parent d8d76fd327
commit 8d4a1899f2
3 changed files with 36 additions and 4 deletions

View File

@ -284,6 +284,8 @@ public class ConnectionManager {
// exporting non-public type through public API, this is a potential bug. // exporting non-public type through public API, this is a potential bug.
public ConnectionHandler getConnectionHandler() { return _connectionHandler; } public ConnectionHandler getConnectionHandler() { return _connectionHandler; }
public PacketQueue getPacketQueue() { return _outboundQueue; } public PacketQueue getPacketQueue() { return _outboundQueue; }
/** do we respond to pings that aren't on an existing connection? */
public boolean answerPings() { return _defaultOptions.getAnswerPings(); }
/** /**
* Something b0rked hard, so kill all of our connections without mercy. * Something b0rked hard, so kill all of our connections without mercy.

View File

@ -9,6 +9,7 @@ import java.util.Properties;
public class ConnectionOptions extends I2PSocketOptionsImpl { public class ConnectionOptions extends I2PSocketOptionsImpl {
private int _connectDelay; private int _connectDelay;
private boolean _fullySigned; private boolean _fullySigned;
private boolean _answerPings;
private volatile int _windowSize; private volatile int _windowSize;
private int _receiveWindow; private int _receiveWindow;
private int _profile; private int _profile;
@ -51,12 +52,15 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
public static final String PROP_MAX_WINDOW_SIZE = "i2p.streaming.maxWindowSize"; public static final String PROP_MAX_WINDOW_SIZE = "i2p.streaming.maxWindowSize";
public static final String PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR = "i2p.streaming.congestionAvoidanceGrowthRateFactor"; public static final String PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR = "i2p.streaming.congestionAvoidanceGrowthRateFactor";
public static final String PROP_SLOW_START_GROWTH_RATE_FACTOR = "i2p.streaming.slowStartGrowthRateFactor"; public static final String PROP_SLOW_START_GROWTH_RATE_FACTOR = "i2p.streaming.slowStartGrowthRateFactor";
public static final String PROP_ANSWER_PINGS = "i2p.streaming.answerPings";
private static final int TREND_COUNT = 3; private static final int TREND_COUNT = 3;
static final int INITIAL_WINDOW_SIZE = 6; static final int INITIAL_WINDOW_SIZE = 6;
static final int DEFAULT_MAX_SENDS = 8; static final int DEFAULT_MAX_SENDS = 8;
public static final int DEFAULT_INITIAL_RTT = 8*1000; public static final int DEFAULT_INITIAL_RTT = 8*1000;
static final int MIN_WINDOW_SIZE = 1; static final int MIN_WINDOW_SIZE = 1;
private static final boolean DEFAULT_ANSWER_PINGS = true;
// Syncronization fix, but doing it this way causes NPE... // Syncronization fix, but doing it this way causes NPE...
// private final int _trend[] = new int[TREND_COUNT]; // private final int _trend[] = new int[TREND_COUNT];
private int _trend[]; private int _trend[];
@ -198,6 +202,7 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
setSlowStartGrowthRateFactor(opts.getSlowStartGrowthRateFactor()); setSlowStartGrowthRateFactor(opts.getSlowStartGrowthRateFactor());
setWriteTimeout(opts.getWriteTimeout()); setWriteTimeout(opts.getWriteTimeout());
setReadTimeout(opts.getReadTimeout()); setReadTimeout(opts.getReadTimeout());
setAnswerPings(opts.getAnswerPings());
} }
} }
@ -221,8 +226,8 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
setInboundBufferSize(getMaxMessageSize() * (Connection.MAX_WINDOW_SIZE + 2)); setInboundBufferSize(getMaxMessageSize() * (Connection.MAX_WINDOW_SIZE + 2));
setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 1)); setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 1));
setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 1)); setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 1));
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT)); setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
} }
@Override @Override
@ -260,9 +265,10 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 2)); setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 2));
if (opts.contains(PROP_SLOW_START_GROWTH_RATE_FACTOR)) if (opts.contains(PROP_SLOW_START_GROWTH_RATE_FACTOR))
setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 2)); setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 2));
if (opts.containsKey(PROP_CONNECT_TIMEOUT)) if (opts.containsKey(PROP_CONNECT_TIMEOUT))
setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT)); setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
if (opts.containsKey(PROP_ANSWER_PINGS))
setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
} }
/** /**
@ -282,11 +288,22 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
* or can we deal with signatures on the SYN and FIN packets * or can we deal with signatures on the SYN and FIN packets
* only? * only?
* *
* There is no property name defined for this, so it's safe to
* say this is unused and always false.
*
* @return if we want signatures on all packets. * @return if we want signatures on all packets.
*/ */
public boolean getRequireFullySigned() { return _fullySigned; } public boolean getRequireFullySigned() { return _fullySigned; }
public void setRequireFullySigned(boolean sign) { _fullySigned = sign; } public void setRequireFullySigned(boolean sign) { _fullySigned = sign; }
/**
* Do we respond to a ping?
*
* @return if we do
*/
public boolean getAnswerPings() { return _answerPings; }
public void setAnswerPings(boolean yes) { _answerPings = yes; }
/** /**
* How many messages will we send before waiting for an ACK? * How many messages will we send before waiting for an ACK?
* *
@ -492,6 +509,13 @@ public class ConnectionOptions extends I2PSocketOptionsImpl {
return buf.toString(); return buf.toString();
} }
private static boolean getBool(Properties opts, String name, boolean defaultVal) {
if (opts == null) return defaultVal;
String val = opts.getProperty(name);
if (val == null) return defaultVal;
return Boolean.valueOf(val).booleanValue();
}
public static void main(String args[]) { public static void main(String args[]) {
Properties p = new Properties(); Properties p = new Properties();

View File

@ -129,7 +129,10 @@ public class PacketHandler {
private void receiveKnownCon(Connection con, Packet packet) { private void receiveKnownCon(Connection con, Packet packet) {
if (packet.isFlagSet(Packet.FLAG_ECHO)) { if (packet.isFlagSet(Packet.FLAG_ECHO)) {
if (packet.getSendStreamId() > 0) { if (packet.getSendStreamId() > 0) {
receivePing(packet); if (con.getOptions().getAnswerPings())
receivePing(packet);
else if (_log.shouldLog(Log.WARN))
_log.warn("Dropping Echo packet on existing con: " + packet);
} else if (packet.getReceiveStreamId() > 0) { } else if (packet.getReceiveStreamId() > 0) {
receivePong(packet); receivePong(packet);
} else { } else {
@ -230,7 +233,10 @@ public class PacketHandler {
private void receiveUnknownCon(Packet packet, long sendId, boolean queueIfNoConn) { private void receiveUnknownCon(Packet packet, long sendId, boolean queueIfNoConn) {
if (packet.isFlagSet(Packet.FLAG_ECHO)) { if (packet.isFlagSet(Packet.FLAG_ECHO)) {
if (packet.getSendStreamId() > 0) { if (packet.getSendStreamId() > 0) {
receivePing(packet); if (_manager.answerPings())
receivePing(packet);
else if (_log.shouldLog(Log.WARN))
_log.warn("Dropping Echo packet on unknown con: " + packet);
} else if (packet.getReceiveStreamId() > 0) { } else if (packet.getReceiveStreamId() > 0) {
receivePong(packet); receivePong(packet);
} else { } else {