Changeset 8d4a189


Ignore:
Timestamp:
Aug 2, 2009 2:51:06 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d84b1125
Parents:
d8d76fd
Message:
  • Streaming: New option i2p.streaming.answerPings (default true)
Location:
apps/streaming/java/src/net/i2p/client/streaming
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionManager.java

    rd8d76fd r8d4a189  
    285285    public ConnectionHandler getConnectionHandler() { return _connectionHandler; }
    286286    public PacketQueue getPacketQueue() { return _outboundQueue; }
     287    /** do we respond to pings that aren't on an existing connection? */
     288    public boolean answerPings() { return _defaultOptions.getAnswerPings(); }
    287289   
    288290    /**
  • apps/streaming/java/src/net/i2p/client/streaming/ConnectionOptions.java

    rd8d76fd r8d4a189  
    1010    private int _connectDelay;
    1111    private boolean _fullySigned;
     12    private boolean _answerPings;
    1213    private volatile int _windowSize;
    1314    private int _receiveWindow;
     
    5253    public static final String PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR = "i2p.streaming.congestionAvoidanceGrowthRateFactor";
    5354    public static final String PROP_SLOW_START_GROWTH_RATE_FACTOR = "i2p.streaming.slowStartGrowthRateFactor";
     55    public static final String PROP_ANSWER_PINGS = "i2p.streaming.answerPings";
    5456   
    5557    private static final int TREND_COUNT = 3;
     
    5860    public static final int DEFAULT_INITIAL_RTT = 8*1000;   
    5961    static final int MIN_WINDOW_SIZE = 1;
     62    private static final boolean DEFAULT_ANSWER_PINGS = true;
     63
    6064    // Syncronization fix, but doing it this way causes NPE...
    6165    // private final int _trend[] = new int[TREND_COUNT];
     
    199203            setWriteTimeout(opts.getWriteTimeout());
    200204            setReadTimeout(opts.getReadTimeout());
     205            setAnswerPings(opts.getAnswerPings());
    201206        }
    202207    }
     
    222227        setCongestionAvoidanceGrowthRateFactor(getInt(opts, PROP_CONGESTION_AVOIDANCE_GROWTH_RATE_FACTOR, 1));
    223228        setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 1));
    224        
    225229        setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
     230        setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
    226231    }
    227232   
     
    261266        if (opts.contains(PROP_SLOW_START_GROWTH_RATE_FACTOR))
    262267            setSlowStartGrowthRateFactor(getInt(opts, PROP_SLOW_START_GROWTH_RATE_FACTOR, 2));
    263        
    264268        if (opts.containsKey(PROP_CONNECT_TIMEOUT))
    265269            setConnectTimeout(getInt(opts, PROP_CONNECT_TIMEOUT, Connection.DISCONNECT_TIMEOUT));
     270        if (opts.containsKey(PROP_ANSWER_PINGS))
     271            setAnswerPings(getBool(opts, PROP_ANSWER_PINGS, DEFAULT_ANSWER_PINGS));
    266272    }
    267273   
     
    283289     * only?
    284290     *
     291     * There is no property name defined for this, so it's safe to
     292     * say this is unused and always false.
     293     *
    285294     * @return if we want signatures on all packets.
    286295     */
    287296    public boolean getRequireFullySigned() { return _fullySigned; }
    288297    public void setRequireFullySigned(boolean sign) { _fullySigned = sign; }
     298   
     299    /**
     300     * Do we respond to a ping?
     301     *
     302     * @return if we do
     303     */
     304    public boolean getAnswerPings() { return _answerPings; }
     305    public void setAnswerPings(boolean yes) { _answerPings = yes; }
    289306   
    290307    /**
     
    493510    }
    494511   
     512    private static boolean getBool(Properties opts, String name, boolean defaultVal) {
     513        if (opts == null) return defaultVal;
     514        String val = opts.getProperty(name);
     515        if (val == null)  return defaultVal;
     516        return Boolean.valueOf(val).booleanValue();
     517    }
     518
    495519    public static void main(String args[]) {
    496520        Properties p = new Properties();
  • apps/streaming/java/src/net/i2p/client/streaming/PacketHandler.java

    rd8d76fd r8d4a189  
    130130        if (packet.isFlagSet(Packet.FLAG_ECHO)) {
    131131            if (packet.getSendStreamId() > 0) {
    132                 receivePing(packet);
     132                if (con.getOptions().getAnswerPings())
     133                    receivePing(packet);
     134                else if (_log.shouldLog(Log.WARN))
     135                    _log.warn("Dropping Echo packet on existing con: " + packet);
    133136            } else if (packet.getReceiveStreamId() > 0) {
    134137                receivePong(packet);
     
    231234        if (packet.isFlagSet(Packet.FLAG_ECHO)) {
    232235            if (packet.getSendStreamId() > 0) {
    233                 receivePing(packet);
     236                if (_manager.answerPings())
     237                    receivePing(packet);
     238                else if (_log.shouldLog(Log.WARN))
     239                    _log.warn("Dropping Echo packet on unknown con: " + packet);
    234240            } else if (packet.getReceiveStreamId() > 0) {
    235241                receivePong(packet);
Note: See TracChangeset for help on using the changeset viewer.