All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess
Direct Known Subclasses:
SAMv3RawSession

class SAMRawSessionextends SAMMessageSession
SAM RAW session class.
  • Field Details

    • RAW_SIZE_MAX

      public static final int RAW_SIZE_MAX
      Largest datagram this session will send, in bytes; larger is rejected.
      See Also:
    • recv

      protected SAMRawReceiver recv
      Receiver handed the raw bytes arriving from the tunnel.
  • Constructor Details

    • SAMRawSession

      protected SAMRawSession(String dest, Properties props, SAMRawReceiver recv) throws IOException, DataFormatException, I2PSessionException
      Create a new SAM RAW session.
      Parameters:
      dest - Base64-encoded destination and private keys (same format as PrivateKeyFile)
      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
    • SAMRawSession

      public SAMRawSession(InputStream destStream, Properties props, SAMRawReceiver recv) throws I2PSessionException
      Create a new SAM RAW session.

      Caller MUST call start().

      Parameters:
      destStream - Input stream containing the destination and private keys (same format as PrivateKeyFile)
      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
    • SAMRawSession

      protected SAMRawSession(I2PSession sess, Properties props, int listenProtocol, int listenPort, SAMRawReceiver recv) throws I2PSessionException
      Create a new SAM RAW session on an existing I2P session.
      Parameters:
      sess - the already established session to share
      props - unused for now
      listenProtocol - protocol number to accept datagrams for, 1-254 or PROTO_ANY (0)
      listenPort - port to accept datagrams on, 1-65535 or PORT_ANY (0)
      recv - Object that will receive incoming data
      Throws:
      I2PSessionException - if the shared session cannot be attached to
  • Method Details

    • sendBytes

      public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException
      Send bytes through a SAM RAW session.
      Specified by:
      sendBytes in interface SAMMessageSess
      Specified by:
      sendBytes in class SAMMessageSession
      Parameters:
      dest - destination to send to, as base64, a .b32.i2p name or a hostname
      data - Bytes to be sent
      proto - if 0, will use PROTO_DATAGRAM_RAW (18)
      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 RAW 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 raw message from I2P.
      Specified by:
      messageReceived in class SAMMessageSession
      Parameters:
      msg - the raw I2P message
      proto - the I2CP protocol
      fromPort - the I2CP from port
      toPort - the I2CP to port
    • shutDown

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