java.lang.Object
net.i2p.router.client.ClientListenerRunner
- All Implemented Interfaces:
Runnable
- Direct Known Subclasses:
SSLClientListenerRunner
Listen for connections on the specified port, and toss them onto the client manager's set of connections once they are established.
This is not used for internal (in-JVM) connections - see ClientManager and QueuedClientConnectionRunner.
Note that this is extended by SSLClientListenerRunner for SSL, and by DomainClientListenerRunner in Android for domain sockets.
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final booleanWhether to bind on all interfaces.protected final RouterContextRouter context.protected booleanWhether the socket is currently listening.protected final LogLogger for this class.protected final ClientManagerClient manager.protected final intPort to listen on.protected booleanWhether the runner is running.protected ServerSocketServer socket for accepting connections.static final StringProperty to control binding to all interfaces.protected static final intGive the i2cp client 5 seconds to show that they're really i2cp clients.Constructor Summary
ConstructorsConstructorDescriptionClientListenerRunner(RouterContext context, ClientManager manager, int port) Create a new client listener runner for the given port.Method Summary
Modifier and TypeMethodDescriptionprotected ServerSocketA ServerSocket for this listener.private booleanisAlive()Just so unit tests don't NPE, where the router could be null.booleanCheck if the listener is currently running and listening.voidrun()protected voidrunConnection(Socket socket) Handle the connection by passing it off to aClientConnectionRunner.protected voidStart up the socket listener, listens for connections, and fires those connections off viarunConnection.voidStop listening for connections.protected booleanVerify the first byte.
Field Details
_log
Logger for this class._context
Router context._manager
Client manager._socket
Server socket for accepting connections._port
protected final int _portPort to listen on._bindAllInterfaces
protected final boolean _bindAllInterfacesWhether to bind on all interfaces._running
protected volatile boolean _runningWhether the runner is running._listening
protected volatile boolean _listeningWhether the socket is currently listening.BIND_ALL_INTERFACES
Property to control binding to all interfaces.- See Also:
CONNECT_TIMEOUT
protected static final int CONNECT_TIMEOUTGive the i2cp client 5 seconds to show that they're really i2cp clients.- See Also:
Constructor Details
ClientListenerRunner
Create a new client listener runner for the given port.- Parameters:
context- the router contextmanager- the client managerport- the port number
Method Details
isListening
public boolean isListening()Check if the listener is currently running and listening.- Returns:
- true if the listener is currently running and listening
getServerSocket
A ServerSocket for this listener. Split out so it can be overridden for SSL.- Returns:
- the socket this listener is bound to
- Throws:
IOException- if the socket cannot be created
run
runServer
protected void runServer()Start up the socket listener, listens for connections, and fires those connections off viarunConnection. This only returns if the socket cannot be opened or there is a catastrophic failure.isAlive
private boolean isAlive()Just so unit tests don't NPE, where the router could be null.- Returns:
- true if the router is running, or absent entirely so unit tests do not NPE
validate
Verify the first byte.- Parameters:
socket- the accepted connection to probe for the I2CP protocol byte- Returns:
- true if the first byte is the I2CP protocol byte
runConnection
Handle the connection by passing it off to aClientConnectionRunner.- Parameters:
socket- the accepted socket connection
stopListening
public void stopListening()Stop listening for connections.