net.i2p.router.transport.ntcp

## Class NTCP2Payload

- java.lang.Object
- - net.i2p.router.transport.ntcp.NTCP2Payload

-     class NTCP2Payload
      extends Object

  NTCP 2 payload generation and parsing utilities.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `NTCP2Payload.Block` Base class for NTCP 2 payload blocks.
    `static class` | `NTCP2Payload.DateTimeBlock` Block containing the current date and time.
    `static class` | `NTCP2Payload.I2NPBlock` Block containing I2NP message.
    `static class` | `NTCP2Payload.OptionsBlock` Block containing options data.
    `static class` | `NTCP2Payload.PaddingBlock` Block containing padding data.
    `static interface` | `NTCP2Payload.PayloadCallback` For all callbacks, recommend throwing exceptions only from the handshake.
    `static class` | `NTCP2Payload.RIBlock` Block containing router information.
    `static class` | `NTCP2Payload.TerminationBlock` Block containing termination data.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BLOCK_HEADER_SIZE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NTCP2Payload()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static int` | `processPayload(I2PAppContext ctx, NTCP2Payload.PayloadCallback cb, byte[] payload, int off, int length, boolean isHandshake)` Incoming payload.
    `static int` | `writePayload(byte[] payload, int off, List<NTCP2Payload.Block> blocks)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BLOCK_HEADER_SIZE

          public static final int BLOCK_HEADER_SIZE

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### NTCP2Payload

          NTCP2Payload()

  - ### Method Detail

    - #### processPayload

          public static int processPayload(I2PAppContext ctx,
                                           NTCP2Payload.PayloadCallback cb,
                                           byte[] payload,
                                           int off,
                                           int length,
                                           boolean isHandshake)
                                    throws IOException,
                                           DataFormatException,
                                           I2NPMessageException

      Incoming payload. Calls the callback for each received block.
      Returns:
        number of blocks processed
      Throws:
        `IOException` - on major errors
        `DataFormatException` - on parsing of individual blocks
        `I2NPMessageException` - on parsing of I2NP block

    - #### writePayload

          public static int writePayload(byte[] payload,
                                         int off,
                                         List<NTCP2Payload.Block> blocks)

      Parameters:
        `payload` - writes to it starting at off
      Returns:
        the new offset