Changeset 25e567a1 for router


Ignore:
Timestamp:
Jul 5, 2018 2:31:54 PM (2 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
7aca1e40
Parents:
43c2018
Message:

NTCP2: Increase max message size
OutNetMessage?: Change size from long to int

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

Legend:

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

    r43c2018 r25e567a1  
    3737    /** cached message ID, for use after we discard the message */
    3838    private final long _messageId;
    39     private final long _messageSize;
     39    private final int _messageSize;
    4040    private final int _priority;
    4141    private final long _expiration;
     
    201201     */
    202202    public String getMessageType() {
    203         I2NPMessage msg = _message;
    204         return msg != null ? msg.getClass().getSimpleName() : "null";
     203        return _message != null ? _message.getClass().getSimpleName() : "null";
    205204    }
    206205
     
    208207    public long getMessageId() { return _messageId; }
    209208   
    210     public long getMessageSize() {
     209    /**
     210     * How large the message is, including the full 16 byte header.
     211     * Transports with different header sizes should adjust.
     212     */
     213    public int getMessageSize() {
    211214        return _messageSize;
    212215    }
  • router/java/src/net/i2p/router/transport/Transport.java

    r43c2018 r25e567a1  
    2929 */
    3030public interface Transport {
    31     public TransportBid bid(RouterInfo toAddress, long dataSize);
     31
     32    /**
     33     *
     34     * @param dataSize assumes full 16-byte header, transports should
     35     *        adjust as necessary
     36     * @return a bid or null if unwilling to send
     37     *
     38     */
     39    public TransportBid bid(RouterInfo toAddress, int dataSize);
     40
    3241    /**
    3342     * Asynchronously send the message as requested in the message and, if the
  • router/java/src/net/i2p/router/transport/ntcp/NTCPConnection.java

    r43c2018 r25e567a1  
    162162     *  In the meantime, don't let the transport bid on big messages.
    163163     */
    164     public static final int BUFFER_SIZE = 16*1024;
     164    static final int BUFFER_SIZE = 16*1024;
    165165    private static final int MAX_DATA_READ_BUFS = 16;
    166166    private static final ByteCache _dataReadBufs = ByteCache.getInstance(MAX_DATA_READ_BUFS, BUFFER_SIZE);
    167167    /** 2 bytes for length and 4 for CRC */
    168     public static final int MAX_MSG_SIZE = BUFFER_SIZE - (2 + 4);
     168    static final int NTCP1_MAX_MSG_SIZE = BUFFER_SIZE - (2 + 4);
    169169
    170170    private static final int INFO_PRIORITY = OutNetMessage.PRIORITY_MY_NETDB_STORE_LOW;
     
    175175    //// NTCP2 things
    176176
     177    /** See spec. Max Noise payload 65535,
     178     *  minus 16 byte MAC and 3 byte block header.
     179     *  Includes 9-byte I2NP header.
     180     */
     181    static final int NTCP2_MAX_MSG_SIZE = 65516;
    177182    private static final int PADDING_RAND_MIN = 16;
    178183    private static final int PADDING_MAX = 64;
     
    181186    private static final long NTCP2_FAIL_TIMEOUT = 10*1000;
    182187    private static final long NTCP2_TERMINATION_CLOSE_DELAY = 50;
     188    // don't make combined messages too big, to minimize latency
     189    private static final int NTCP2_PREFERRED_PAYLOAD_MAX = 5000;
    183190    static final int REASON_UNSPEC = 0;
    184191    static final int REASON_TERMINATION = 1;
     
    833840            }
    834841            _currentOutbound.add(msg);
    835             // don't make combined msgs too big to minimize latency
    836             final int MAX_MSG_SIZE = 5000;
    837842            I2NPMessage m = msg.getMessage();
    838843            Block block = new NTCP2Payload.I2NPBlock(m);
     
    840845            size += block.getTotalLength();
    841846            // now add more (maybe)
    842             if (size < MAX_MSG_SIZE) {
     847            if (size < NTCP2_PREFERRED_PAYLOAD_MAX) {
    843848                // keep adding as long as we will be under 5 KB
    844849                while (true) {
     
    848853                    m = msg.getMessage();
    849854                    int msz = m.getMessageSize() - 7;
    850                     if (size + msz > MAX_MSG_SIZE)
     855                    if (size + msz > NTCP2_PREFERRED_PAYLOAD_MAX)
    851856                        break;
    852857                    OutNetMessage msg2 = _outbound.poll();
  • router/java/src/net/i2p/router/transport/ntcp/NTCPTransport.java

    r43c2018 r25e567a1  
    460460    }
    461461
    462     public TransportBid bid(RouterInfo toAddress, long dataSize) {
     462    public TransportBid bid(RouterInfo toAddress, int dataSize) {
    463463        if (!isAlive())
    464464            return null;
    465         if (dataSize > NTCPConnection.MAX_MSG_SIZE) {
    466             // let SSU deal with it
     465        // passed in dataSize assumes 16 byte header, if NTCP2 then
     466        // we have a 9-byte header so there's 7 to spare
     467        if (dataSize > NTCPConnection.NTCP2_MAX_MSG_SIZE + 7 ||
     468            (!_enableNTCP2 && dataSize > NTCPConnection.NTCP1_MAX_MSG_SIZE)) {
     469            // Too big for NTCP2, or NTCP2 disabled and too big for NTCP1
     470            // Let SSU deal with it
    467471            _context.statManager().addRateData("ntcp.noBidTooLargeI2NP", dataSize);
    468472            return null;
     
    479483        }
    480484
    481         boolean established = isEstablished(toAddress.getIdentity());
     485        boolean established = isEstablished(peer);
    482486        if (established) { // should we check the queue size?  nah, if its valid, use it
    483             //if (_log.shouldLog(Log.DEBUG))
    484             //    _log.debug("fast bid when trying to send to " + peer + " as its already established");
     487            if (dataSize > NTCPConnection.NTCP1_MAX_MSG_SIZE) {
     488                // Must be version 2 to send a big message
     489                NTCPConnection con = _conByIdent.get(peer);
     490                if (con == null || con.getVersion() < NTCP2_INT_VERSION) {
     491                    _context.statManager().addRateData("ntcp.noBidTooLargeI2NP", dataSize);
     492                    return null;
     493                }
     494            }
    485495            return _fastBid;
     496        }
     497        if (dataSize > NTCPConnection.NTCP1_MAX_MSG_SIZE) {
     498            // Not established, too big for NTCP 1, let SSU deal with it
     499            // TODO look at his addresses to see if NTCP2 supported?
     500            _context.statManager().addRateData("ntcp.noBidTooLargeI2NP", dataSize);
     501            return null;
    486502        }
    487503
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r43c2018 r25e567a1  
    17401740    }
    17411741
    1742     public TransportBid bid(RouterInfo toAddress, long dataSize) {
     1742    public TransportBid bid(RouterInfo toAddress, int dataSize) {
    17431743        if (dataSize > OutboundMessageState.MAX_MSG_SIZE) {
    17441744            // NTCP max is lower, so msg will get dropped
Note: See TracChangeset for help on using the changeset viewer.