net.i2p.sam

## Class SAMv3Handler

- java.lang.Object
- - net.i2p.sam.SAMHandler
  - - net.i2p.sam.SAMv1Handler
    - - net.i2p.sam.SAMv3Handler

- All Implemented Interfaces:
    Runnable, Handler, SAMDatagramReceiver, SAMRawReceiver, SAMStreamReceiver

      class SAMv3Handler
      extends SAMv1Handler

  Class able to handle a SAM version 3 client connection.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static SessionsDB` | `sSessionsHash`

    - ### Fields inherited from class net.i2p.sam.SAMv1Handler

      `_id, datagramSession, rawSession, SESSION_ERROR, streamSession`

    - ### Fields inherited from class net.i2p.sam.SAMHandler

      `_log, bridge, i2cpProps, socket, stopHandler, stopLock, thread, verMajor, verMinor`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SAMv3Handler(SocketChannel s, int verMajor, int verMinor, Properties i2cpProps, SAMBridge parent)` Create a new SAM version 3 handler.
    `SAMv3Handler(SocketChannel s, int verMajor, int verMinor, SAMBridge parent)` Create a new SAM version 3 handler.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `execSessionMessage(String opcode, Properties props)`
    `protected boolean` | `execStreamConnect(Properties props)`
    `protected boolean` | `execStreamMessage(String opcode, Properties props)`
    `(package private) SAMBridge` | `getBridge()` For SAMv3StreamSession
    `String` | `getClientIP()`
    `(package private) Session` | `getSession()` For SAMv3DatagramServer
    `void` | `handle()` Actually handle the SAM protocol.
    `void` | `notifyStreamIncomingConnection(Destination d, int fromPort, int toPort)`
    `static void` | `notifyStreamIncomingConnection(SocketChannel client, Destination d)`
    `static void` | `notifyStreamIncomingConnection(SocketChannel client, Destination d, int fromPort, int toPort)`
    `void` | `notifyStreamResult(boolean verbose, String result, String message)`
    `(package private) void` | `setSession(SAMv3DatagramSession sess)` For subsessions created by MasterSession
    `(package private) void` | `setSession(SAMv3RawSession sess)` For subsessions created by MasterSession
    `(package private) void` | `setSession(SAMv3StreamSession sess)` For subsessions created by MasterSession
    `void` | `stealSocket()` For SAMv3StreamSession connect and accept
    `void` | `stopHandling()` Stop the SAM handler, close the socket, unregister with the bridge.
    `boolean` | `verifVersion()`

    - ### Methods inherited from class net.i2p.sam.SAMv1Handler

      `createMessageString, execDatagramMessage, execDestMessage, execNamingMessage, execRawMessage, execStreamClose, execStreamSend, getDatagramSession, getRawSession, getStreamSession, notifyStreamDisconnection, notifyStreamIncomingConnection, notifyStreamOutgoingConnection, notifyStreamSendBufferFree, receiveDatagramBytes, receiveRawBytes, receiveStreamBytes, stopDatagramReceiving, stopRawReceiving, stopStreamReceiving, streamSendAnswer, writeString`

    - ### Methods inherited from class net.i2p.sam.SAMHandler

      `closeClientSocket, getClientSocket, getWriteLock, run, shouldStop, startHandling, toString, writeBytes, writeString, writeString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### sSessionsHash

          public static final SessionsDB sSessionsHash

  - ### Constructor Detail

    - #### SAMv3Handler

          public SAMv3Handler(SocketChannel s,
                              int verMajor,
                              int verMinor,
                              Properties i2cpProps,
                              SAMBridge parent)
                       throws SAMException,
                              IOException

      Create a new SAM version 3 handler. This constructor expects that the SAM HELLO message has been still answered (and stripped) from the socket input stream.
      Parameters:
        `s` - Socket attached to a SAM client
        `verMajor` - SAM major version to manage (should be 3)
        `verMinor` - SAM minor version to manage
        `i2cpProps` - properties to configure the I2CP connection (host, port, etc)
      Throws:
        `SAMException`
        `IOException`

    - #### SAMv3Handler

          public SAMv3Handler(SocketChannel s,
                              int verMajor,
                              int verMinor,
                              SAMBridge parent)
                       throws SAMException,
                              IOException

      Create a new SAM version 3 handler. This constructor expects that the SAM HELLO message has been still answered (and stripped) from the socket input stream.
      Parameters:
        `s` - Socket attached to a SAM client
        `verMajor` - SAM major version to manage (should be 3)
        `verMinor` - SAM minor version to manage
      Throws:
        `SAMException`
        `IOException`

  - ### Method Detail

    - #### execSessionMessage

          protected boolean execSessionMessage(String opcode,
                                               Properties props)

      Overrides:
        `execSessionMessage` in class `SAMv1Handler`

    - #### execStreamConnect

          protected boolean execStreamConnect(Properties props)

      Overrides:
        `execStreamConnect` in class `SAMv1Handler`

    - #### execStreamMessage

          protected boolean execStreamMessage(String opcode,
                                              Properties props)

      Overrides:
        `execStreamMessage` in class `SAMv1Handler`

    - #### getBridge

          SAMBridge getBridge()

      For SAMv3StreamSession

    - #### getClientIP

          public String getClientIP()

    - #### getSession

          Session getSession()

      For SAMv3DatagramServer
      Returns:
        may be null

    - #### handle

          public void handle()

      Description copied from class: `SAMHandler`
      Actually handle the SAM protocol.
      Overrides:
        `handle` in class `SAMv1Handler`

    - #### notifyStreamIncomingConnection

          public void notifyStreamIncomingConnection(Destination d,
                                                     int fromPort,
                                                     int toPort)
                                              throws IOException

      Throws:
        `IOException`

    - #### notifyStreamIncomingConnection

          public static void notifyStreamIncomingConnection(SocketChannel client,
                                                            Destination d)
                                                     throws IOException

      Throws:
        `IOException`

    - #### notifyStreamIncomingConnection

          public static void notifyStreamIncomingConnection(SocketChannel client,
                                                            Destination d,
                                                            int fromPort,
                                                            int toPort)
                                                     throws IOException

      Throws:
        `IOException`

    - #### notifyStreamResult

          public void notifyStreamResult(boolean verbose,
                                         String result,
                                         String message)
                                  throws IOException

      Parameters:
        `verbose` - if false, does nothing
        `result` - non-null
        `message` - may be null
      Throws:
        `IOException`

    - #### setSession

          void setSession(SAMv3DatagramSession sess)

      For subsessions created by MasterSession

    - #### setSession

          void setSession(SAMv3RawSession sess)

      For subsessions created by MasterSession

    - #### setSession

          void setSession(SAMv3StreamSession sess)

      For subsessions created by MasterSession

    - #### stealSocket

          public void stealSocket()

      For SAMv3StreamSession connect and accept

    - #### stopHandling

          public void stopHandling()

      Stop the SAM handler, close the socket, unregister with the bridge. Overridden to not close the client socket if stolen.
      Specified by:
        `stopHandling` in interface `Handler`
      Overrides:
        `stopHandling` in class `SAMHandler`

    - #### verifVersion

          public boolean verifVersion()

      Overrides:
        `verifVersion` in class `SAMv1Handler`