java.lang.Object
net.i2p.i2ptunnel.socks.SocketWrapper
- All Implemented Interfaces:
Closeable, AutoCloseable, 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 Summary
FieldsModifier and TypeFieldDescriptionprivate static final DestinationPlaceholder destination for a connection with no real oneprivate final SocketThe java.net socket whose reads and writes are wrapped.Constructor Summary
ConstructorsConstructorDescriptionSocketWrapper(Socket sock) Wraps a TCP socket obtained from an outproxy so that the tunnel framework can treat it as an I2P connection.Method Summary
All MethodsModifier and TypeMethodDescriptionvoidclose()Gets the input stream from the underlying socket.intGets the local port of the wrapped outproxy socket, which the wrapper always reports as unspecified.Returns no socket options, because the outproxy has already configured the wrapped TCP socket.Gets the output stream from the underlying socket.Peer destination of the socket.intgetPort()Gets the remote port of the wrapped outproxy socket, which the wrapper always reports as unspecified.longSocket read timeout in milliseconds.Local destination of the socket.booleanisClosed()Whether the socket is closed.voidreset()Closes the wrapper by closing the wrapped outproxy socket.voidsetOptions(I2PSocketOptions options) Discards the options without applying them, because the outproxy has already configured the wrapped TCP socket.voidsetReadTimeout(long ms) Ignores the requested timeout, because the read timeout belongs to the wrapped outproxy socket.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface I2PSocket
getLifetimeBytesReceived, getLifetimeBytesSentModifier and TypeMethodDescriptiondefault longHow many bytes have been received over the lifetime of this socket.default longHow many bytes have been sent over the lifetime of this socket.
Field Details
socket
The java.net socket whose reads and writes are wrapped.DUMMY_DEST
Placeholder destination for a connection with no real one
Constructor Details
SocketWrapper
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
Local destination of the socket.- Specified by:
getThisDestinationin interfaceI2PSocket- Returns:
- the Destination of this side of the socket.
getPeerDestination
Peer destination of the socket.- Specified by:
getPeerDestinationin interfaceI2PSocket- Returns:
- the destination of the peer.
getInputStream
Gets the input stream from the underlying socket.- Specified by:
getInputStreamin interfaceI2PSocket- Returns:
- the socket's input stream
- Throws:
IOException- if the socket is closed
getOutputStream
Gets the output stream from the underlying socket.- Specified by:
getOutputStreamin interfaceI2PSocket- Returns:
- the socket's output stream
- Throws:
IOException- if the socket is closed
getOptions
Returns no socket options, because the outproxy has already configured the wrapped TCP socket.- Specified by:
getOptionsin interfaceI2PSocket- Returns:
- null always
setOptions
Discards the options without applying them, because the outproxy has already configured the wrapped TCP socket.- Specified by:
setOptionsin interfaceI2PSocket- Parameters:
options- I2PSocketOptions to set
getReadTimeout
public long getReadTimeout()Socket read timeout in milliseconds.- Specified by:
getReadTimeoutin interfaceI2PSocket- 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:
setReadTimeoutin interfaceI2PSocket- Parameters:
ms- the requested timeout in milliseconds, discarded
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
reset
Closes the wrapper by closing the wrapped outproxy socket.- Specified by:
resetin interfaceI2PSocket- Throws:
IOException- on reset failure
isClosed
getPort
getLocalPort
public int getLocalPort()Gets the local port of the wrapped outproxy socket, which the wrapper always reports as unspecified.- Specified by:
getLocalPortin interfaceI2PSocket- Returns:
- 0 always