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

class SAMv3DatagramSessionextends SAMDatagramSession implements Session, SAMDatagramReceiver
SAM v3 datagram session implementation.
  • Field Details

    • handler

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

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

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

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

    • SAMv3DatagramSession

      public SAMv3DatagramSession(String nick, SAMv3DatagramServer dgServer) throws IOException, DataFormatException, I2PSessionException, SAMException
      Build a DatagramSession according to informations registered with the given nickname

      Caller MUST call start().

      Parameters:
      nick - nickname of the session
      dgServer - the datagram server that dispatches datagrams to this session
      Throws:
      IOException - declared on this constructor, but not raised by the body
      DataFormatException - likewise declared, but not raised by the body
      I2PSessionException - if the session registered under nick cannot be rebuilt from the record's destination
      SAMException - if the nickname is no longer registered
    • SAMv3DatagramSession

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

      Caller MUST call start().

      Parameters:
      nick - nickname of the session
      props - session properties read from the SESSION CREATE command
      handler - handler used to send DATAGRAM replies back to the client
      isess - the existing I2P session this datagram session runs over
      listenProtocol - datagram protocol number to listen for, 0 for any
      listenPort - local port to listen on, 0 for any
      dgServer - the datagram server that dispatches datagrams to this session
      Throws:
      IOException - declared on this constructor, but not raised by the body
      DataFormatException - likewise declared, but not raised by the body
      I2PSessionException - declared on this constructor, but not raised by the body
  • Method Details

    • getNick

      public String getNick()
      Get the session nickname.
      Specified by:
      getNick in interface Session
      Returns:
      the nickname this session is registered under with the SAM v3 handler
    • getRec

      private static SessionRecord getRec(String nick) throws SAMException
      Look up the registered session record for the given nickname, throwing if it has already disappeared.
      Parameters:
      nick - the nickname the session was registered under
      Returns:
      the registered session record, never null because a missing one is thrown rather than returned
      Throws:
      SAMException - if the nickname is not registered
    • receiveDatagramBytes

      public void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException
      Receive a datagram from I2P and forward to the SAM client.
      Specified by:
      receiveDatagramBytes in interface SAMDatagramReceiver
      Parameters:
      sender - the destination that sent the datagram
      data - the datagram payload
      proto - the I2CP protocol
      fromPort - the I2CP from port
      toPort - the I2CP to port
      Throws:
      IOException - if forwarding to the client fails
    • stopDatagramReceiving

      public void stopDatagramReceiving()
      Stop receiving datagrams.
      Specified by:
      stopDatagramReceiving in interface SAMDatagramReceiver