Changeset bf0947e


Ignore:
Timestamp:
Oct 31, 2011 9:13:01 PM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
835db43
Parents:
a3a1110b
Message:
  • Tunnels:
    • Restore and implement lengthOverride()
    • Adjust quantity override
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    ra3a1110b rbf0947e  
    66    - Reduce max reorg cycle time
    77    - Reduce new bonus values
     8    - Fix rare NSEE thx sponge
    89  * SSU: Increase threshold for incremented cost
     10  * Tunnels:
     11    - Restore and implement lengthOverride()
     12    - Adjust quantity override
    913
    10142011-10-29 zzz
  • router/java/src/net/i2p/router/RouterVersion.java

    ra3a1110b rbf0947e  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 4;
     21    public final static long BUILD = 5;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/TunnelPoolSettings.java

    ra3a1110b rbf0947e  
    2020    private int _length;
    2121    private int _lengthVariance;
    22     //private int _lengthOverride;
     22    private int _lengthOverride;
    2323    private boolean _isInbound;
    2424    private boolean _isExploratory;
     
    6161        _length = DEFAULT_LENGTH;
    6262        _lengthVariance = DEFAULT_LENGTH_VARIANCE;
     63        _lengthOverride = -1;
    6364        _allowZeroHop = DEFAULT_ALLOW_ZERO_HOP;
    6465        _IPRestriction = DEFAULT_IP_RESTRICTION;
     
    8889    // public void setRebuildPeriod(int periodMs) { _rebuildPeriod = periodMs; }
    8990   
    90     /** how many remote hops should be in the tunnel */
     91    /**
     92     *  How many remote hops should be in the tunnel NOT including us
     93     *  @return 0 to 7
     94     */
    9195    public int getLength() { return _length; }
     96
     97    /**
     98     *  How many remote hops should be in the tunnel NOT including us
     99     *  @param length 0 to 7 (not enforced here)
     100     */
    92101    public void setLength(int length) { _length = length; }
    93102   
     
    105114    public void setLengthVariance(int variance) { _lengthVariance = variance; }
    106115
    107     /* UNUSED Set to a nonzero value to override the length setting */
    108     //public int getLengthOverride() { return _lengthOverride; }
    109     //public void setLengthOverride(int variance) { _lengthOverride = variance; }
    110    
     116    /**
     117     * A temporary length to be used due to network conditions.
     118     * If less than zero, the standard length should be used.
     119     * Unused until 0.8.11
     120     */
     121    public int getLengthOverride() { return _lengthOverride; }
     122
     123    /**
     124     * A temporary length to be used due to network conditions.
     125     * If less than zero, the standard length will be used.
     126     * Unused until 0.8.11
     127     */
     128    public void setLengthOverride(int length) { _lengthOverride = length; }
     129
    111130    /** is this an inbound tunnel? */
    112131    public boolean isInbound() { return _isInbound; }
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPeerSelector.java

    ra3a1110b rbf0947e  
    4848    protected int getLength(RouterContext ctx, TunnelPoolSettings settings) {
    4949        int length = settings.getLength();
    50         //int override = settings.getLengthOverride();
    51         //if (override != 0)
    52         //    length = override;
    53         //else if (settings.getLengthVariance() != 0) {
    54         if (settings.getLengthVariance() != 0) {
     50        int override = settings.getLengthOverride();
     51        if (override >= 0) {
     52            length = override;
     53        } else if (settings.getLengthVariance() != 0) {
    5554            int skew = settings.getLengthVariance();
    5655            if (skew > 0)
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java

    ra3a1110b rbf0947e  
    4444    private long _lastLifetimeProcessed;
    4545    private final String _rateName;
     46
    4647    private static final int TUNNEL_LIFETIME = 10*60*1000;
     48    /** if less than one success in this many, reduce quantity (exploratory only) */
     49    private static final int BUILD_TRIES_QUANTITY_OVERRIDE = 12;
     50    /** if less than one success in this many, reduce length (exploratory only) */
     51    private static final int BUILD_TRIES_LENGTH_OVERRIDE = 18;
    4752   
    4853    TunnelPool(RouterContext ctx, TunnelPoolManager mgr, TunnelPoolSettings settings, TunnelPeerSelector sel) {
     
    323328            RateStat s = _context.statManager().getRate("tunnel.buildExploratorySuccess");
    324329            if (e != null && r != null && s != null) {
    325                 // 60 min was too long - is 10 min too short?
    326                 // By not adding in previous period, this gives us a burst every
    327                 // 10 min - is that good or bad?
    328330                Rate er = e.getRate(10*60*1000);
    329331                Rate rr = r.getRate(10*60*1000);
    330332                Rate sr = s.getRate(10*60*1000);
    331333                if (er != null && rr != null && sr != null) {
    332                     long ec = er.getCurrentEventCount();
    333                     long rc = rr.getCurrentEventCount();
    334                     long sc = sr.getCurrentEventCount();
     334                    long ec = er.getCurrentEventCount() + er.getLastEventCount();
     335                    long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
     336                    long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
    335337                    long tot = ec + rc + sc;
    336                     if (tot >= 10) {
    337                         if (1000 * sc / tot <=  1000 / 10)
     338                    if (tot >= BUILD_TRIES_QUANTITY_OVERRIDE) {
     339                        if (1000 * sc / tot <=  1000 / BUILD_TRIES_QUANTITY_OVERRIDE)
    338340                            rv--;
    339341                    }
     
    342344        }
    343345        return rv;
     346    }
     347
     348   
     349    /**
     350     *  Shorten the length when under extreme stress, else clear the override.
     351     *  We only do this for exploratory tunnels, since we have to build a fallback
     352     *  if we run out. It's much better to have a shorter tunnel than a fallback.
     353     *
     354     *  @since 0.8.11
     355     */
     356    private void setLengthOverride() {
     357        if (!_settings.isExploratory())
     358            return;
     359        int len = _settings.getLength();
     360        if (len > 1) {
     361            RateStat e = _context.statManager().getRate("tunnel.buildExploratoryExpire");
     362            RateStat r = _context.statManager().getRate("tunnel.buildExploratoryReject");
     363            RateStat s = _context.statManager().getRate("tunnel.buildExploratorySuccess");
     364            if (e != null && r != null && s != null) {
     365                Rate er = e.getRate(10*60*1000);
     366                Rate rr = r.getRate(10*60*1000);
     367                Rate sr = s.getRate(10*60*1000);
     368                if (er != null && rr != null && sr != null) {
     369                    long ec = er.getCurrentEventCount() + er.getLastEventCount();
     370                    long rc = rr.getCurrentEventCount() + rr.getLastEventCount();
     371                    long sc = sr.getCurrentEventCount() + sr.getLastEventCount();
     372                    long tot = ec + rc + sc;
     373                    if (tot >= BUILD_TRIES_LENGTH_OVERRIDE) {
     374                        if (1000 * sc / tot <=  1000 / BUILD_TRIES_LENGTH_OVERRIDE)
     375                            _settings.setLengthOverride(len - 1);
     376                            return;
     377                    }
     378                }
     379            }
     380        }
     381        // disable
     382        _settings.setLengthOverride(-1);
    344383    }
    345384
     
    10091048
    10101049        if (!forceZeroHop) {
    1011             int len = settings.getLength();
     1050            int len = settings.getLengthOverride();
     1051            if (len < 0)
     1052                len = settings.getLength();
    10121053            if (len > 0 && _context.random().nextBoolean()) {
    10131054                // look for a tunnel to reuse, if the right length and expiring soon
     
    10161057                synchronized (_tunnels) {
    10171058                    for (TunnelInfo ti : _tunnels) {
    1018                         if (ti.getLength() == len && ti.getExpiration() < now + 3*60*1000 && !ti.wasReused()) {
     1059                        if (ti.getLength() >= len && ti.getExpiration() < now + 3*60*1000 && !ti.wasReused()) {
    10191060                            ti.setReused();
     1061                            len = ti.getLength();
    10201062                            peers = new ArrayList(len);
    10211063                            // peers list is ordered endpoint first, but cfg.getPeer() is ordered gateway first
     
    10271069                }
    10281070            }
    1029             if (peers == null)
     1071            if (peers == null) {
     1072                setLengthOverride();
    10301073                peers = _peerSelector.selectPeers(_context, settings);
     1074            }
    10311075
    10321076            if ( (peers == null) || (peers.isEmpty()) ) {
Note: See TracChangeset for help on using the changeset viewer.