java.lang.Object
net.i2p.i2ptunnel.socks.SocketWrapper
All Implemented Interfaces:
Closeable, AutoCloseable, I2PSocket

class SocketWrapperextends Object implements I2PSocket
I2PSocket implementation wrapping a standard TCP Socket obtained from an outproxy, which is itself a wrapper around the Orchid stream.

SOCKS and HTTP tunnels use this so the tunnel framework can treat an outproxy connection as an I2P connection and handle it uniformly. All I2PSocket operations are delegated to the underlying Socket, and the destination is a fixed dummy: there is no I2P destination to report.

  • Field Details

    • socket

      private final Socket socket
      The java.net socket whose reads and writes are wrapped.
    • DUMMY_DEST

      private static final Destination DUMMY_DEST
      Placeholder destination for a connection with no real one
  • Constructor Details

    • SocketWrapper

      public SocketWrapper(Socket sock)
      Wraps a TCP socket obtained from an outproxy so that the tunnel framework can treat it as an I2P connection.
      Parameters:
      sock - the TCP socket to wrap, obtained from the outproxy
  • Method Details

    • getThisDestination

      public Destination getThisDestination()
      Local destination of the socket.
      Specified by:
      getThisDestination in interface I2PSocket
      Returns:
      the Destination of this side of the socket.
    • getPeerDestination

      public Destination getPeerDestination()
      Peer destination of the socket.
      Specified by:
      getPeerDestination in interface I2PSocket
      Returns:
      the destination of the peer.
    • getInputStream

      public InputStream getInputStream() throws IOException
      Gets the input stream from the underlying socket.
      Specified by:
      getInputStream in interface I2PSocket
      Returns:
      the socket's input stream
      Throws:
      IOException - if the socket is closed
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Gets the output stream from the underlying socket.
      Specified by:
      getOutputStream in interface I2PSocket
      Returns:
      the socket's output stream
      Throws:
      IOException - if the socket is closed
    • getOptions

      public I2PSocketOptions getOptions()
      Returns no socket options, because the outproxy has already configured the wrapped TCP socket.
      Specified by:
      getOptions in interface I2PSocket
      Returns:
      null always
    • setOptions

      public void setOptions(I2PSocketOptions options)
      Discards the options without applying them, because the outproxy has already configured the wrapped TCP socket.
      Specified by:
      setOptions in interface I2PSocket
      Parameters:
      options - I2PSocketOptions to set
    • getReadTimeout

      public long getReadTimeout()
      Socket read timeout in milliseconds.
      Specified by:
      getReadTimeout in interface I2PSocket
      Returns:
      the read timeout
    • setReadTimeout

      public void setReadTimeout(long ms)
      Ignores the requested timeout, because the read timeout belongs to the wrapped outproxy socket.
      Specified by:
      setReadTimeout in interface I2PSocket
      Parameters:
      ms - the requested timeout in milliseconds, discarded
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • reset

      public void reset() throws IOException
      Closes the wrapper by closing the wrapped outproxy socket.
      Specified by:
      reset in interface I2PSocket
      Throws:
      IOException - on reset failure
    • isClosed

      public boolean isClosed()
      Whether the socket is closed.
      Specified by:
      isClosed in interface I2PSocket
      Returns:
      true if the wrapped outproxy socket is closed
    • getPort

      public int getPort()
      Gets the remote port of the wrapped outproxy socket, which the wrapper always reports as unspecified.
      Specified by:
      getPort in interface I2PSocket
      Returns:
      Default I2PSession.PORT_UNSPECIFIED (0) or PORT_ANY (0)
    • getLocalPort

      public int getLocalPort()
      Gets the local port of the wrapped outproxy socket, which the wrapper always reports as unspecified.
      Specified by:
      getLocalPort in interface I2PSocket
      Returns:
      0 always