Package com.biglybt.ui.telnet
Class SocketServer
- java.lang.Object
-
- com.biglybt.ui.telnet.SocketServer
-
- All Implemented Interfaces:
java.lang.Runnable
final class SocketServer extends java.lang.Object implements java.lang.Runnable
this class is used to receive incoming connections for the telnet UI and then authenticate and create a console session for the connection
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set
allowedHosts
private int
maxLoginAttempts
private java.net.ServerSocket
serverSocket
private UI
ui
private UserManager
userManager
-
Constructor Summary
Constructors Constructor Description SocketServer(UI ui, int port, java.util.Set allowedHosts, UserManager userManager, int maxLoginAttempts)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkHost(java.lang.String hostName)
compare the specified host (might be a hostname or an IP - dont really care) and see if it is a match against one of the allowed hostsprivate boolean
isAllowed(java.net.InetSocketAddress addr)
check that the specified host/ip is allowedprivate UserProfile
login(java.io.InputStream in, java.io.OutputStream out)
if usermanager is null (ie: multi user is not enabled), returns the default user profile otherwise, requests username and password and authenticates user before returning the user profile for this uservoid
run()
start up the server socket and when a new connection is received, check that the source address is in our permitted list and if so, start a new console input on that socket.
-
-
-
Field Detail
-
serverSocket
private final java.net.ServerSocket serverSocket
-
allowedHosts
private final java.util.Set allowedHosts
-
maxLoginAttempts
private final int maxLoginAttempts
-
userManager
private final UserManager userManager
-
ui
private final UI ui
-
-
Constructor Detail
-
SocketServer
public SocketServer(UI ui, int port, java.util.Set allowedHosts, UserManager userManager, int maxLoginAttempts) throws java.io.IOException
- Throws:
java.io.IOException
-
-
Method Detail
-
run
public void run()
start up the server socket and when a new connection is received, check that the source address is in our permitted list and if so, start a new console input on that socket.- Specified by:
run
in interfacejava.lang.Runnable
-
login
private UserProfile login(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException
if usermanager is null (ie: multi user is not enabled), returns the default user profile otherwise, requests username and password and authenticates user before returning the user profile for this user- Parameters:
in
- input stream to read fromout
- stream to write messages to- Returns:
- username if login was successful, null otherwise
- Throws:
java.io.IOException
-
isAllowed
private boolean isAllowed(java.net.InetSocketAddress addr)
check that the specified host/ip is allowed- Parameters:
addr
-- Returns:
-
checkHost
private boolean checkHost(java.lang.String hostName)
compare the specified host (might be a hostname or an IP - dont really care) and see if it is a match against one of the allowed hosts- Parameters:
hostName
-- Returns:
- true if this hostname matches one in our allowed hosts
-
-