All Implemented Interfaces:
Closeable, AutoCloseable, SAMMessageSess, SAMRawReceiver, Session

class SAMv3RawSessionextends SAMRawSession implements Session, SAMRawReceiver
SAM v3 raw session implementation.
  • Field Details

    • nick

      private final String nick
      Name the client gave this session.
    • handler

      private final SAMv3Handler handler
      The handler that created this session.
    • server

      private final SAMv3DatagramServer server
      The UDP server the session is registered with.
    • clientAddress

      private final SocketAddress clientAddress
      Where the client's datagrams come from.
    • _sendHeader

      private final boolean _sendHeader
      True to prefix replies with the destination's key.
  • Constructor Details

    • SAMv3RawSession

      public SAMv3RawSession(String nick, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException
      Build a Raw Datagram Session according to information registered with the given nickname

      Caller MUST call start().

      Parameters:
      nick - nickname of the session
      dgServer - the datagram server this session reports its senders to
      Throws:
      IOException - if the nickname is not registered; the lookup throws InterruptedIOException
      DataFormatException - declared on the superclass constructor, but not raised by the body
      I2PSessionException - if the I2P session cannot be created from the recorded destination
    • SAMv3RawSession

      public SAMv3RawSession(String nick, Properties props, SAMv3Handler handler, I2PSession isess, int listenProtocol, int listenPort, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException
      Build a Raw Session on an existing i2p session registered with the given nickname

      Caller MUST call start().

      Parameters:
      nick - nickname of the session
      props - the session properties, read for PORT and HOST
      handler - the SAM handler owning the session record
      isess - the already-running I2P session to wrap, not owned here
      listenProtocol - the I2CP protocol to bind, or I2PSession.PROTO_ANY for all
      listenPort - the local port to bind, or I2PSession.PORT_ANY to let the router choose
      dgServer - the datagram server this session reports its senders to
      Throws:
      IOException - declared on this constructor, but not raised by the body
      DataFormatException - likewise declared, but not raised by the body
      I2PSessionException - if the shared session cannot be attached to
  • Method Details

    • getNick

      public String getNick()
      Get the session nickname.
      Specified by:
      getNick in interface Session
      Returns:
      the nickname this session was registered under
    • getRec

      private static SessionRecord getRec(String nick) throws InterruptedIOException
      Look up the registered session record for the given nickname, throwing if it has already disappeared.
      Parameters:
      nick - the registered session nickname to look up
      Returns:
      the registered session record
      Throws:
      InterruptedIOException - if the nickname is not registered
    • getSocketAddress

      static SocketAddress getSocketAddress(Properties props, SAMv3Handler handler)
      Get the socket address from session properties.
      Parameters:
      props - the session properties containing PORT and optionally HOST
      handler - the SAM handler for client IP fallback
      Returns:
      the socket address, or null if PORT is not set
    • receiveRawBytes

      public void receiveRawBytes(byte[] data, int proto, int fromPort, int toPort) throws IOException
      Receive raw data from I2P and forward to the SAM client.
      Specified by:
      receiveRawBytes in interface SAMRawReceiver
      Parameters:
      data - the raw data payload
      proto - the I2CP protocol
      fromPort - the I2CP from port
      toPort - the I2CP to port
      Throws:
      IOException - if forwarding to the client fails
    • stopRawReceiving

      public void stopRawReceiving()
      Stop receiving raw data.
      Specified by:
      stopRawReceiving in interface SAMRawReceiver