Changeset 1b6c002 for router


Ignore:
Timestamp:
Aug 2, 2018 10:56:14 AM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2e85c23
Parents:
726d2f4
Message:

NTCP2: Send termination on idle timeout
Use timer to delay close after sending termination
Prevent sending more data after termination

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

Legend:

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

    r726d2f4 r1b6c002  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 19;
     21    public final static long BUILD = 20;
    2222
    2323    /** for example "-test" */
  • router/java/src/net/i2p/router/transport/ntcp/EventPumper.java

    r726d2f4 r1b6c002  
    297297                                     con.getTimeSinceReceive() > expire) {
    298298                                    // we haven't sent or received anything in a really long time, so lets just close 'er up
    299                                     con.close();
     299                                    con.sendTerminationAndClose();
    300300                                    if (_log.shouldInfo())
    301301                                        _log.info("Failsafe or expire close for " + con);
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r726d2f4 r1b6c002  
    630630    private void enqueueInfoMessageNTCP1() {
    631631        int priority = INFO_PRIORITY;
    632         if (_log.shouldLog(Log.INFO))
    633             _log.info("SENDING INFO message pri. " + priority + ": " + toString());
     632        if (_log.shouldDebug())
     633            _log.debug("SENDING INFO message pri. " + priority + ": " + toString());
    634634        DatabaseStoreMessage dsm = new DatabaseStoreMessage(_context);
    635635        dsm.setEntry(_context.router().getRouterInfo());
     
    993993
    994994    /**
    995      *  NTCP2 only
     995     *  NTCP 1 or 2.
     996     *  For NTCP1, sends termination and then closes the connection after a brief delay.
     997     *  For NTCP2, simply closes the connection immediately.
     998     *
     999     *  @since 0.9.36
     1000     */
     1001    void sendTerminationAndClose() {
     1002        ReadState rs = null;
     1003        synchronized (this) {
     1004            if (_version == 2 && isEstablished())
     1005                rs = _curReadState;
     1006        }
     1007        if (rs != null)
     1008            sendTermination(REASON_TIMEOUT, rs.getFramesReceived());
     1009        else
     1010            close();
     1011    }
     1012
     1013    /**
     1014     *  NTCP2 only. Also closes the connection after a brief delay.
    9961015     *
    9971016     *  @since 0.9.36
     
    10161035        // use a "read buf" for the temp array
    10171036        ByteArray dataBuf = acquireReadBuf();
    1018         sendNTCP2(dataBuf.getData(), blocks);
     1037        synchronized(this) {
     1038            if (_sender != null) {
     1039                sendNTCP2(dataBuf.getData(), blocks);
     1040                _sender.destroy();
     1041                // this "plugs" the NTCP2 sender, so sendNTCP2()
     1042                // won't send any more after the termination.
     1043                _sender = null;
     1044                new DelayedCloser();
     1045            }
     1046        }
    10191047        releaseReadBuf(dataBuf);
    10201048    }
     
    12401268            if (!_outbound.isEmpty())
    12411269                _transport.getWriter().wantsWrite(this, "write completed");
    1242             if (_log.shouldLog(Log.INFO))
    1243                 _log.info("I2NP meta message sent completely");
     1270            if (_log.shouldDebug())
     1271                _log.debug("I2NP meta message sent completely");
    12441272            // need to increment as EventPumper will close conn if not completed
    12451273            _messagesWritten.incrementAndGet();
     
    14281456        public void receive(ByteBuffer buf);
    14291457        public void destroy();
     1458        public int getFramesReceived();
    14301459    }
    14311460
     
    17341763            init();
    17351764        }
     1765
     1766        /*
     1767         * Dummy.
     1768         * @return 0 always
     1769         * @since 0.9.36
     1770         */
     1771        public int getFramesReceived() { return 0; }
    17361772    }
    17371773
     
    18201856        _paddingConfig = OUR_PADDING;
    18211857        sendTermination(reason, 0);
    1822         try { Thread.sleep(NTCP2_TERMINATION_CLOSE_DELAY); } catch (InterruptedException ie) {}
    1823         close();
    18241858    }
    18251859
     
    20322066        }
    20332067
     2068        public int getFramesReceived() { return _frameCount; }
     2069
    20342070        //// PayloadCallbacks
    20352071
     
    21402176                _log.warn("immediate close after AEAD failure and reading " + toRead);
    21412177            sendTermination(REASON_AEAD, validFramesRcvd);
    2142             try { Thread.sleep(NTCP2_TERMINATION_CLOSE_DELAY); } catch (InterruptedException ie) {}
    2143             close();
    21442178        }
    21452179    }
     
    21732207            if (_read >= _toRead) {
    21742208                cancel();
     2209                // only do this once
     2210                _read = Integer.MIN_VALUE;
    21752211                if (_log.shouldWarn())
    21762212                    _log.warn("close after AEAD failure and reading " + _toRead);
    21772213                sendTermination(REASON_AEAD, _validFramesRcvd);
    2178                 try { Thread.sleep(NTCP2_TERMINATION_CLOSE_DELAY); } catch (InterruptedException ie) {}
    2179                 close();
    21802214            }
    21812215        }
     
    21862220
    21872221        public void timeReached() {
     2222            // only do this once
     2223            _read = Integer.MIN_VALUE;
    21882224            if (_log.shouldWarn())
    21892225                _log.warn("timeout after AEAD failure waiting for more data");
    21902226            sendTermination(REASON_AEAD, _validFramesRcvd);
    2191             try { Thread.sleep(NTCP2_TERMINATION_CLOSE_DELAY); } catch (InterruptedException ie) {}
     2227        }
     2228
     2229        public int getFramesReceived() { return 0; }
     2230    }
     2231
     2232    /**
     2233     * Close after a brief timeout.
     2234     * Construct after sending termination.
     2235     *
     2236     * @since 0.9.36
     2237     */
     2238    private class DelayedCloser extends SimpleTimer2.TimedEvent {
     2239
     2240        /** schedules itself */
     2241        public DelayedCloser() {
     2242            super(_context.simpleTimer2());
     2243            schedule(NTCP2_TERMINATION_CLOSE_DELAY);
     2244        }
     2245
     2246        public void timeReached() {
    21922247            close();
    21932248        }
Note: See TracChangeset for help on using the changeset viewer.