net.i2p.i2ptunnel.socks

## Class SOCKS5Server

- java.lang.Object
- - net.i2p.i2ptunnel.socks.SOCKSServer
  - - net.i2p.i2ptunnel.socks.SOCKS5Server

-     class SOCKS5Server
      extends SOCKSServer

  SOCKS5 server implementation with comprehensive protocol support and authentication.

  This class handles SOCKS version 5 protocol including authentication (username/password and no-auth), multiple address types (IPv4, IPv6, domain), and extended commands including Tor RESOLVE for hostname resolution. It supports UDP ASSOCIATE commands and provides outproxy connectivity through both SOCKS and HTTP CONNECT methods.

  The server includes security features like localhost blocking, IP-to-domain mapping, and integrates with I2P naming service for destination resolution. It also supports torsocks compatibility through hostname caching mechanisms.

  Supports torsocks as of 0.9.57.

- - ### Field Summary

    - ### Fields inherited from class net.i2p.i2ptunnel.socks.SOCKSServer

      `_context, _log, addressType, clientSock, connHostName, connPort, props`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SOCKS5Server(I2PAppContext ctx, Socket clientSock, Properties props)` Create a SOCKS5 server that communicates with the client using the specified socket.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `confirmConnection()` Confirm to the client that the connection has succeeded
    `Socket` | `getClientSocket()` Get a socket that can be used to send/receive 8-bit clean data to/from the client.
    `I2PSocket` | `getDestinationI2PSocket(I2PSOCKSTunnel t)` Get an I2PSocket that can be used to send/receive 8-bit clean data to/from the destination of the SOCKS connection.
    `void` | `httpsConnect(I2PSocket destSock, OutputStream pout, String connHostName, int connPort, String configUser, String configPW)` Act as a https client to connect to a CONNECT outproxy.
    `protected void` | `setupServer()` Perform server initialization (expecially regarding protected variables).

    - ### Methods inherited from class net.i2p.i2ptunnel.socks.SOCKSServer

      `getMappedDomainNameForIP, getOutproxyPlugin`

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

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

- - ### Constructor Detail

    - #### SOCKS5Server

          public SOCKS5Server(I2PAppContext ctx,
                              Socket clientSock,
                              Properties props)

      Create a SOCKS5 server that communicates with the client using the specified socket. This method should not be invoked directly: new SOCKS5Server objects should be created by using SOCKSServerFactory.createSOCSKServer(). It is assumed that the SOCKS VER field has been stripped from the input stream of the client socket.
      Parameters:
        `clientSock` - client socket
        `props` - non-null

  - ### Method Detail

    - #### confirmConnection

          protected void confirmConnection()
                                    throws SOCKSException

      Description copied from class: `SOCKSServer`
      Confirm to the client that the connection has succeeded
      Specified by:
        `confirmConnection` in class `SOCKSServer`
      Throws:
        `SOCKSException`

    - #### getClientSocket

          public Socket getClientSocket()
                                 throws SOCKSException

      Description copied from class: `SOCKSServer`
      Get a socket that can be used to send/receive 8-bit clean data to/from the client.
      Specified by:
        `getClientSocket` in class `SOCKSServer`
      Returns:
        a Socket connected with the client
      Throws:
        `SOCKSException`

    - #### getDestinationI2PSocket

          public I2PSocket getDestinationI2PSocket(I2PSOCKSTunnel t)
                                            throws SOCKSException

      Get an I2PSocket that can be used to send/receive 8-bit clean data to/from the destination of the SOCKS connection.
      Specified by:
        `getDestinationI2PSocket` in class `SOCKSServer`
      Returns:
        an I2PSocket connected with the destination
      Throws:
        `SOCKSException`

    - #### httpsConnect

          public void httpsConnect(I2PSocket destSock,
                                   OutputStream pout,
                                   String connHostName,
                                   int connPort,
                                   String configUser,
                                   String configPW)
                            throws IOException

      Act as a https client to connect to a CONNECT outproxy. Caller must send success or error to local socks client. Caller must close destSock and pout.
      Parameters:
        `destSock` - socket to the proxy
        `pout` - output stream to the proxy
        `connHostName` - hostname or IP for the proxy to connect to
        `connPort` - port for the proxy to connect to
        `configUser` - username unsupported
        `configPW` - password unsupported
      Throws:
        `IOException`

    - #### setupServer

          protected void setupServer()
                              throws SOCKSException

      Description copied from class: `SOCKSServer`
      Perform server initialization (expecially regarding protected variables).
      Specified by:
        `setupServer` in class `SOCKSServer`
      Throws:
        `SOCKSException`