Changeset cd62d717


Ignore:
Timestamp:
Jun 18, 2015 3:02:21 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
20c796e8
Parents:
acc6478
Message:

I2CP: Don't send the first LS request to the client until we have
at least one OB tunnel, so the client waits until we are ready.
This will reduce drops, retransmissions, and failures on new client tunnels.
Fixes to prevent multiple pending LS requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/client/ClientConnectionRunner.java

    racc6478 rcd62d717  
    124124        SessionConfig config;
    125125        LeaseRequestState leaseRequest;
     126        Rerequest rerequestTimer;
    126127        LeaseSet currentLeaseSet;
    127128
     
    767768     * block.
    768769     *
     770     * Job args are always null, may need some fixups if we start using them.
     771     *
    769772     * @param h the Destination's hash
    770773     * @param set LeaseSet with requested leases - this object must be updated to contain the
     
    801804        LeaseSet current = null;
    802805        Destination dest = sp.dest;
     806        LeaseRequestState state;
    803807        synchronized (this) {
    804808            current = sp.currentLeaseSet;
     
    818822                }
    819823            }
    820         }
    821         if (_log.shouldLog(Log.INFO))
    822             _log.info("Current leaseSet " + current + "\nNew leaseSet " + set);
    823         LeaseRequestState state;
    824         synchronized (this) {
     824
     825            if (_log.shouldLog(Log.INFO))
     826                _log.info("Current leaseSet " + current + "\nNew leaseSet " + set);
     827
    825828            state = sp.leaseRequest;
    826829            if (state != null) {
     
    836839                    // ours is newer, so wait a few secs and retry
    837840                    set.setDestination(dest);
    838                     _context.simpleTimer2().addEvent(new Rerequest(set, expirationTime, onCreateJob, onFailedJob), 3*1000);
     841                    Rerequest timer = new Rerequest(set, expirationTime, onCreateJob, onFailedJob);
     842                    sp.rerequestTimer = timer;
     843                    _context.simpleTimer2().addEvent(timer, 3*1000);
    839844                    if (_log.shouldLog(Log.DEBUG))
    840845                        _log.debug("Already requesting, ours newer, wait 3 sec: " + state);
     
    844849            } else {
    845850                set.setDestination(dest);
    846                 sp.leaseRequest = state = new LeaseRequestState(onCreateJob, onFailedJob,
     851                if (current == null && _context.tunnelManager().getOutboundClientTunnelCount(h) <= 0) {
     852                    // at startup of a client, where we don't have a leaseset, wait for
     853                    // an outbound tunnel also, so the client doesn't start sending data
     854                    // before we are ready
     855                    Rerequest timer = new Rerequest(set, expirationTime, onCreateJob, onFailedJob);
     856                    sp.rerequestTimer = timer;
     857                    _context.simpleTimer2().addEvent(timer, 1000);
     858                    if (_log.shouldLog(Log.DEBUG))
     859                        _log.debug("No current LS but no OB tunnels, wait 1 sec for " + h);
     860                    return;
     861                } else {
     862                    // so the timer won't fire off with an older LS request
     863                    sp.rerequestTimer = null;
     864                    sp.leaseRequest = state = new LeaseRequestState(onCreateJob, onFailedJob,
    847865                                                                _context.clock().now() + expirationTime, set);
    848                 if (_log.shouldLog(Log.DEBUG))
    849                     _log.debug("New request: " + state);
     866                    if (_log.shouldLog(Log.DEBUG))
     867                        _log.debug("New request: " + state);
     868                }
    850869            }
    851870        }
     
    868887
    869888        public void timeReached() {
     889            Hash h = _ls.getDestination().calculateHash();
     890            SessionParams sp = _sessions.get(h);
     891            if (sp == null) {
     892                if (_log.shouldLog(Log.WARN))
     893                    _log.warn("cancelling rerequest, session went away");
     894                return;
     895            }
     896            synchronized(ClientConnectionRunner.this) {
     897                if (sp.rerequestTimer != Rerequest.this) {
     898                    if (_log.shouldLog(Log.WARN))
     899                        _log.warn("cancelling rerequest, newer request came in");
     900                    return;
     901                }
     902            }
    870903            requestLeaseSet(_ls.getDestination().calculateHash(), _ls, _expirationTime, _onCreate, _onFailed);
    871904        }
Note: See TracChangeset for help on using the changeset viewer.