Package net.i2p.sam

Class PrimarySession

All Implemented Interfaces:
Closeable, AutoCloseable, I2PSessionListener, I2PSessionMuxedListener, SAMDatagramReceiver, SAMMessageSess, SAMRawReceiver, Session

A session that does nothing, but implements interfaces for raw, datagram, and streaming for convenience. We extend SAMv3StreamSession as we must have it set up the I2PSession, in case user adds a STREAM session (and he probably will). This session receives all data from I2P, but you can't send any data on it.
Since:
0.9.25
  • Constructor Details

  • Method Details

    • start

      public void start()
      Overridden to start the acceptor.
      Specified by:
      start in interface SAMMessageSess
      Overrides:
      start in class SAMStreamSession
    • add

      public String add(String nick, String style, Properties props)
      Add a session
      Returns:
      null for success, or error message
    • remove

      public String remove(String nick, Properties props)
      Remove a session
      Parameters:
      props - ignored, may be null
      Returns:
      null for success, or error message
    • receiveDatagramBytes

      public void receiveDatagramBytes(Destination sender, byte[] data, int proto, int fromPort, int toPort) throws IOException
      Description copied from interface: SAMDatagramReceiver
      Send a byte array to a SAM client.
      Specified by:
      receiveDatagramBytes in interface SAMDatagramReceiver
      Parameters:
      sender - Destination
      data - Byte array to be received
      proto - I2CP protocol
      fromPort - I2CP from port
      toPort - I2CP to port
      Throws:
      IOException - always
    • stopDatagramReceiving

      public void stopDatagramReceiving()
      Does nothing.
      Specified by:
      stopDatagramReceiving in interface SAMDatagramReceiver
    • receiveRawBytes

      public void receiveRawBytes(byte[] data, int proto, int fromPort, int toPort) throws IOException
      Description copied from interface: SAMRawReceiver
      Send a byte array to a SAM client, without informations regarding the sender.
      Specified by:
      receiveRawBytes in interface SAMRawReceiver
      Parameters:
      data - Byte array to be received
      proto - I2CP protocol
      fromPort - I2CP from port
      toPort - I2CP to port
      Throws:
      IOException - always
    • stopRawReceiving

      public void stopRawReceiving()
      Does nothing.
      Specified by:
      stopRawReceiving in interface SAMRawReceiver
    • connect

      public void connect(SAMv3Handler handler, String dest, Properties props) throws I2PException
      Description copied from class: SAMv3StreamSession
      Connect the SAM STREAM session to the specified Destination for a single connection, using the socket stolen from the handler.
      Overrides:
      connect in class SAMv3StreamSession
      Parameters:
      handler - The handler that communicates with the requesting client
      dest - Base64-encoded Destination to connect to
      props - Options to be used for connection
      Throws:
      I2PException - always
    • accept

      public void accept(SAMv3Handler handler, boolean verbose) throws SAMException
      Description copied from class: SAMv3StreamSession
      Accept a single incoming STREAM on the socket stolen from the handler. As of version 3.2 (0.9.24), multiple simultaneous accepts are allowed. Accepts and forwarding may not be done at the same time.
      Overrides:
      accept in class SAMv3StreamSession
      Parameters:
      handler - The handler that communicates with the requesting client
      verbose - If true, SAM will send the Base64-encoded peer Destination of an incoming socket as the first line of data sent to its client on the handler socket
      Throws:
      SAMException - always
    • startForwardingIncoming

      public void startForwardingIncoming(Properties props, boolean sendPorts) throws SAMException
      Description copied from class: SAMv3StreamSession
      Forward sockets from I2P to the host/port provided. Accepts and forwarding may not be done at the same time.
      Overrides:
      startForwardingIncoming in class SAMv3StreamSession
      Throws:
      SAMException - always
    • stopForwardingIncoming

      public void stopForwardingIncoming()
      does nothing
      Overrides:
      stopForwardingIncoming in class SAMv3StreamSession
    • getListenProtocol

      public int getListenProtocol()
      Specified by:
      getListenProtocol in interface SAMMessageSess
      Overrides:
      getListenProtocol in class SAMStreamSession
    • getListenPort

      public int getListenPort()
      Specified by:
      getListenPort in interface SAMMessageSess
      Overrides:
      getListenPort in class SAMStreamSession
    • close

      public void close()
      Close the primary session and all subsessions. Overridden to stop the acceptor and the subsessions.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface SAMMessageSess
      Overrides:
      close in class SAMv3StreamSession
    • disconnected

      public void disconnected(I2PSession session)
      Description copied from interface: I2PSessionMuxedListener
      Notify the client that the session has been terminated. All registered listeners will be called.
      Specified by:
      disconnected in interface I2PSessionListener
      Specified by:
      disconnected in interface I2PSessionMuxedListener
    • errorOccurred

      public void errorOccurred(I2PSession session, String message, Throwable error)
      Description copied from interface: I2PSessionMuxedListener
      Notify the client that some error occurred. All registered listeners will be called.
      Specified by:
      errorOccurred in interface I2PSessionListener
      Specified by:
      errorOccurred in interface I2PSessionMuxedListener
      Parameters:
      error - can be null? or not?
    • messageAvailable

      public void messageAvailable(I2PSession session, int msgId, long size)
      Description copied from interface: I2PSessionMuxedListener
      Will be called only if you register via setSessionListener() or addSessionListener(). And if you are doing that, just use I2PSessionListener. If you register via addSessionListener(), this will be called only for the proto(s) and toport(s) you register for. After this is called, the client should call receiveMessage(msgId). There is currently no method for the client to reject the message. If the client does not call receiveMessage() within a timeout period (currently 30 seconds), the session will delete the message and log an error.
      Specified by:
      messageAvailable in interface I2PSessionListener
      Specified by:
      messageAvailable in interface I2PSessionMuxedListener
      Parameters:
      session - session to notify
      msgId - message number available
      size - size of the message - why it's a long and not an int is a mystery
    • messageAvailable

      public void messageAvailable(I2PSession session, int msgId, long size, int proto, int fromPort, int toPort)
      Description copied from interface: I2PSessionMuxedListener
      Instruct the client that the given session has received a message Will be called only if you register via addMuxedSessionListener(). Will be called only for the proto(s) and toport(s) you register for. After this is called, the client should call receiveMessage(msgId). There is currently no method for the client to reject the message. If the client does not call receiveMessage() within a timeout period (currently 30 seconds), the session will delete the message and log an error. Only one listener is called for a given message, even if more than one have registered. See I2PSessionDemultiplexer for details.
      Specified by:
      messageAvailable in interface I2PSessionMuxedListener
      Parameters:
      session - session to notify
      msgId - message number available
      size - size of the message - why it's a long and not an int is a mystery
      proto - 1-254 or 0 for unspecified
      fromPort - 1-65535 or 0 for unspecified
      toPort - 1-65535 or 0 for unspecified
      Since:
      0.9.24
    • reportAbuse

      public void reportAbuse(I2PSession session, int severity)
      Description copied from interface: I2PSessionMuxedListener
      Instruct the client that the session specified seems to be under attack and that the client may wish to move its destination to another router. All registered listeners will be called. Unused. Not fully implemented.
      Specified by:
      reportAbuse in interface I2PSessionListener
      Specified by:
      reportAbuse in interface I2PSessionMuxedListener
      Parameters:
      session - session to report abuse to
      severity - how bad the abuse is