Changeset b5117ea


Ignore:
Timestamp:
Jun 2, 2018 3:53:06 PM (3 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
02855a0
Parents:
05ffa63
Message:

NTCP2: Data phase payload generation and parsing

Location:
router/java/src/net/i2p
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/data/i2np/I2NPMessageImpl.java

    r05ffa63 rb5117ea  
    439439            int dataSize = len - 1 - 4;
    440440            msg.readMessage(buffer, offset, dataSize, type, handler);
     441            msg.setMessageExpiration(expiration);
     442            return msg;
     443        } catch (IllegalArgumentException iae) {
     444            throw new I2NPMessageException("Corrupt message (negative expiration)", iae);
     445        }
     446    }
     447
     448    /**
     449     *  Read the message with a short 9-byte header.
     450     *  THe header consists of a one-byte type, 4-byte ID, and a 4-byte expiration in seconds only.
     451     *  Used by NTCP2 only!
     452     *  @since 0.9.35
     453     */
     454    public static I2NPMessage fromRawByteArrayNTCP2(I2PAppContext ctx, byte buffer[], int offset,
     455                                                    int len, I2NPMessageHandler handler) throws I2NPMessageException {
     456        int type = buffer[offset] & 0xff;
     457        offset++;
     458        I2NPMessage msg = createMessage(ctx, type);
     459        if (msg == null)
     460            throw new I2NPMessageException("Unknown message type: " + type);
     461
     462        try {
     463            long id = DataHelper.fromLong(buffer, offset, 4);
     464            offset += 4;
     465            // January 19 2038? No, unsigned, good until Feb. 7 2106
     466            // in seconds, round up so we don't lose time every hop
     467            long expiration = (DataHelper.fromLong(buffer, offset, 4) * 1000) + 500;
     468            offset += 4;
     469            int dataSize = len - 9;
     470            msg.readMessage(buffer, offset, dataSize, type, handler);
     471            msg.setUniqueId(id);
    441472            msg.setMessageExpiration(expiration);
    442473            return msg;
Note: See TracChangeset for help on using the changeset viewer.