java.lang.Object
net.i2p.i2ptunnel.socks.SOCKSServer
- Direct Known Subclasses:
SOCKS4aServer, SOCKS5Server
Abstract base class used by all SOCKS servers.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final I2PAppContextThe application context, used for the log manager and property lookups.protected final LogThe logger for this class.protected intSOCKS address type (e.g.protected final SocketThe connected socket back to the local SOCKS client.protected StringHostname requested by the SOCKS client.protected intPort requested by the SOCKS client.protected final PropertiesThe tunnel configuration, holding the IP to domain mappings.Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSOCKSServer(I2PAppContext ctx, Socket clientSock, Properties props) Create a handler for one accepted SOCKS connection.Method Summary
Modifier and TypeMethodDescriptionprotected abstract voidConfirm to the client that the connection has succeeded.abstract SocketGet a socket for sending/receiving 8-bit clean data to/from the client.abstract I2PSocketGet an I2PSocket for sending/receiving 8-bit clean data to/from the destination of the SOCKS connection.protected StringIP to domain name mapping support.protected OutproxyLooks up the registered outproxy plugin to route through, if any.voidhttpsConnect(I2PSocket destSock, OutputStream pout, String connHostName, int connPort, String configUser, String configPW) Act as a https client to connect to a CONNECT outproxy.protected I2PSocketoutproxyConnect(I2PSOCKSTunnel tun, String proxy) Act as a SOCKS 5 client to connect to an outproxy Caller must send success or error to local socks client.protected abstract voidPerform server initialization (expecially regarding protected variables).
Field Details
connHostName
Hostname requested by the SOCKS client.connPort
protected int connPortPort requested by the SOCKS client.addressType
protected int addressTypeSOCKS address type (e.g. DOMAINNAME, IPv4, IPv6)._context
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._log
The logger for this class.
Constructor Details
SOCKSServer
Create a handler for one accepted SOCKS connection.- Parameters:
ctx- the application context, used for the log manager and property lookupsclientSock- the connected socket back to the local SOCKS clientprops- the tunnel configuration, holding the IP to domain mappings
Method Details
getMappedDomainNameForIP
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
Perform server initialization (expecially regarding protected variables).- Throws:
SOCKSException- if the client's request cannot be read off the socket
getClientSocket
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
Confirm to the client that the connection has succeeded.- Throws:
SOCKSException- if the success reply cannot be written back to the client
getDestinationI2PSocket
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
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 overproxy- 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 completeI2PException- 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 proxypout- output stream to the proxyconnHostName- hostname or IP for the proxy to connect toconnPort- port for the proxy to connect toconfigUser- unused; HTTP proxy basic auth is not supportedconfigPW- unused; HTTP proxy basic auth is not supported- Throws:
IOException- if the proxy's reply cannot be read, or reports a non-200 status