Commit 1b22ea34 authored by Guus der Kinderen's avatar Guus der Kinderen

Restore S2S inbound port by creating ConnectionListiner for legacy/nonMINA socket handling.

parent f0e6e04d
...@@ -77,23 +77,6 @@ public interface ConnectionManager { ...@@ -77,23 +77,6 @@ public interface ConnectionManager {
*/ */
public Collection<ServerPort> getPorts(); public Collection<ServerPort> getPorts();
/**
* Creates a new socket reader for the new accepted socket to be managed
* by the connection manager.
*
* @param socket the new accepted socket by this manager.
* @param isSecure true if the connection is secure.
* @param serverPort holds information about the port on which the server is listening for
* connections.
* @param useBlockingMode true means that the server will use a thread per connection.
* @return the created socket reader.
* @throws java.io.IOException when there is an error creating the socket reader.
* @deprecated This is part of the legacy blocking IO implementation. It should no longer be used in favor of NIO.
*/
@Deprecated
public SocketReader createSocketReader(Socket socket, boolean isSecure, ServerPort serverPort,
boolean useBlockingMode) throws IOException;
/** /**
* Sets if the port listener for unsecured clients will be available or not. When disabled * Sets if the port listener for unsecured clients will be available or not. When disabled
* there won't be a port listener active. Therefore, new clients won't be able to connect to * there won't be a port listener active. Therefore, new clients won't be able to connect to
......
...@@ -42,10 +42,9 @@ class BlockingAcceptingMode extends SocketAcceptingMode { ...@@ -42,10 +42,9 @@ class BlockingAcceptingMode extends SocketAcceptingMode {
private static final Logger Log = LoggerFactory.getLogger(BlockingAcceptingMode.class); private static final Logger Log = LoggerFactory.getLogger(BlockingAcceptingMode.class);
protected BlockingAcceptingMode(ConnectionManager connManager, ServerPort serverPort, protected BlockingAcceptingMode(int tcpPort, InetAddress bindInterface) throws IOException {
InetAddress bindInterface) throws IOException { super();
super(connManager, serverPort); serverSocket = new ServerSocket(tcpPort, -1, bindInterface);
serverSocket = new ServerSocket(serverPort.getPort(), -1, bindInterface);
} }
/** /**
...@@ -59,8 +58,8 @@ class BlockingAcceptingMode extends SocketAcceptingMode { ...@@ -59,8 +58,8 @@ class BlockingAcceptingMode extends SocketAcceptingMode {
Socket sock = serverSocket.accept(); Socket sock = serverSocket.accept();
if (sock != null) { if (sock != null) {
Log.debug("Connect " + sock.toString()); Log.debug("Connect " + sock.toString());
SocketReader reader =
connManager.createSocketReader(sock, false, serverPort, true); SocketReader reader = createServerSocketReader( sock, false, true );
Thread thread = new Thread(reader, reader.getName()); Thread thread = new Thread(reader, reader.getName());
thread.setDaemon(true); thread.setDaemon(true);
thread.setPriority(Thread.NORM_PRIORITY); thread.setPriority(Thread.NORM_PRIORITY);
......
...@@ -43,28 +43,19 @@ public class SocketAcceptThread extends Thread { ...@@ -43,28 +43,19 @@ public class SocketAcceptThread extends Thread {
/** /**
* Holds information about the port on which the server will listen for connections. * Holds information about the port on which the server will listen for connections.
*/ */
private ServerPort serverPort; private final int tcpPort;
private InetAddress bindInterface;
private SocketAcceptingMode acceptingMode; private SocketAcceptingMode acceptingMode;
public SocketAcceptThread(ConnectionManager connManager, ServerPort serverPort) public SocketAcceptThread( int tcpPort, InetAddress bindInterface )
throws IOException { throws IOException {
super("Socket Listener at port " + serverPort.getPort()); super("Socket Listener at port " + tcpPort);
// Listen on a specific network interface if it has been set. this.tcpPort = tcpPort;
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); this.bindInterface = bindInterface;
InetAddress bindInterface = null;
if (interfaceName != null) {
if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName);
// Create the new server port based on the new bind address
serverPort = new ServerPort(serverPort.getPort(),
serverPort.getDomainNames().get(0), interfaceName, serverPort.isSecure(),
serverPort.getSecurityType(), serverPort.getType());
}
}
this.serverPort = serverPort;
// Set the blocking reading mode to use // Set the blocking reading mode to use
acceptingMode = new BlockingAcceptingMode(connManager, serverPort, bindInterface); acceptingMode = new BlockingAcceptingMode(tcpPort, bindInterface);
} }
/** /**
...@@ -73,7 +64,7 @@ public class SocketAcceptThread extends Thread { ...@@ -73,7 +64,7 @@ public class SocketAcceptThread extends Thread {
* @return the port the socket is bound to. * @return the port the socket is bound to.
*/ */
public int getPort() { public int getPort() {
return serverPort.getPort(); return tcpPort;
} }
/** /**
...@@ -82,7 +73,7 @@ public class SocketAcceptThread extends Thread { ...@@ -82,7 +73,7 @@ public class SocketAcceptThread extends Thread {
* @return information about the port on which the server is listening for connections. * @return information about the port on which the server is listening for connections.
*/ */
public ServerPort getServerPort() { public ServerPort getServerPort() {
return serverPort; return new ServerPort(tcpPort, null, bindInterface.getHostName(), false, null, ServerPort.Type.server);
} }
/** /**
......
...@@ -20,11 +20,11 @@ ...@@ -20,11 +20,11 @@
package org.jivesoftware.openfire.net; package org.jivesoftware.openfire.net;
import org.jivesoftware.openfire.ConnectionManager; import org.jivesoftware.openfire.*;
import org.jivesoftware.openfire.ServerPort;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket;
/** /**
* Abstract class for {@link BlockingAcceptingMode}. * Abstract class for {@link BlockingAcceptingMode}.
...@@ -40,21 +40,12 @@ abstract class SocketAcceptingMode { ...@@ -40,21 +40,12 @@ abstract class SocketAcceptingMode {
*/ */
protected boolean notTerminated = true; protected boolean notTerminated = true;
/**
* Holds information about the port on which the server will listen for connections.
*/
protected ServerPort serverPort;
/** /**
* socket that listens for connections. * socket that listens for connections.
*/ */
protected ServerSocket serverSocket; protected ServerSocket serverSocket;
protected ConnectionManager connManager; protected SocketAcceptingMode() {
protected SocketAcceptingMode(ConnectionManager connManager, ServerPort serverPort) {
this.connManager = connManager;
this.serverPort = serverPort;
} }
public abstract void run(); public abstract void run();
...@@ -72,4 +63,14 @@ abstract class SocketAcceptingMode { ...@@ -72,4 +63,14 @@ abstract class SocketAcceptingMode {
// we don't care, no matter what, the socket should be dead // we don't care, no matter what, the socket should be dead
} }
} }
public SocketReader createServerSocketReader(Socket sock, boolean isSecure, boolean useBlockingMode) throws IOException {
final XMPPServer server = XMPPServer.getInstance();
final String serverName = server.getServerInfo().getXMPPDomain();
final PacketRouter router = server.getPacketRouter();
final RoutingTable routingTable = server.getRoutingTable();
final PacketDeliverer deliverer = server.getPacketDeliverer();
final SocketConnection conn = new SocketConnection(deliverer, sock, isSecure);
return new ServerSocketReader(router, routingTable, serverName, sock, conn, useBlockingMode);
}
} }
...@@ -174,7 +174,6 @@ public class ConnectionListener ...@@ -174,7 +174,6 @@ public class ConnectionListener
// TODO Start all connection types here, by supplying more connection acceptors other than a MINA-based one. // TODO Start all connection types here, by supplying more connection acceptors other than a MINA-based one.
switch ( getType() ) switch ( getType() )
{ {
case SOCKET_S2S:
case BOSH_C2S: case BOSH_C2S:
case WEBADMIN: case WEBADMIN:
Log.debug( "Not starting a (MINA-based) connection acceptor, as connections of type " + getType() + " depend on another IO technology."); Log.debug( "Not starting a (MINA-based) connection acceptor, as connections of type " + getType() + " depend on another IO technology.");
...@@ -205,7 +204,15 @@ public class ConnectionListener ...@@ -205,7 +204,15 @@ public class ConnectionListener
} }
Log.debug( "Starting..." ); Log.debug( "Starting..." );
if ( getType() == ConnectionType.SOCKET_S2S )
{
connectionAcceptor = new LegacyConnectionAcceptor( generateConnectionConfiguration() );
}
else
{
connectionAcceptor = new MINAConnectionAcceptor( generateConnectionConfiguration() ); connectionAcceptor = new MINAConnectionAcceptor( generateConnectionConfiguration() );
}
connectionAcceptor.start(); connectionAcceptor.start();
Log.info( "Started." ); Log.info( "Started." );
} }
......
...@@ -895,19 +895,4 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana ...@@ -895,19 +895,4 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
} }
return result; return result;
} }
// Old, pre NIO / MINA code. Should not be used as NIO offers better performance
@Deprecated
public SocketReader createSocketReader(Socket sock, boolean isSecure, ServerPort serverPort, boolean useBlockingMode) throws IOException {
if (serverPort.isServerPort()) {
final XMPPServer server = XMPPServer.getInstance();
final String serverName = server.getServerInfo().getXMPPDomain();
final PacketRouter router = server.getPacketRouter();
final RoutingTable routingTable = server.getRoutingTable();
final PacketDeliverer deliverer = server.getPacketDeliverer();
final SocketConnection conn = new SocketConnection(deliverer, sock, isSecure);
return new ServerSocketReader(router, routingTable, serverName, sock, conn, useBlockingMode);
}
return null;
}
} }
package org.jivesoftware.openfire.spi;
import org.jivesoftware.openfire.net.SocketAcceptThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A connection acceptor that employs the legacy, pre-MINA/NIO socket implementation of Openfire.
*
* @author Guus der Kinderen, guus.der.kinderen@gmail.com
* @deprecated Used only for S2S, which should be be ported to NIO.
*/
@Deprecated
public class LegacyConnectionAcceptor extends ConnectionAcceptor
{
private final Logger Log = LoggerFactory.getLogger( LegacyConnectionAcceptor.class );
private SocketAcceptThread socketAcceptThread;
/**
* Constructs a new instance which will accept new connections based on the provided configuration.
* <p/>
* The provided configuration is expected to be immutable. ConnectionAcceptor instances are not expected to handle
* changes in configuration. When such changes are to be applied, an instance is expected to be replaced.
* <p/>
* Newly instantiated ConnectionAcceptors will not accept any connections before {@link #start()} is invoked.
*
* @param configuration The configuration for connections to be accepted (cannot be null).
*/
public LegacyConnectionAcceptor( ConnectionConfiguration configuration )
{
super( configuration );
}
/**
* Starts this acceptor by binding the socket acceptor. When the acceptor is already started, a warning will be
* logged and the method invocation is otherwise ignored.
*/
@Override
public synchronized void start()
{
if ( socketAcceptThread != null )
{
Log.warn( "Unable to start acceptor (it is already started!)" );
return;
}
if ( configuration.getMaxThreadPoolSize() > 1 ) {
Log.warn( "Configuration allows for up to " + configuration.getMaxThreadPoolSize() + " threads, although implementation is limited to exactly one." );
}
try {
socketAcceptThread = new SocketAcceptThread(configuration.getPort(), configuration.getBindAddress());
socketAcceptThread.setDaemon(true);
socketAcceptThread.setPriority(Thread.MAX_PRIORITY);
socketAcceptThread.start();
}
catch (Exception e) {
System.err.println( "Error starting " + configuration.getPort() + ": " + e.getMessage() );
Log.error( "Error starting: " + configuration.getPort(), e );
// Reset for future use.
if (socketAcceptThread != null ) {
try {
socketAcceptThread.shutdown();
} finally {
socketAcceptThread = null;
}
}
}
}
/**
* Stops this acceptor by unbinding the socket acceptor. Does nothing when the instance is not started.
*/
@Override
public synchronized void stop()
{
if ( socketAcceptThread != null ) {
try {
socketAcceptThread.shutdown();
} finally {
socketAcceptThread = null;
}
}
}
@Override
boolean isIdle()
{
return socketAcceptThread != null; // We're not tracking actual sessions. This is a best effort response.
}
}
...@@ -139,6 +139,14 @@ class MINAConnectionAcceptor extends ConnectionAcceptor ...@@ -139,6 +139,14 @@ class MINAConnectionAcceptor extends ConnectionAcceptor
{ {
System.err.println( "Error starting " + configuration.getPort() + ": " + e.getMessage() ); System.err.println( "Error starting " + configuration.getPort() + ": " + e.getMessage() );
Log.error( "Error starting: " + configuration.getPort(), e ); Log.error( "Error starting: " + configuration.getPort(), e );
// Reset for future use.
if (socketAcceptor != null) {
try {
socketAcceptor.unbind();
} finally {
socketAcceptor = null;
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment