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