Changeset 5ce06d02


Ignore:
Timestamp:
May 6, 2011 12:35:19 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
f965466
Parents:
c356792
Message:

the rest of -2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java

    rc356792 r5ce06d02  
    2626 */
    2727public class TunnelPool {
    28     private final List _inProgress = new ArrayList();
     28    private final List<PooledTunnelCreatorConfig> _inProgress = new ArrayList();
    2929    private final RouterContext _context;
    3030    private final Log _log;
    3131    private TunnelPoolSettings _settings;
    32     private final ArrayList<TunnelInfo> _tunnels;
     32    private final List<TunnelInfo> _tunnels;
    3333    private final TunnelPeerSelector _peerSelector;
    3434    private final TunnelPoolManager _manager;
     
    277277    }
    278278   
    279     public void addTunnel(TunnelInfo info) {
     279    /**
     280     *  Add to the pool.
     281     */
     282    void addTunnel(TunnelInfo info) {
    280283        if (_log.shouldLog(Log.DEBUG))
    281             _log.debug(toString() + ": Adding tunnel " + info, new Exception("Creator"));
     284            _log.debug(toString() + ": Adding tunnel " + info /* , new Exception("Creator") */ );
    282285        LeaseSet ls = null;
    283286        synchronized (_tunnels) {
     
    291294    }
    292295   
    293     public void removeTunnel(TunnelInfo info) {
     296    /**
     297     *  Remove from the pool.
     298     */
     299    void removeTunnel(TunnelInfo info) {
    294300        if (_log.shouldLog(Log.DEBUG))
    295301            _log.debug(toString() + ": Removing tunnel " + info);
     
    468474
    469475    /**
    470      * Build a leaseSet with the required tunnels that aren't about to expire
     476     * Build a leaseSet with the required tunnels that aren't about to expire.
     477     * Caller must synchronize on _tunnels.
    471478     *
     479     * @return null on failure
    472480     */
    473481    private LeaseSet locked_buildNewLeaseSet() {
     
    725733        synchronized (_inProgress) {
    726734            inProgress = _inProgress.size();
    727             for (int i = 0; i < _inProgress.size(); i++) {
    728                 PooledTunnelCreatorConfig cfg = (PooledTunnelCreatorConfig)_inProgress.get(i);
     735            for (int i = 0; i < inProgress; i++) {
     736                PooledTunnelCreatorConfig cfg = _inProgress.get(i);
    729737                if (cfg.getLength() <= 1)
    730738                    fallback++;
     
    847855    }
    848856   
     857    /**
     858     *  @return null on failure
     859     */
    849860    PooledTunnelCreatorConfig configureNewTunnel() { return configureNewTunnel(false); }
    850861
     862    /**
     863     *  @return null on failure
     864     */
    851865    private PooledTunnelCreatorConfig configureNewTunnel(boolean forceZeroHop) {
    852866        TunnelPoolSettings settings = getSettings();
    853         List peers = null;
    854         long expiration = _context.clock().now() + settings.getDuration();
     867        // peers for new tunnel, including us, ENDPOINT FIRST
     868        List<Hash> peers = null;
     869        long expiration = _context.clock().now() + TunnelPoolSettings.DEFAULT_DURATION;
    855870
    856871        if (!forceZeroHop) {
    857872            peers = _peerSelector.selectPeers(_context, settings);
     873
    858874            if ( (peers == null) || (peers.isEmpty()) ) {
    859                 // no inbound or outbound tunnels to send the request through, and
     875                // no peers to build the tunnel with, and
    860876                // the pool is refusing 0 hop tunnels
    861877                if (peers == null) {
     
    872888            peers.add(_context.routerHash());
    873889        }
     890
    874891        PooledTunnelCreatorConfig cfg = new PooledTunnelCreatorConfig(_context, peers.size(), settings.isInbound(), settings.getDestination());
    875892        cfg.setTunnelPool(this);
    876         // peers[] is ordered endpoint first, but cfg.getPeer() is ordered gateway first
     893        // peers list is ordered endpoint first, but cfg.getPeer() is ordered gateway first
    877894        for (int i = 0; i < peers.size(); i++) {
    878895            int j = peers.size() - 1 - i;
    879             cfg.setPeer(j, (Hash)peers.get(i));
     896            cfg.setPeer(j, peers.get(i));
    880897            HopConfig hop = cfg.getConfig(j);
    881898            hop.setCreation(_context.clock().now());
     
    896913    }
    897914   
     915    /**
     916     *  Remove from the _inprogress list
     917     */
    898918    void buildComplete(PooledTunnelCreatorConfig cfg) {
    899919        synchronized (_inProgress) { _inProgress.remove(cfg); }
Note: See TracChangeset for help on using the changeset viewer.