Changeset 0b2ef3d


Ignore:
Timestamp:
Aug 3, 2018 8:14:46 PM (20 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c0be83f
Parents:
526aadb
Message:

NTCP2: Fix termination handling
log tweaks

Location:
router/java/src/net/i2p/router
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/RouterVersion.java

    r526aadb r0b2ef3d  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 21;
     21    public final static long BUILD = 22;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r526aadb r0b2ef3d  
    10251025        // no synch needed, sendNTCP2() is synched
    10261026        if (_log.shouldInfo())
    1027             _log.info("Sending termination, reason: " + reason + ", vaild frames rcvd: " + validFramesRcvd);
     1027            _log.info("Sending termination, reason: " + reason + ", vaild frames rcvd: " + validFramesRcvd + " on " + this);
    10281028        List<Block> blocks = new ArrayList<Block>(2);
    10291029        Block block = new NTCP2Payload.TerminationBlock(reason, validFramesRcvd);
     
    19331933
    19341934        public void receive(ByteBuffer buf) {
    1935             if (_terminated)
     1935            if (_terminated) {
     1936                if (_log.shouldWarn())
     1937                    _log.warn("Got " + buf.remaining() + " after termination on " + NTCPConnection.this);
    19361938                return;
     1939            }
    19371940            while (buf.hasRemaining()) {
    19381941                if (_received == -2) {
     
    19541957                    if (_framelen < OutboundNTCP2State.MAC_SIZE) {
    19551958                        if (_log.shouldWarn())
    1956                             _log.warn("Short frame length: " + _framelen);
     1959                            _log.warn("Short frame length: " + _framelen + " on " + NTCPConnection.this);
     1960                        destroy();
    19571961                        // set a random length, then close
    19581962                        delayedClose(buf, _frameCount);
     
    19731977                    buf.position(pos + _framelen);
    19741978                    if (!ok) {
     1979                        // decryptAndProcess called destroy() and set _terminated
    19751980                        delayedClose(buf, _frameCount);
    19761981                        return;
     
    20242029         *  Decrypts in place.
    20252030         *  Length is _framelen
    2026          *  Side effects: Sets _received = -2, increments _frameCount and _blockCount if valid
     2031         *  Side effects: Sets _received = -2, increments _frameCount and _blockCount if valid,
     2032         *  calls destroy() and sets _terminated if termination block received or if invalid.
    20272033         *
    20282034         *  Does not call close() on failure. Caller MUST call delayedClose() if this returns false.
     
    20382044                // TODO set a random length, then close
    20392045                if (_log.shouldWarn())
    2040                     _log.warn("Bad AEAD data phase frame " + _frameCount + " on " + NTCPConnection.this, gse);
     2046                    _log.warn("Bad AEAD data phase frame " + _frameCount +
     2047                              " with " + _framelen + " bytes on " + NTCPConnection.this, gse);
     2048                destroy();
    20412049                return false;
    20422050            }
     2051            // no payload processing errors in the data phase are fatal
    20432052            try {
    20442053                int blocks = NTCP2Payload.processPayload(_context, this, data, off,
     
    20602069            _received = -2;
    20612070            _frameCount++;
    2062             return !_terminated;
     2071            return true;
    20632072        }
    20642073
    20652074        public void destroy() {
     2075            if (_log.shouldInfo())
     2076                _log.info("NTCP2 read state destroy() on " + NTCPConnection.this, new Exception("I did it"));
    20662077            if (_dataBuf != null && _dataBuf.getData().length == BUFFER_SIZE)
    20672078                releaseReadBuf(_dataBuf);
     
    21402151        public void gotTermination(int reason, long lastReceived) {
    21412152            if (_log.shouldInfo())
    2142                 _log.info("Got Termination: " + reason + " total rcvd: " + lastReceived);
    2143             _terminated = true;
     2153                _log.info("Got Termination: " + reason + " total rcvd: " + lastReceived + " on " + NTCPConnection.this);
     2154            // close() calls destroy() sets _terminated
    21442155            close();
    21452156        }
     
    21472158        public void gotUnknown(int type, int len) {
    21482159            if (_log.shouldWarn())
    2149                 _log.warn("Got unknown block type " + type + " length " + len);
     2160                _log.warn("Got unknown block type " + type + " length " + len + " on " + NTCPConnection.this);
    21502161        }
    21512162
     
    21652176     * This replaces _curReadState, so no more messages will be received.
    21662177     *
     2178     * Call this only on data phase AEAD failure.
     2179     * For other failures, use sendTermination().
     2180     *
    21672181     * @param buf possibly with data remaining
    21682182     * @param validFramesRcvd to be sent in termination message
     
    21742188        if (remaining > 0) {
    21752189            if (_log.shouldWarn())
    2176                 _log.warn("delayed close after AEAD failure, to read: " + toRead);
     2190                _log.warn("delayed close, AEAD failure after " + validFramesRcvd +
     2191                          " good frames, to read: " + toRead + " on " + this, new Exception("I did it"));
    21772192            _curReadState = new NTCP2FailState(toRead, validFramesRcvd);
    21782193            _curReadState.receive(buf);
    21792194        } else {
    21802195            if (_log.shouldWarn())
    2181                 _log.warn("immediate close after AEAD failure and reading " + toRead);
     2196                _log.warn("immediate close, AEAD failure after " + validFramesRcvd +
     2197                          " good frames and reading " + toRead + " on " + this, new Exception("I did it"));
    21822198            sendTermination(REASON_AEAD, validFramesRcvd);
    21832199        }
     
    22152231                _read = Integer.MIN_VALUE;
    22162232                if (_log.shouldWarn())
    2217                     _log.warn("close after AEAD failure and reading " + _toRead);
     2233                    _log.warn("close after AEAD failure and reading " + _toRead + " on " + NTCPConnection.this);
    22182234                sendTermination(REASON_AEAD, _validFramesRcvd);
    22192235            }
     
    22282244            _read = Integer.MIN_VALUE;
    22292245            if (_log.shouldWarn())
    2230                 _log.warn("timeout after AEAD failure waiting for more data");
     2246                _log.warn("timeout after AEAD failure waiting for more data on " + NTCPConnection.this);
    22312247            sendTermination(REASON_AEAD, _validFramesRcvd);
    22322248        }
Note: See TracChangeset for help on using the changeset viewer.