java.lang.Object
net.i2p.i2ptunnel.socks.SOCKSServer
Direct Known Subclasses:
SOCKS4aServer, SOCKS5Server

abstract class SOCKSServerextends Object
Abstract base class used by all SOCKS servers.
  • Field Details

    • connHostName

      protected String connHostName
      Hostname requested by the SOCKS client.
    • connPort

      protected int connPort
      Port requested by the SOCKS client.
    • addressType

      protected int addressType
      SOCKS address type (e.g. DOMAINNAME, IPv4, IPv6).
    • _context

      protected final I2PAppContext _context
      The application context, used for the log manager and property lookups.
    • clientSock

      protected final Socket clientSock
      The connected socket back to the local SOCKS client.
    • props

      protected final Properties props
      The tunnel configuration, holding the IP to domain mappings.
    • _log

      protected final Log _log
      The logger for this class.
  • Constructor Details

    • SOCKSServer

      protected SOCKSServer(I2PAppContext ctx, Socket clientSock, Properties props)
      Create a handler for one accepted SOCKS connection.
      Parameters:
      ctx - the application context, used for the log manager and property lookups
      clientSock - the connected socket back to the local SOCKS client
      props - the tunnel configuration, holding the IP to domain mappings
  • Method Details

    • getMappedDomainNameForIP

      protected String getMappedDomainNameForIP(String ip)
      IP to domain name mapping support. This matches the given IP string against a user-set list of mappings. This enables applications which do not properly support the SOCKS5 DOMAINNAME feature to be used with I2P.
      Parameters:
      ip - The IP address to check.
      Returns:
      The domain name if a mapping is found, or null otherwise.
    • setupServer

      protected abstract void setupServer() throws SOCKSException
      Perform server initialization (expecially regarding protected variables).
      Throws:
      SOCKSException - if the client's request cannot be read off the socket
    • getClientSocket

      public abstract Socket getClientSocket() throws SOCKSException
      Get a socket for sending/receiving 8-bit clean data to/from the client.
      Returns:
      a Socket connected with the client
      Throws:
      SOCKSException - if the initial handshake fails before the socket can be returned
    • confirmConnection

      protected abstract void confirmConnection() throws SOCKSException
      Confirm to the client that the connection has succeeded.
      Throws:
      SOCKSException - if the success reply cannot be written back to the client
    • getDestinationI2PSocket

      public abstract I2PSocket getDestinationI2PSocket(I2PSOCKSTunnel t) throws SOCKSException
      Get an I2PSocket for sending/receiving 8-bit clean data to/from the destination of the SOCKS connection.
      Parameters:
      t - the streaming tunnel to build the destination socket over
      Returns:
      an I2PSocket connected with the destination
      Throws:
      SOCKSException - if the requested host name or port was never established
    • getOutproxyPlugin

      protected Outproxy getOutproxyPlugin()
      Looks up the registered outproxy plugin to route through, if any.
      Returns:
      null if disabled or not installed
    • outproxyConnect

      protected I2PSocket outproxyConnect(I2PSOCKSTunnel tun, String proxy) throws IOException, I2PException
      Act as a SOCKS 5 client to connect to an outproxy Caller must send success or error to local socks client.
      Parameters:
      tun - the streaming tunnel to build the outproxy socket over
      proxy - the outproxy to connect to, as "name" or "name:port"
      Returns:
      open socket or throws error
      Throws:
      IOException - if the outproxy name does not resolve or the handshake cannot complete
      I2PException - if the streaming library cannot create the socket to the outproxy
    • 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 - unused; HTTP proxy basic auth is not supported
      configPW - unused; HTTP proxy basic auth is not supported
      Throws:
      IOException - if the proxy's reply cannot be read, or reports a non-200 status