java.lang.Object
net.i2p.sam.SAMMessageSession
net.i2p.sam.SAMDatagramSession
All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess
Direct Known Subclasses:
SAMv3DatagramSession

class SAMDatagramSessionextends SAMMessageSession
SAM DATAGRAM session class.
  • Field Details

    • DGRAM_SIZE_MAX

      public static final int DGRAM_SIZE_MAX
      Largest datagram payload accepted in either direction, in bytes.
      See Also:
    • recv

      protected SAMDatagramReceiver recv
      Receiver this session hands assembled incoming datagrams to.
    • dgramMaker

      private final I2PDatagramMaker dgramMaker
      Makes the datagrams this session sends.
    • dgramDissector

      private final I2PDatagramDissector dgramDissector
      Dissects the datagrams this session receives
  • Constructor Details

    • SAMDatagramSession

      protected SAMDatagramSession(String dest, Properties props, SAMDatagramReceiver recv) throws IOException, DataFormatException, I2PSessionException
      Create a new SAM DATAGRAM session.
      Parameters:
      dest - Base64-encoded destination (private key)
      props - Properties to setup the I2P session
      recv - Object that will receive incoming data
      Throws:
      IOException - declared on this constructor, but not raised by the body
      DataFormatException - likewise declared, but not raised by the body
      I2PSessionException - if the I2P session cannot be created from dest
    • SAMDatagramSession

      public SAMDatagramSession(InputStream destStream, Properties props, SAMDatagramReceiver recv) throws I2PSessionException
      Create a new SAM DATAGRAM session.

      Caller MUST call start().

      Parameters:
      destStream - Input stream containing the destination keys
      props - Properties to setup the I2P session
      recv - Object that will receive incoming data
      Throws:
      I2PSessionException - if the I2P session cannot be created from the keys read out of destStream
    • SAMDatagramSession

      protected SAMDatagramSession(I2PSession sess, Properties props, int listenProtocol, int listenPort, SAMDatagramReceiver recv) throws I2PSessionException
      Create a new SAM DATAGRAM session on an existing I2P session.
      Parameters:
      sess - the already-established I2P session to run over, which this session does not own
      props - unused for now
      listenProtocol - the tunnel protocol for the datagram tunnel, normally PROTO_DATAGRAM
      listenPort - the local port the datagram tunnel is published from
      recv - the object handed each datagram that arrives on the session
      Throws:
      I2PSessionException - not raised here, since the body only wires up the session
  • Method Details

    • sendBytes

      public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException
      Send bytes through a SAM DATAGRAM session.
      Specified by:
      sendBytes in interface SAMMessageSess
      Specified by:
      sendBytes in class SAMMessageSession
      Parameters:
      dest - the .b32.i2p address to send to
      data - Bytes to be sent
      proto - ignored, will always use PROTO_DATAGRAM (17)
      fromPort - the I2CP from port, 0 for the default
      toPort - the I2CP to port, 0 for the default
      Returns:
      True if the data was sent, false otherwise
      Throws:
      DataFormatException - on unknown / bad dest
      I2PSessionException - on serious error, probably session closed
    • sendBytes

      public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) throws DataFormatException, I2PSessionException
      Send bytes through a SAM DATAGRAM session.
      Parameters:
      dest - the base32 destination or .b32.i2p hostname to send to
      data - the bytes to send
      proto - the I2CP protocol to send under
      fromPort - the I2CP from port, 0 for the default
      toPort - the I2CP to port, 0 for the default
      sendLeaseSet - true to include the LeaseSet in the message
      sendTags - the number of tunnels to include, 0 to leave as default
      tagThreshold - the build success ratio below which no tunnel is sent, 0 for default
      expiration - the lease lifetime in seconds from now, 0 to leave as default
      Returns:
      True if the data was sent, false otherwise
      Throws:
      DataFormatException - if dest is not a valid destination
      I2PSessionException - on serious error, probably session closed
    • messageReceived

      protected void messageReceived(byte[] msg, int proto, int fromPort, int toPort)
      Handle a received datagram message from I2P.
      Specified by:
      messageReceived in class SAMMessageSession
      Parameters:
      msg - the raw I2P datagram message
      proto - the I2CP protocol
      fromPort - the I2CP from port
      toPort - the I2CP to port
    • shutDown

      protected void shutDown()
      Shut down the datagram session.
      Specified by:
      shutDown in class SAMMessageSession