java.lang.Object
net.i2p.client.datagram.I2PDatagramMaker

public final class I2PDatagramMakerextends Object
Class for creating I2P repliable datagrams. Note that objects of this class are NOT THREAD SAFE!
  • Field Details

    • INIT_DGRAM_BUFSIZE

      private static final int INIT_DGRAM_BUFSIZE
      Starting size of the datagram buffer, in bytes.
      See Also:
    • MAX_DGRAM_BUFSIZE

      private static final int MAX_DGRAM_BUFSIZE
      Largest datagram that can be made, in bytes.
      See Also:
    • hashGen

      private final SHA256Generator hashGen
      Hashes the datagram contents.
    • dsaEng

      private final DSAEngine dsaEng
      Signs the datagram.
    • sxPrivKey

      private SigningPrivateKey sxPrivKey
      Key that signs the datagrams.
    • sxDestBytes

      private byte[] sxDestBytes
      This maker's destination, embedded in each datagram.
    • sxDGram

      private final ByteArrayOutputStream sxDGram
      Buffer the datagram is assembled in.
  • Constructor Details

    • I2PDatagramMaker

      public I2PDatagramMaker(I2PSession session)
      An I2PDatagramMaker able to create I2P repliable datagrams going to be sent through the specified I2PSession.

      Does NOT support LS2 offline keys!

      Parameters:
      session - I2PSession used to send I2PDatagrams through
      Throws:
      IllegalArgumentException - if session has offline keys
    • I2PDatagramMaker

      public I2PDatagramMaker()
      An I2PDatagramMaker with no session yet; use setI2PDatagramMaker to set the parameters.
  • Method Details

    • setI2PDatagramMaker

      public void setI2PDatagramMaker(I2PSession session)
      Does NOT support LS2 offline keys!
      Parameters:
      session - I2PSession used to send I2PDatagrams through
      Throws:
      IllegalArgumentException - if session has offline keys
    • makeI2PDatagram

      public byte[] makeI2PDatagram(byte[] payload)
      Make a repliable I2P datagram containing the specified payload.

      Format is:

      1. Destination (387+ bytes)
      2. Signature (40+ bytes, type and length as implied by signing key type in the Destination)
      3. Payload

      Maximum datagram size is ~64KB, so maximum payload size is a little less. Practical maximum is a few KB less due to Destination and Garlic overhead. 10 KB or less is recommended for best results.

      For DSA_SHA1 Destinations, the signature is of the SHA-256 Hash of the payload.

      As of 0.9.14, for non-DSA_SHA1 Destinations, the signature is of the payload itself.

      Parameters:
      payload - non-null Bytes to be contained in the I2P datagram.
      Returns:
      null on error
      Throws:
      IllegalArgumentException - if payload is too big
      IllegalStateException - if Destination signature type unsupported