Changeset b328b47


Ignore:
Timestamp:
Aug 31, 2011 12:52:22 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
9e6f993
Parents:
bd7e655
Message:
  • OCMOSJ: Remove some global cache locks, other cleanups
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    rbd7e655 rb328b47  
     12011-08-31 zzz
     2  * OCMOSJ: Remove some global cache locks, other cleanups
     3
    142011-08-30 zzz
    25  * I2CP: Cache b32 lookups client-side
  • router/java/src/net/i2p/router/RouterVersion.java

    rbd7e655 rb328b47  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 5;
     21    public final static long BUILD = 6;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/message/OutboundClientMessageOneShotJob.java

    rbd7e655 rb328b47  
    1010import java.util.Properties;
    1111import java.util.Set;
     12import java.util.concurrent.ConcurrentHashMap;
    1213
    1314import net.i2p.crypto.SessionKeyManager;
     
    4344/**
    4445 * Send a client message out a random outbound tunnel and into a random inbound
    45  * tunnel on the target leaseSet.  This also bundles the sender's leaseSet and
     46 * tunnel on the target leaseSet.  This also (sometimes) bundles the sender's leaseSet and
    4647 * a DeliveryStatusMessage (for ACKing any sessionTags used in the garlic).
    4748 *
     
    4950public class OutboundClientMessageOneShotJob extends JobImpl {
    5051    private final Log _log;
    51     private long _overallExpiration;
    52     private ClientMessage _clientMessage;
     52    private final long _overallExpiration;
     53    private final ClientMessage _clientMessage;
    5354    private final MessageId _clientMessageId;
    5455    private final int _clientMessageSize;
     
    7071   
    7172    /**
     73     * This is the place where we make I2P go fast.
     74     *
     75     * We have five static caches.
     76     * - The LeaseSet cache is used to decide whether to bundle our own leaseset,
     77     *   which minimizes overhead.
     78     * - The Lease cache is used to persistently send to the same lease for the destination,
     79     *   which keeps the streaming lib happy by minimizing out-of-order delivery.
     80     * - The Tunnel and BackloggedTunnel caches are used to persistently use the same outbound tunnel
     81     *   for the same destination,
     82     *   which keeps the streaming lib happy by minimizing out-of-order delivery.
     83     * - The last reply requested cache ensures that a reply is requested every so often,
     84     *   so that failed tunnels are recognized.
     85     *
     86     */
     87
     88    /**
     89     * Key used to cache things with, based on source + dest
     90     */
     91    private final HashPair _hashPair;
     92
     93    /**
     94     * Use the same outbound tunnel as we did for the same destination previously,
     95     * if possible, to keep the streaming lib happy
     96     * Use two caches - although a cache of a list of tunnels per dest might be
     97     * more elegant.
     98     * Key the caches on the source+dest pair.
     99     *
     100     */
     101    private static final Map<HashPair, TunnelInfo> _tunnelCache = new HashMap(64);
     102
     103    private static final Map<HashPair, TunnelInfo> _backloggedTunnelCache = new HashMap(64);
     104
     105    /**
     106      * Returns the reply lease set if forced to do so,
     107      * or if configured to do so,
     108      * or if a certain percentage of the time if configured to do so,
     109      * or if our lease set has changed since we last talked to them,
     110      * or 10% of the time anyway so they don't forget us (disabled for now),
     111      * or null otherwise.
     112      *
     113      * Note that wantACK randomly forces us another 5% of the time.
     114      *
     115      * We don't want to do this too often as a typical 2-lease leaseset
     116      * in a DatabaseStoreMessage is 861+37=898 bytes -
     117      * when added to garlic it's a 1056-byte addition total, which is huge.
     118      *
     119      * Key the cache on the source+dest pair.
     120      */
     121    private static final Map<HashPair, LeaseSet> _leaseSetCache = new ConcurrentHashMap(64);
     122
     123    /**
     124     * Use the same inbound tunnel (i.e. lease) as we did for the same destination previously,
     125     * if possible, to keep the streaming lib happy
     126     * Key the caches on the source+dest pair.
     127     *
     128     * We're going to use the lease until it expires, as long as it remains in the current leaseSet.
     129     *
     130     * If not found,
     131     * fetch the next lease that we should try sending through, randomly chosen
     132     * from within the sorted leaseSet (NOT sorted by # of failures through each
     133     * lease).
     134     *
     135     */
     136    private static final ConcurrentHashMap<HashPair, Lease> _leaseCache = new ConcurrentHashMap(64);
     137
     138    /**
     139     * This cache is used to ensure that we request a reply every so often.
     140     * Hopefully this allows the router to recognize a failed tunnel and switch,
     141     * before upper layers like streaming lib fail, even for low-bandwidth
     142     * connections like IRC.
     143     */
     144    private static final Map<HashPair, Long> _lastReplyRequestCache = new ConcurrentHashMap(64);
     145
     146    /**
    72147     * final timeout (in milliseconds) that the outbound message will fail in.
    73148     * This can be overridden in the router.config or the client's session config
     
    120195        _from = msg.getFromDestination();
    121196        _to = msg.getDestination();
     197        _hashPair = new HashPair(_from.calculateHash(), _to.calculateHash());
    122198        _toString = _to.calculateHash().toBase64().substring(0,4);
    123         _leaseSetLookupBegin = -1;
    124199        _start = getContext().clock().now();
    125200       
    126201        // use expiration requested by client if available, otherwise session config,
    127202        // otherwise router config, otherwise default
    128         _overallExpiration = msg.getExpiration();
    129         if (_overallExpiration > 0) {
     203        long overallExpiration = msg.getExpiration();
     204        if (overallExpiration > 0) {
    130205            // Unless it's already expired, set a min and max expiration
    131             if (_overallExpiration <= _start) {
    132                 _overallExpiration = Math.max(_overallExpiration, _start + OVERALL_TIMEOUT_MS_MIN);
    133                 _overallExpiration = Math.min(_overallExpiration, _start + OVERALL_TIMEOUT_MS_DEFAULT);
     206            if (overallExpiration <= _start) {
     207                overallExpiration = Math.max(overallExpiration, _start + OVERALL_TIMEOUT_MS_MIN);
     208                overallExpiration = Math.min(overallExpiration, _start + OVERALL_TIMEOUT_MS_DEFAULT);
    134209                if (_log.shouldLog(Log.INFO))
    135                     _log.info(getJobId() + ": Message Expiration (ms): " + (_overallExpiration - _start));
     210                    _log.info(getJobId() + ": Message Expiration (ms): " + (overallExpiration - _start));
    136211            } else {
    137212                if (_log.shouldLog(Log.WARN))
     
    153228                }
    154229            }
    155             _overallExpiration = timeoutMs + _start;
     230            overallExpiration = timeoutMs + _start;
    156231           if (_log.shouldLog(Log.INFO))
    157232               _log.info(getJobId() + " Default Expiration (ms): " + timeoutMs);
    158233        }
     234        _overallExpiration = overallExpiration;
    159235    }
    160236   
     
    192268        Hash key = _to.calculateHash();
    193269        SendJob success = new SendJob(getContext());
    194         LeaseSet ls = getContext().netDb().lookupLeaseSetLocally(key);
    195         if (ls != null) {
     270        _leaseSet = getContext().netDb().lookupLeaseSetLocally(key);
     271        if (_leaseSet != null) {
    196272            getContext().statManager().addRateData("client.leaseSetFoundLocally", 1, 0);
    197             _leaseSetLookupBegin = -1;
    198273            if (_log.shouldLog(Log.DEBUG))
    199274                _log.debug(getJobId() + ": Send outbound client message - leaseSet found locally for " + _toString);
     
    209284   
    210285    /**
    211       * Returns the reply lease set if forced to do so,
    212       * or if configured to do so,
    213       * or if a certain percentage of the time if configured to do so,
    214       * or if our lease set has changed since we last talked to them,
    215       * or 10% of the time anyway so they don't forget us (disabled for now),
    216       * or null otherwise.
    217       *
    218       * Note that wantACK randomly forces us another 5% of the time.
    219       *
    220       * We don't want to do this too often as a typical 2-lease leaseset
    221       * in a DatabaseStoreMessage is 861+37=898 bytes -
    222       * when added to garlic it's a 1056-byte addition total, which is huge.
    223       *
    224       * Key the cache on the source+dest pair.
    225       */
    226     private final static HashMap<HashPair, LeaseSet> _leaseSetCache = new HashMap();
    227 
     286     *  @param force to force including a reply lease set
     287     *  @return lease set or null if we should not send the lease set
     288     */
    228289    private LeaseSet getReplyLeaseSet(boolean force) {
    229290        LeaseSet newLS = getContext().netDb().lookupLeaseSetLocally(_from.calculateHash());
     
    257318
    258319        // If the last leaseSet we sent him is still good, don't bother sending again
    259         synchronized (_leaseSetCache) {
     320            LeaseSet ls = _leaseSetCache.put(_hashPair, newLS);
    260321            if (!force) {
    261                 LeaseSet ls = _leaseSetCache.get(hashPair());
    262322                if (ls != null) {
    263323                    if (ls.equals(newLS)) {
     
    276336                        if (_log.shouldLog(Log.INFO))
    277337                            _log.info(getJobId() + ": Expired from cache - reply leaseset for " + _toString);
    278                         // will get overwritten below
    279                         // _leaseSetCache.remove(hashPair());
    280338                    }
    281339                }
    282340            }
    283             _leaseSetCache.put(hashPair(), newLS);
    284         }
     341
    285342        if (_log.shouldLog(Log.INFO))
    286343            _log.info(getJobId() + ": Added to cache - reply leaseset for " + _toString);
     
    293350            super(enclosingContext);
    294351        }
    295         public String getName() { return "Send outbound client message through the lease"; }
     352        public String getName() { return "Outbound client message send"; }
    296353        public void runJob() {
    297354            if (_leaseSetLookupBegin > 0) {
    298355                long lookupTime = getContext().clock().now() - _leaseSetLookupBegin;
    299                 getContext().statManager().addRateData("client.leaseSetFoundRemoteTime", lookupTime, lookupTime);
     356                getContext().statManager().addRateData("client.leaseSetFoundRemoteTime", lookupTime, 0);
    300357            }
    301358            _wantACK = false;
     
    304361                send();
    305362            } else {
     363                // shouldn't happen
    306364                if (_log.shouldLog(Log.WARN))
    307365                    _log.warn("Unable to send on a random lease, as getNext returned null (to=" + _toString + ")");
     
    312370   
    313371    /**
    314      * Use the same inbound tunnel (i.e. lease) as we did for the same destination previously,
    315      * if possible, to keep the streaming lib happy
    316      * Key the caches on the source+dest pair.
    317      *
    318      * We're going to use the lease until it expires, as long as it remains in the current leaseSet.
    319      *
    320      * If not found,
    321      * fetch the next lease that we should try sending through, randomly chosen
    322      * from within the sorted leaseSet (NOT sorted by # of failures through each
    323      * lease).
    324      *
    325      */
    326     private final static HashMap<HashPair, Lease> _leaseCache = new HashMap();
    327 
     372     *  @return success
     373     */
    328374    private boolean getNextLease() {
    329         _leaseSet = getContext().netDb().lookupLeaseSetLocally(_to.calculateHash());
     375        // set in runJob if found locally
    330376        if (_leaseSet == null) {
    331             if (_log.shouldLog(Log.WARN))
    332                 _log.warn(getJobId() + ": Lookup locally didn't find the leaseSet for " + _toString);
    333             return false;
     377            _leaseSet = getContext().netDb().lookupLeaseSetLocally(_to.calculateHash());
     378            if (_leaseSet == null) {
     379                // shouldn't happen
     380                if (_log.shouldLog(Log.WARN))
     381                    _log.warn(getJobId() + ": Lookup locally didn't find the leaseSet for " + _toString);
     382                return false;
     383            }
    334384        }
    335385
    336386        // Use the same lease if it's still good
    337387        // Even if _leaseSet changed, _leaseSet.getEncryptionKey() didn't...
    338         synchronized (_leaseCache) {
    339             _lease = _leaseCache.get(hashPair());
     388            _lease = _leaseCache.get(_hashPair);
    340389            if (_lease != null) {
    341390                // if outbound tunnel length == 0 && lease.firsthop.isBacklogged() don't use it ??
     
    352401                    }
    353402                }
     403                // remove only if still equal to _lease (concurrent)
     404                _leaseCache.remove(_hashPair, _lease);
    354405                if (_log.shouldLog(Log.INFO))
    355406                    _log.info(getJobId() + ": Expired from cache - lease for " + _toString);
    356                 _leaseCache.remove(hashPair());
    357             }
    358         }
     407            }
    359408
    360409        // get the possible leases
    361         List leases = new ArrayList(_leaseSet.getLeaseCount());
     410        List<Lease> leases = new ArrayList(_leaseSet.getLeaseCount());
    362411        for (int i = 0; i < _leaseSet.getLeaseCount(); i++) {
    363412            Lease lease = _leaseSet.getLease(i);
     
    402451        // Avoid a lease on a gateway we think is unreachable, if possible
    403452        for (int i = 0; i < leases.size(); i++) {
    404             Lease l = (Lease) leases.get(i);
     453            Lease l = leases.get(i);
    405454/***
    406455 ***  Anonymity concerns with this, as the dest could act unreachable just to us, then
     
    419468        }
    420469        if (_lease == null) {
    421             _lease = (Lease)leases.get(0);
     470            _lease = leases.get(0);
    422471            if (_log.shouldLog(Log.WARN))
    423472                _log.warn(getJobId() + ": All leases are unreachable for " + _toString);
    424473        }
    425         synchronized (_leaseCache) {
    426             _leaseCache.put(hashPair(), _lease);
    427         }
     474        _leaseCache.put(_hashPair, _lease);
    428475        if (_log.shouldLog(Log.INFO))
    429476            _log.info(getJobId() + ": Added to cache - lease for " + _toString);
     
    434481   
    435482    /**
    436      * we couldn't even find the leaseSet, but try again (or die
    437      * if we've already tried too hard)
    438      *
     483     * We couldn't even find the leaseSet, so die
    439484     */
    440485    private class LookupLeaseSetFailedJob extends JobImpl {
     
    442487            super(enclosingContext);
    443488        }
    444         public String getName() { return "Lookup for outbound client message failed"; }
     489        public String getName() { return "Outbound client message lease lookup failed"; }
    445490        public void runJob() {
    446491            if (_leaseSetLookupBegin > 0) {
     
    458503    }
    459504   
    460     /**
    461      * This cache is used to ensure that we request a reply every so often.
    462      * Hopefully this allows the router to recognize a failed tunnel and switch,
    463      * before upper layers like streaming lib fail, even for low-bandwidth
    464      * connections like IRC.
    465      */
    466     private final static HashMap<HashPair, Long> _lastReplyRequestCache = new HashMap();
    467 
    468505    /**
    469506     * Send the message to the specified tunnel by creating a new garlic message containing
     
    491528        // DONE (added new cache): wantACK if we haven't in last 1m (requires a new static cache probably)
    492529        boolean wantACK;
    493         synchronized (_lastReplyRequestCache) {
    494             Long lastSent = _lastReplyRequestCache.get(hashPair());
     530
     531            Long lastSent = _lastReplyRequestCache.get(_hashPair);
    495532            wantACK = _wantACK || existingTags <= 30 ||
    496533                      lastSent == null || lastSent.longValue() < now - REPLY_REQUEST_INTERVAL;
    497534            if (wantACK)
    498                 _lastReplyRequestCache.put(hashPair(), Long.valueOf(now));
    499         }
     535                _lastReplyRequestCache.put(_hashPair, Long.valueOf(now));
    500536       
    501537        PublicKey key = _leaseSet.getEncryptionKey();
     
    560596                       + _toString + " at "
    561597                       + _lease.getTunnelId() + " on "
    562                        + _lease.getGateway().toBase64());
     598                       + _lease.getGateway());
    563599       
    564600        if (_outTunnel != null) {
     
    567603                           + _toString + " at "
    568604                           + _lease.getTunnelId() + " on "
    569                            + _lease.getGateway().toBase64());
     605                           + _lease.getGateway());
    570606
    571607            DispatchJob dispatchJob = new DispatchJob(getContext(), msg, selector, onReply, onFail, (int)(_overallExpiration-getContext().clock().now()));
     
    580616            dieFatal();
    581617        }
    582         _clientMessage = null;
    583618        _clove = null;
    584619        getContext().statManager().addRateData("client.dispatchPrepareTime", now - _start, 0);
     
    603638        }
    604639
    605         public String getName() { return "Dispatch outbound client message"; }
     640        public String getName() { return "Outbound client message dispatch"; }
    606641
    607642        public void runJob() {
     
    621656        }
    622657    }
    623    
    624     /**
    625      * This is the place where we make I2P go fast.
    626      *
    627      * We have five static caches.
    628      * - The LeaseSet cache is used to decide whether to bundle our own leaseset,
    629      *   which minimizes overhead.
    630      * - The Lease cache is used to persistently send to the same lease for the destination,
    631      *   which keeps the streaming lib happy by minimizing out-of-order delivery.
    632      * - The Tunnel and BackloggedTunnel caches are used to persistently use the same outbound tunnel
    633      *   for the same destination,
    634      *   which keeps the streaming lib happy by minimizing out-of-order delivery.
    635      * - The last reply requested cache ensures that a reply is requested every so often,
    636      *   so that failed tunnels are recognized.
    637      *
    638      */
    639 
    640     /**
    641      * Key used to cache things with based on source + dest
    642      */
    643     private HashPair _hashPair;
    644     private HashPair hashPair() {
    645         if (_hashPair == null)
    646             _hashPair = new HashPair(_from.calculateHash(), _to.calculateHash());
    647         return _hashPair;
    648     }
    649658
    650659    /**
     
    672681    }
    673682
    674 
    675     /**
    676      * This is a little sneaky, but get the _from back out of the "opaque" hash key
    677      * (needed for cleanTunnelCache)
    678      */
    679     private static Hash sourceFromHashPair(HashPair s) {
    680         return s.sh;
    681     }
    682 
    683683    /**
    684684     * Called on failure to give us a better chance of success next time.
     
    689689     */
    690690    private void clearCaches() {
    691         HashPair key = hashPair();
    692691        if (_inTunnel != null) {   // if we wanted an ack, we sent our lease too
    693             synchronized(_leaseSetCache) {
    694                 _leaseSetCache.remove(key);
    695             }
     692                _leaseSetCache.remove(_hashPair);
    696693        }
    697694        if (_lease != null) {
    698             synchronized(_leaseCache) {
    699                 Lease l = _leaseCache.get(key);
    700                 if (l != null && l.equals(_lease))
    701                     _leaseCache.remove(key);
    702             }
     695            // remove only if still equal to _lease (concurrent)
     696            _leaseCache.remove(_hashPair, _lease);
    703697        }
    704698        if (_outTunnel != null) {
    705699            synchronized(_tunnelCache) {
    706                 TunnelInfo t = _backloggedTunnelCache.get(key);
     700                TunnelInfo t = _backloggedTunnelCache.get(_hashPair);
    707701                if (t != null && t.equals(_outTunnel))
    708                     _backloggedTunnelCache.remove(key);
    709                 t = _tunnelCache.get(key);
     702                    _backloggedTunnelCache.remove(_hashPair);
     703                t = _tunnelCache.get(_hashPair);
    710704                if (t != null && t.equals(_outTunnel))
    711                     _tunnelCache.remove(key);
     705                    _tunnelCache.remove(_hashPair);
    712706            }
    713707        }
     
    718712     */
    719713    public static void clearAllCaches() {
    720         synchronized(_leaseSetCache) {
    721             _leaseSetCache.clear();
    722         }
    723         synchronized(_leaseCache) {
    724             _leaseCache.clear();
    725         }
     714        _leaseSetCache.clear();
     715        _leaseCache.clear();
    726716        synchronized(_tunnelCache) {
    727717            _backloggedTunnelCache.clear();
    728718            _tunnelCache.clear();
    729719        }
     720        _lastReplyRequestCache.clear();
    730721    }
    731722
    732723    /**
    733724     * Clean out old leaseSets
    734      * Caller must synchronize on tc.
    735725     */
    736726    private static void cleanLeaseSetCache(RouterContext ctx, Map<HashPair, LeaseSet> tc) {
     
    745735    /**
    746736     * Clean out old leases
    747      * Caller must synchronize on tc.
    748737     */
    749738    private static void cleanLeaseCache(Map<HashPair, Lease> tc) {
     
    760749     */
    761750    private static void cleanTunnelCache(RouterContext ctx, Map<HashPair, TunnelInfo> tc) {
    762         for (Iterator iter = tc.entrySet().iterator(); iter.hasNext(); ) {
    763             Map.Entry entry = (Map.Entry)iter.next();
    764             HashPair k = (HashPair) entry.getKey();
    765             TunnelInfo tunnel = (TunnelInfo) entry.getValue();
    766             if (!ctx.tunnelManager().isValidTunnel(sourceFromHashPair(k), tunnel))
     751        for (Iterator<Map.Entry<HashPair, TunnelInfo>> iter = tc.entrySet().iterator(); iter.hasNext(); ) {
     752            Map.Entry<HashPair, TunnelInfo> entry = iter.next();
     753            HashPair k = entry.getKey();
     754            TunnelInfo tunnel = entry.getValue();
     755            // This is a little sneaky, but get the _from back out of the "opaque" hash key
     756            if (!ctx.tunnelManager().isValidTunnel(k.sh, tunnel))
    767757                iter.remove();
    768758        }
     
    771761    /**
    772762     * Clean out old reply times
    773      * Caller must synchronize on tc.
    774763     */
    775764    private static void cleanReplyCache(RouterContext ctx, Map<HashPair, Long> tc) {
    776765        long now = ctx.clock().now();
    777         for (Iterator iter = tc.values().iterator(); iter.hasNext(); ) {
    778             Long l = (Long) iter.next();
     766        for (Iterator<Long> iter = tc.values().iterator(); iter.hasNext(); ) {
     767            Long l = iter.next();
    779768            if (l.longValue() < now - CLEAN_INTERVAL)
    780769                iter.remove();
     
    788777        }
    789778        public void timeReached() {
    790             synchronized(_leaseSetCache) {
    791                 cleanLeaseSetCache(_ctx, _leaseSetCache);
    792             }
    793             synchronized(_leaseCache) {
    794                 cleanLeaseCache(_leaseCache);
    795             }
     779            cleanLeaseSetCache(_ctx, _leaseSetCache);
     780            cleanLeaseCache(_leaseCache);
    796781            synchronized(_tunnelCache) {
    797782                cleanTunnelCache(_ctx, _tunnelCache);
    798783                cleanTunnelCache(_ctx, _backloggedTunnelCache);
    799784            }
    800             synchronized(_lastReplyRequestCache) {
    801                 cleanReplyCache(_ctx, _lastReplyRequestCache);
    802             }
    803         }
    804     }
    805 
    806     /**
    807      * Use the same outbound tunnel as we did for the same destination previously,
    808      * if possible, to keep the streaming lib happy
    809      * Use two caches - although a cache of a list of tunnels per dest might be
    810      * more elegant.
    811      * Key the caches on the source+dest pair.
    812      *
    813      */
    814     private static final HashMap<HashPair, TunnelInfo> _tunnelCache = new HashMap();
    815 
    816     private static HashMap<HashPair, TunnelInfo> _backloggedTunnelCache = new HashMap();
     785            cleanReplyCache(_ctx, _lastReplyRequestCache);
     786        }
     787    }
    817788
    818789    private TunnelInfo selectOutboundTunnel(Destination to) {
     
    825796             * backlog and seeing if traffic came back or not.
    826797             */
    827             tunnel = _backloggedTunnelCache.get(hashPair());
     798            tunnel = _backloggedTunnelCache.get(_hashPair);
    828799            if (tunnel != null) {
    829800                if (getContext().tunnelManager().isValidTunnel(_from.calculateHash(), tunnel)) {
     
    831802                        if (_log.shouldLog(Log.WARN))
    832803                            _log.warn("Switching back to tunnel " + tunnel + " for " + _toString);
    833                         _backloggedTunnelCache.remove(hashPair());
    834                         _tunnelCache.put(hashPair(), tunnel);
     804                        _backloggedTunnelCache.remove(_hashPair);
     805                        _tunnelCache.put(_hashPair, tunnel);
    835806                        _wantACK = true;
    836807                        return tunnel;
    837808                    }  // else still backlogged
    838809                } else // no longer valid
    839                     _backloggedTunnelCache.remove(hashPair());
     810                    _backloggedTunnelCache.remove(_hashPair);
    840811            }
    841812            // Use the same tunnel unless backlogged
    842             tunnel = _tunnelCache.get(hashPair());
     813            tunnel = _tunnelCache.get(_hashPair);
    843814            if (tunnel != null) {
    844815                if (getContext().tunnelManager().isValidTunnel(_from.calculateHash(), tunnel)) {
     
    848819                    if (_log.shouldLog(Log.WARN))
    849820                        _log.warn("Switching from backlogged " + tunnel + " for " + _toString);
    850                     _backloggedTunnelCache.put(hashPair(), tunnel);
     821                    _backloggedTunnelCache.put(_hashPair, tunnel);
    851822                } // else no longer valid
    852                 _tunnelCache.remove(hashPair());
     823                _tunnelCache.remove(_hashPair);
    853824            }
    854825            // Pick a new tunnel
    855826            tunnel = selectOutboundTunnel();
    856827            if (tunnel != null)
    857                 _tunnelCache.put(hashPair(), tunnel);
     828                _tunnelCache.put(_hashPair, tunnel);
    858829            _wantACK = true;
    859830        }
    860831        return tunnel;
    861832    }
     833
    862834    /**
    863835     * Pick an arbitrary outbound tunnel to send the message through, or null if
    864836     * there aren't any around
    865837     *
     838     * TODO - rather than pick one at random, pick the "closest" to the lease,
     839     * to minimize network OBEP - IBGW connections?
     840     * This would also eliminate a connection when OBEP == IBGW.
     841     * Anonymity issues?
    866842     */
    867843    private TunnelInfo selectOutboundTunnel() {
    868844        return getContext().tunnelManager().selectOutboundTunnel(_from.calculateHash());
    869845    }
    870     /**
    871      * Pick an arbitrary outbound tunnel for any deliveryStatusMessage to come back in
     846
     847    /**
     848     * Pick an arbitrary inbound tunnel for any deliveryStatusMessage to come back in
    872849     *
    873850     */
     
    903880        getContext().clientManager().messageDeliveryStatusUpdate(_from, _clientMessageId, false);
    904881        getContext().statManager().updateFrequency("client.sendMessageFailFrequency");
    905         _clientMessage = null;
    906882        _clove = null;
    907883    }
     
    956932        public ReplySelector(long token) {
    957933            _pendingToken = token;
    958             if (_log.shouldLog(Log.INFO))
    959                 _log.info(OutboundClientMessageOneShotJob.this.getJobId()
    960                            + ": Reply selector for client message: token=" + token);
     934            //if (_log.shouldLog(Log.INFO))
     935            //    _log.info(OutboundClientMessageOneShotJob.this.getJobId()
     936            //               + ": Reply selector for client message: token=" + token);
    961937        }
    962938       
     
    1007983        }
    1008984       
    1009         public String getName() { return "Send client message successful"; }
     985        public String getName() { return "Outbound client message send success"; }
    1010986
    1011987        public void runJob() {
     
    10681044        }
    10691045       
    1070         public String getName() { return "Send client message timed out"; }
     1046        public String getName() { return "Outbound client message send timeout"; }
    10711047
    10721048        public void runJob() {
Note: See TracChangeset for help on using the changeset viewer.