Changeset efe3696a


Ignore:
Timestamp:
Jan 17, 2018 4:23:54 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
cae1fe1
Parents:
889b5ae
Message:

i2ptunnel: Set defaults for limits

Location:
apps/i2ptunnel/java/src/net/i2p/i2ptunnel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/TunnelController.java

    r889b5ae refe3696a  
    8686    public static final String PROP_TARGET_PORT = "targetPort";
    8787    public static final String PROP_TYPE = "type";
     88   
     89    /**
     90     * all of these are @since 0.9.33 (moved from TunnelConfig)
     91     */
     92    public static final String PROP_MAX_CONNS_MIN = "i2p.streaming.maxConnsPerMinute";
     93    public static final String PROP_MAX_CONNS_HOUR = "i2p.streaming.maxConnsPerHour";
     94    public static final String PROP_MAX_CONNS_DAY = "i2p.streaming.maxConnsPerDay";
     95    public static final String PROP_MAX_TOTAL_CONNS_MIN = "i2p.streaming.maxTotalConnsPerMinute";
     96    public static final String PROP_MAX_TOTAL_CONNS_HOUR = "i2p.streaming.maxTotalConnsPerHour";
     97    public static final String PROP_MAX_TOTAL_CONNS_DAY = "i2p.streaming.maxTotalConnsPerDay";
     98    public static final String PROP_MAX_STREAMS = "i2p.streaming.maxConcurrentStreams";
     99    public static final String PROP_LIMITS_SET = "i2p.streaming.limitsManuallySet";
     100    public static final int DEFAULT_MAX_CONNS_MIN = 10;
     101    public static final int DEFAULT_MAX_CONNS_HOUR = 40;
     102    public static final int DEFAULT_MAX_CONNS_DAY = 100;
     103    public static final int DEFAULT_MAX_TOTAL_CONNS_MIN = 25;
     104    public static final int DEFAULT_MAX_TOTAL_CONNS_HOUR = 0;
     105    public static final int DEFAULT_MAX_TOTAL_CONNS_DAY = 0;
     106    public static final int DEFAULT_MAX_STREAMS = 20;
    88107
    89108    /** @since 0.9.14 */
     
    97116    /** @since 0.9.30 */
    98117    private static final String OPT_ALT_PKF = PFX_OPTION + I2PTunnelServer.PROP_ALT_PKF;
     118
     119    /**
     120     * all of these are @since 0.9.33
     121     */
     122    private static final String OPT_MAX_CONNS_MIN = PFX_OPTION + PROP_MAX_CONNS_MIN;
     123    private static final String OPT_MAX_CONNS_HOUR = PFX_OPTION + PROP_MAX_CONNS_HOUR;
     124    private static final String OPT_MAX_CONNS_DAY = PFX_OPTION + PROP_MAX_CONNS_DAY;
     125    private static final String OPT_MAX_TOTAL_CONNS_MIN = PFX_OPTION + PROP_MAX_TOTAL_CONNS_MIN;
     126    private static final String OPT_MAX_TOTAL_CONNS_HOUR = PFX_OPTION + PROP_MAX_TOTAL_CONNS_HOUR;
     127    private static final String OPT_MAX_TOTAL_CONNS_DAY = PFX_OPTION + PROP_MAX_TOTAL_CONNS_DAY;
     128    private static final String OPT_MAX_STREAMS = PFX_OPTION + PROP_MAX_STREAMS;
     129    private static final String OPT_LIMITS_SET = PFX_OPTION + PROP_LIMITS_SET;
     130    public static final String OPT_POST_MAX = PFX_OPTION + I2PTunnelHTTPServer.OPT_POST_MAX;
     131    public static final String OPT_POST_TOTAL_MAX = PFX_OPTION + I2PTunnelHTTPServer.OPT_POST_TOTAL_MAX;
    99132
    100133    /** all of these @since 0.9.14 */
     
    791824                    _config.setProperty(OPT_SIG_TYPE, PREFERRED_SIGTYPE.name());
    792825            }
     826            if (!isClient(type)) {
     827                String p1 = _config.getProperty(OPT_MAX_CONNS_MIN, "0");
     828                String p2 = _config.getProperty(OPT_MAX_CONNS_HOUR, "0");
     829                String p3 = _config.getProperty(OPT_MAX_CONNS_DAY, "0");
     830                String p4 = _config.getProperty(OPT_MAX_TOTAL_CONNS_MIN, "0");
     831                String p5 = _config.getProperty(OPT_MAX_TOTAL_CONNS_HOUR, "0");
     832                String p6 = _config.getProperty(OPT_MAX_TOTAL_CONNS_DAY, "0");
     833                String p7 = _config.getProperty(OPT_MAX_STREAMS, "0");
     834                String p8 = _config.getProperty(OPT_LIMITS_SET, "false");
     835                if (p1.equals("0") && p2.equals("0") && p3.equals("0") &&
     836                    p4.equals("0") && p5.equals("0") && p6.equals("0") &&
     837                    p7.equals("0") && !p8.equals("true")) {
     838                    // No limits set, let's set some defaults
     839                    _config.setProperty(OPT_MAX_CONNS_MIN, Integer.toString(DEFAULT_MAX_CONNS_MIN));
     840                    _config.setProperty(OPT_MAX_CONNS_HOUR, Integer.toString(DEFAULT_MAX_CONNS_HOUR));
     841                    _config.setProperty(OPT_MAX_CONNS_DAY, Integer.toString(DEFAULT_MAX_CONNS_DAY));
     842                    _config.setProperty(OPT_MAX_TOTAL_CONNS_MIN, Integer.toString(DEFAULT_MAX_TOTAL_CONNS_MIN));
     843                    _config.setProperty(OPT_MAX_STREAMS, Integer.toString(DEFAULT_MAX_STREAMS));
     844                }
     845                if (type.equals(TYPE_HTTP_SERVER) && !p8.equals("true")) {
     846                    String p9 = _config.getProperty(OPT_POST_MAX, "0");
     847                    String p10 = _config.getProperty(OPT_POST_TOTAL_MAX, "0");
     848                    if (p9.equals("0") && p10.equals("0")) {
     849                        _config.setProperty(OPT_POST_MAX, Integer.toString(I2PTunnelHTTPServer.DEFAULT_POST_MAX));
     850                        _config.setProperty(OPT_POST_TOTAL_MAX, Integer.toString(I2PTunnelHTTPServer.DEFAULT_POST_TOTAL_MAX));
     851                    }
     852                }
     853            }
    793854        }
    794855
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/GeneralHelper.java

    r889b5ae refe3696a  
    663663    /** all of these are @since 0.8.3 */
    664664    public int getLimitMinute(int tunnel) {
    665         return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_MIN, 0);
     665        return getProperty(tunnel, TunnelController.PROP_MAX_CONNS_MIN, TunnelController.DEFAULT_MAX_CONNS_MIN);
    666666    }
    667667
    668668    public int getLimitHour(int tunnel) {
    669         return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_HOUR, 0);
     669        return getProperty(tunnel, TunnelController.PROP_MAX_CONNS_HOUR, TunnelController.DEFAULT_MAX_CONNS_HOUR);
    670670    }
    671671
    672672    public int getLimitDay(int tunnel) {
    673         return getProperty(tunnel, TunnelConfig.PROP_MAX_CONNS_DAY, 0);
     673        return getProperty(tunnel, TunnelController.PROP_MAX_CONNS_DAY, TunnelController.DEFAULT_MAX_CONNS_DAY);
    674674    }
    675675
    676676    public int getTotalMinute(int tunnel) {
    677         return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_MIN, 0);
     677        return getProperty(tunnel, TunnelController.PROP_MAX_TOTAL_CONNS_MIN, TunnelController.DEFAULT_MAX_TOTAL_CONNS_MIN);
    678678    }
    679679
    680680    public int getTotalHour(int tunnel) {
    681         return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_HOUR, 0);
     681        return getProperty(tunnel, TunnelController.PROP_MAX_TOTAL_CONNS_HOUR, 0);
    682682    }
    683683
    684684    public int getTotalDay(int tunnel) {
    685         return getProperty(tunnel, TunnelConfig.PROP_MAX_TOTAL_CONNS_DAY, 0);
     685        return getProperty(tunnel, TunnelController.PROP_MAX_TOTAL_CONNS_DAY, 0);
    686686    }
    687687
    688688    public int getMaxStreams(int tunnel) {
    689         return getProperty(tunnel, TunnelConfig.PROP_MAX_STREAMS, 0);
     689        return getProperty(tunnel, TunnelController.PROP_MAX_STREAMS, TunnelController.DEFAULT_MAX_STREAMS);
    690690    }
    691691
     
    695695     */
    696696    public int getPostMax(int tunnel) {
    697         return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_MAX, 0);
     697        return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_MAX, I2PTunnelHTTPServer.DEFAULT_POST_MAX);
    698698    }
    699699
    700700    public int getPostTotalMax(int tunnel) {
    701         return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_MAX, 0);
     701        return getProperty(tunnel, I2PTunnelHTTPServer.OPT_POST_TOTAL_MAX, I2PTunnelHTTPServer.DEFAULT_POST_TOTAL_MAX);
    702702    }
    703703
  • apps/i2ptunnel/java/src/net/i2p/i2ptunnel/ui/TunnelConfig.java

    r889b5ae refe3696a  
    473473     * all of these are @since 0.8.3 (moved from IndexBean)
    474474     */
    475     public static final String PROP_MAX_CONNS_MIN = "i2p.streaming.maxConnsPerMinute";
    476     public static final String PROP_MAX_CONNS_HOUR = "i2p.streaming.maxConnsPerHour";
    477     public static final String PROP_MAX_CONNS_DAY = "i2p.streaming.maxConnsPerDay";
    478     public static final String PROP_MAX_TOTAL_CONNS_MIN = "i2p.streaming.maxTotalConnsPerMinute";
    479     public static final String PROP_MAX_TOTAL_CONNS_HOUR = "i2p.streaming.maxTotalConnsPerHour";
    480     public static final String PROP_MAX_TOTAL_CONNS_DAY = "i2p.streaming.maxTotalConnsPerDay";
    481     public static final String PROP_MAX_STREAMS = "i2p.streaming.maxConcurrentStreams";
     475    public static final String PROP_MAX_CONNS_MIN = TunnelController.PROP_MAX_CONNS_MIN;
     476    public static final String PROP_MAX_CONNS_HOUR = TunnelController.PROP_MAX_CONNS_HOUR;
     477    public static final String PROP_MAX_CONNS_DAY = TunnelController.PROP_MAX_CONNS_DAY;
     478    public static final String PROP_MAX_TOTAL_CONNS_MIN = TunnelController.PROP_MAX_TOTAL_CONNS_MIN;
     479    public static final String PROP_MAX_TOTAL_CONNS_HOUR = TunnelController.PROP_MAX_TOTAL_CONNS_HOUR;
     480    public static final String PROP_MAX_TOTAL_CONNS_DAY = TunnelController.PROP_MAX_TOTAL_CONNS_DAY;
     481    public static final String PROP_MAX_STREAMS = TunnelController.PROP_MAX_STREAMS;
    482482
    483483    public void setLimitMinute(int val) {
     
    608608            if (_targetPort >= 0)
    609609                config.setProperty(TunnelController.PROP_TARGET_PORT, Integer.toString(_targetPort));
     610            // see TunnelController.setConfig()
     611            _booleanOptions.add(TunnelController.PROP_LIMITS_SET);
    610612            for (String p : _booleanServerOpts)
    611613                config.setProperty(OPT + p, "" + _booleanOptions.contains(p));
     
    764766        I2PTunnelHTTPServer.OPT_REJECT_USER_AGENTS,
    765767        I2PTunnelServer.PROP_UNIQUE_LOCAL,
    766         "shouldBundleReplyInfo"
     768        "shouldBundleReplyInfo",
     769        TunnelController.PROP_LIMITS_SET
    767770        };
    768771    private static final String _otherClientOpts[] = {
Note: See TracChangeset for help on using the changeset viewer.