Changeset fc817b0


Ignore:
Timestamp:
Jul 26, 2018 12:17:50 PM (21 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
2586db9
Parents:
2f2ff4f
Message:

NTCP2: Defer NTCP ½ classifiation until receiving 64 bytes

File:
1 edited

Legend:

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

    r2f2ff4f rfc817b0  
    148148            return;
    149149        }
    150         // TODO if less than 64, buffer and decide later?
    151150        if (_state == State.IB_INIT && src.hasRemaining()) {
    152151            int remaining = src.remaining();
    153             if (remaining < NTCP1_MSG1_SIZE && _transport.isNTCP2Enabled()) {
    154                 // NTCP2
    155                 // TODO can't change our mind later if we get more than 287
    156                 _con.setVersion(2);
    157                 changeState(State.IB_NTCP2_INIT);
    158                 receiveInboundNTCP2(src);
    159                 // releaseBufs() will return the unused DH
    160                 return;
     152            if (_transport.isNTCP2Enabled()) {
     153                if (remaining + _received < MSG1_SIZE) {
     154                    // Less than 64 total received, so we defer the NTCP 1 or 2 decision.
     155                    // Buffer in _X.
     156                    // Stay in the IB_INIT state, and wait for more data.
     157                    src.get(_X, _received, remaining);
     158                    _received += remaining;
     159                    if (_log.shouldWarn())
     160                        _log.warn("Short buffer got " + remaining + " total now " + _received + " on " + this);
     161                    return;
     162                }
     163                if (remaining + _received < NTCP1_MSG1_SIZE) {
     164                    // Less than 288 total received, assume NTCP2
     165                    // TODO can't change our mind later if we get more than 287
     166                    _con.setVersion(2);
     167                    changeState(State.IB_NTCP2_INIT);
     168                    receiveInboundNTCP2(src);
     169                    // releaseBufs() will return the unused DH
     170                    return;
     171                }
    161172            }
    162173            int toGet = Math.min(remaining, XY_SIZE - _received);
     
    621632            _received += toGet;
    622633            if (_received < MSG1_SIZE) {
    623                 // TODO if we got less than 64 should we even be here?
     634                // Won't get here, now handled in receiveInbound()
    624635                if (_log.shouldWarn())
    625636                    _log.warn("Short buffer got " + toGet + " total now " + _received);
Note: See TracChangeset for help on using the changeset viewer.