Commit 2de79b4e authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

ServerPort now uses acual bind IP address. JM-783

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@5093 b35dd754-fafc-0310-a699-88a17e54d16e
parent e7ef387b
......@@ -12,7 +12,8 @@
package org.jivesoftware.wildfire;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
import java.util.List;
/**
* Represents a port on which the server will listen for connections.
......@@ -24,7 +25,7 @@ import java.util.Iterator;
public class ServerPort {
private int port;
private ArrayList<String> names;
private List<String> names = new ArrayList<String>(1);
private String address;
private boolean secure;
private String algorithm;
......@@ -34,7 +35,6 @@ public class ServerPort {
boolean isSecure, String algorithm, Type type)
{
this.port = port;
this.names = new ArrayList<String>(1);
this.names.add(name);
this.address = address;
this.secure = isSecure;
......@@ -58,8 +58,8 @@ public class ServerPort {
*
* @return the server domain name(s) as Strings.
*/
public Iterator getDomainNames() {
return names.iterator();
public List<String> getDomainNames() {
return Collections.unmodifiableList(names);
}
/**
......@@ -126,6 +126,10 @@ public class ServerPort {
return type == Type.connectionManager;
}
public Type getType() {
return type;
}
public static enum Type {
client,
......
......@@ -73,9 +73,6 @@ public class SSLSocketAcceptThread extends Thread {
public SSLSocketAcceptThread(ConnectionManager connManager, ServerPort serverPort)
throws IOException {
super("Secure Socket Listener");
this.connManager = connManager;
this.serverPort = serverPort;
int port = serverPort.getPort();
// Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface");
InetAddress bindInterface = null;
......@@ -83,12 +80,19 @@ public class SSLSocketAcceptThread extends Thread {
try {
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());
}
}
catch (UnknownHostException e) {
Log.error(LocaleUtils.getLocalizedString("admin.error"), e);
}
}
this.connManager = connManager;
this.serverPort = serverPort;
int port = serverPort.getPort();
serverSocket = SSLConfig.createServerSocket(port, bindInterface);
}
......
......@@ -59,15 +59,19 @@ public class SocketAcceptThread extends Thread {
public SocketAcceptThread(ConnectionManager connManager, ServerPort serverPort)
throws IOException {
super("Socket Listener at port " + serverPort.getPort());
this.serverPort = serverPort;
// Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface");
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
boolean useBlockingMode = JiveGlobals.getBooleanProperty("xmpp.socket.blocking", true);
if (useBlockingMode) {
......
......@@ -88,11 +88,10 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
// Start servers socket unless it's been disabled.
if (isServerListenerEnabled()) {
int port = getServerListenerPort();
ServerPort serverPort = new ServerPort(port, serverName, localIPAddress,
false, null, ServerPort.Type.server);
try {
serverSocketThread = new SocketAcceptThread(this, serverPort);
ports.add(serverPort);
serverSocketThread = new SocketAcceptThread(this, new ServerPort(port, serverName,
localIPAddress, false, null, ServerPort.Type.server));
ports.add(serverSocketThread.getServerPort());
serverSocketThread.setDaemon(true);
serverSocketThread.setPriority(Thread.MAX_PRIORITY);
serverSocketThread.start();
......@@ -121,11 +120,11 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
// Start multiplexers socket unless it's been disabled.
if (isConnectionManagerListenerEnabled()) {
int port = getConnectionManagerListenerPort();
ServerPort serverPort = new ServerPort(port, serverName, localIPAddress,
false, null, ServerPort.Type.connectionManager);
try {
multiplexerSocketThread = new SocketAcceptThread(this, serverPort);
ports.add(serverPort);
multiplexerSocketThread = new SocketAcceptThread(this, new ServerPort(port,
serverName, localIPAddress, false, null,
ServerPort.Type.connectionManager));
ports.add(multiplexerSocketThread.getServerPort());
multiplexerSocketThread.setDaemon(true);
multiplexerSocketThread.setPriority(Thread.MAX_PRIORITY);
multiplexerSocketThread.start();
......@@ -154,11 +153,10 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
// Start components socket unless it's been disabled.
if (isComponentListenerEnabled()) {
int port = getComponentListenerPort();
ServerPort serverPort = new ServerPort(port, serverName, localIPAddress,
false, null, ServerPort.Type.component);
try {
componentSocketThread = new SocketAcceptThread(this, serverPort);
ports.add(serverPort);
componentSocketThread = new SocketAcceptThread(this, new ServerPort(port,
serverName, localIPAddress, false, null, ServerPort.Type.component));
ports.add(componentSocketThread.getServerPort());
componentSocketThread.setDaemon(true);
componentSocketThread.setPriority(Thread.MAX_PRIORITY);
componentSocketThread.start();
......@@ -187,11 +185,11 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
// Start clients plain socket unless it's been disabled.
if (isClientListenerEnabled()) {
int port = getClientListenerPort();
ServerPort serverPort = new ServerPort(port, serverName, localIPAddress,
false, null, ServerPort.Type.client);
try {
socketThread = new SocketAcceptThread(this, serverPort);
ports.add(serverPort);
socketThread = new SocketAcceptThread(this, new ServerPort(port, serverName,
localIPAddress, false, null, ServerPort.Type.client));
ports.add(socketThread.getServerPort());
socketThread.setDaemon(true);
socketThread.setPriority(Thread.MAX_PRIORITY);
socketThread.start();
......@@ -224,11 +222,10 @@ public class ConnectionManagerImpl extends BasicModule implements ConnectionMana
if ("".equals(algorithm) || algorithm == null) {
algorithm = "TLS";
}
ServerPort serverPort = new ServerPort(port, serverName, localIPAddress,
true, algorithm, ServerPort.Type.client);
try {
sslSocketThread = new SSLSocketAcceptThread(this, serverPort);
ports.add(serverPort);
sslSocketThread = new SSLSocketAcceptThread(this, new ServerPort(port, serverName,
localIPAddress, true, algorithm, ServerPort.Type.client));
ports.add(sslSocketThread.getServerPort());
sslSocketThread.setDaemon(true);
sslSocketThread.setPriority(Thread.MAX_PRIORITY);
sslSocketThread.start();
......
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