if ( _ssl ){
if ( _port == 0 ){
throw( new TRTrackerServerException( "port of 0 not currently supported for SSL"));
}
try {
SSLServerSocketFactory factory = SESecurityManager.getSSLServerSocketFactory();
if ( factory == null ){
throw( new TRTrackerServerException( "TRTrackerServer: failed to get SSL factory" ));
}else{
SSLServerSocket ssl_server_socket;
if ( _bind_ip != null ){
current_bind_ip = _bind_ip;
ssl_server_socket = (SSLServerSocket)factory.createServerSocket( getPort(), 128, _bind_ip );
}else if ( bind_ip == null ){
ssl_server_socket = (SSLServerSocket)factory.createServerSocket( getPort(), 128 );
}else{
current_bind_ip = bind_ip;
ssl_server_socket = (SSLServerSocket)factory.createServerSocket( getPort(), 128, bind_ip );
}
String cipherSuites[] = ssl_server_socket.getSupportedCipherSuites();
ssl_server_socket.setEnabledCipherSuites(cipherSuites);
ssl_server_socket.setNeedClientAuth(false);
ssl_server_socket.setReuseAddress(true);
server_socket = ssl_server_socket;
Thread accept_thread =
new AEThread("TRTrackerServer:accept.loop(ssl)")
{
public void
runSupport()
{
acceptLoop( server_socket );
}
};
accept_thread.setDaemon( true );
accept_thread.start();
Logger.log(new LogEvent(LOGID,
"TRTrackerServer: SSL listener established on port "
+ getPort()));
ok = true;
}
}catch( Throwable e){
Logger.logTextResource(new LogAlert(LogAlert.UNREPEATABLE,
LogAlert.AT_ERROR, "Tracker.alert.listenfail"), new String[] { ""
+ getPort() });
Logger.log(new LogEvent(LOGID,
"TRTrackerServer: SSL listener failed on port " + getPort(), e));
if ( e instanceof TRTrackerServerException ){
throw((TRTrackerServerException)e);
}else{
throw( new TRTrackerServerException( "TRTrackerServer: accept fails: " + e.toString()));
}
}
}else{
try{
ServerSocket ss;
int port = getPort();
if ( _bind_ip != null ){
current_bind_ip = _bind_ip;
ss = new ServerSocket( port, 1024, _bind_ip );
}else if ( bind_ip == null ){
ss = new ServerSocket( port, 1024 );
}else{
current_bind_ip = bind_ip;
ss = new ServerSocket( port, 1024, bind_ip );
}
if ( port == 0 ){
setPort( ss.getLocalPort());
}
ss.setReuseAddress(true);
server_socket = ss;
Thread accept_thread =
new AEThread("TRTrackerServer:accept.loop")
{
public void
runSupport()
{
acceptLoop( server_socket );
}
};
accept_thread.setDaemon( true );
accept_thread.start();
Logger.log(new LogEvent(LOGID, "TRTrackerServer: "
+ "listener established on port " + getPort()));
ok = true;
}catch( Throwable e){
Logger.logTextResource(new LogAlert(LogAlert.UNREPEATABLE,
LogAlert.AT_ERROR, "Tracker.alert.listenfail"), new String[] { ""
+ getPort() });
throw( new TRTrackerServerException( "TRTrackerServer: accept fails", e ));
}
}
}finally{
if ( !ok ){