Changeset 082922d


Ignore:
Timestamp:
Sep 18, 2014 1:32:27 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
ec2708a1
Parents:
ea02a7c
Message:

NTCP: Return unused DH keypairs to the pool

Location:
router/java/src/net/i2p/router/transport/ntcp
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/transport/ntcp/EstablishState.java

    rea02a7c r082922d  
    6565   
    6666    public static final VerifiedEstablishState VERIFIED = new VerifiedEstablishState();
     67    public static final FailedEstablishState FAILED = new FailedEstablishState();
    6768   
    6869    private final RouterContext _context;
     
    121122    private static final int HXY_TSB_PAD_SIZE = HXY_SIZE + 4 + 12;  // 48
    122123
    123     private State _state;
     124    protected State _state;
    124125
    125126    private enum State {
     
    164165        _con = null;
    165166        _e_hXY_tsB = null;
    166         _state = State.VERIFIED;
    167167    }
    168168
     
    901901    public synchronized byte[] getExtraBytes() { return _extra; }
    902902
     903    /**
     904     *  Release resources on timeout.
     905     *  @param e may be null
     906     *  @since 0.9.16
     907     */
     908    public synchronized void close(String reason, Exception e) {
     909        fail(reason, e);
     910    }
     911
    903912    /** Caller must synch. */
    904913    private void fail(String reason) { fail(reason, null); }
     
    920929    }
    921930
    922     /** Only call once. Caller must synch. */
     931    /**
     932     *  Only call once. Caller must synch.
     933     *  @since 0.9.16
     934     */
    923935    private void releaseBufs() {
    924936        // null or longer for OB
     
    928940        SimpleByteCache.release(_curDecrypted);
    929941        SimpleByteCache.release(_hX_xor_bobIdentHash);
    930         SimpleByteCache.release(_X);
    931         SimpleByteCache.release(_Y);
     942        if (_dh.getPeerPublicValue() == null)
     943            _transport.returnUnused(_dh);
     944        if (_con.isInbound())
     945            SimpleByteCache.release(_X);
     946        else
     947            SimpleByteCache.release(_Y);
    932948    }
    933949
     
    10251041     */
    10261042    private static class VerifiedEstablishState extends EstablishState {
    1027         @Override public boolean isComplete() { return true; }
     1043
     1044        public VerifiedEstablishState() {
     1045            super();
     1046            _state = State.VERIFIED;
     1047        }
     1048
    10281049        @Override public void prepareOutbound() {
    10291050            Log log =RouterContext.getCurrentContext().logManager().getLog(VerifiedEstablishState.class);
    10301051            log.warn("prepareOutbound() on verified state, doing nothing!");
    10311052        }
    1032         @Override public String toString() { return "VerfiedEstablishState";}
     1053
     1054        @Override public String toString() { return "VerifiedEstablishState";}
     1055    }
     1056
     1057    /**
     1058     *  @since 0.9.16
     1059     */
     1060    private static class FailedEstablishState extends EstablishState {
     1061
     1062        public FailedEstablishState() {
     1063            super();
     1064            _state = State.CORRUPT;
     1065        }
     1066
     1067        @Override public void prepareOutbound() {
     1068            Log log =RouterContext.getCurrentContext().logManager().getLog(VerifiedEstablishState.class);
     1069            log.warn("prepareOutbound() on verified state, doing nothing!");
     1070        }
     1071
     1072        @Override public String toString() { return "FailedEstablishState";}
    10331073    }
    10341074
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    rea02a7c r082922d  
    533533                _context.statManager().addRateData("ntcp.connectSuccessful", 1);
    534534            } else {
    535                 con.close();
     535                con.closeOnTimeout("connect failed", null);
    536536                _transport.markUnreachable(con.getRemotePeer().calculateHash());
    537537                _context.statManager().addRateData("ntcp.connectFailedTimeout", 1);
     
    540540            if (_log.shouldLog(Log.INFO))
    541541                _log.info("Failed outbound " + con, ioe);
    542             con.close();
     542            con.closeOnTimeout("connect failed", ioe);
    543543            //_context.banlist().banlistRouter(con.getRemotePeer().calculateHash(), "Error connecting", NTCPTransport.STYLE);
    544544            _transport.markUnreachable(con.getRemotePeer().calculateHash());
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    rea02a7c r082922d  
    372372    }
    373373   
     374    /**
     375     *  Close and release EstablishState resources.
     376     *  @param e may be null
     377     *  @since 0.9.16
     378     */
     379    public void closeOnTimeout(String cause, Exception e) {
     380        EstablishState es = _establishState;
     381        close();
     382        es.close(cause, e);
     383    }
     384
    374385    private synchronized NTCPConnection locked_close(boolean allowRequeue) {
    375386        if (_chan != null) try { _chan.close(); } catch (IOException ioe) { }
    376387        if (_conKey != null) _conKey.cancel();
    377         _establishState = EstablishState.VERIFIED;
     388        _establishState = EstablishState.FAILED;
    378389        NTCPConnection old = _transport.removeCon(this);
    379390        _transport.getReader().connectionClosed(this);
Note: See TracChangeset for help on using the changeset viewer.