Commit 46260fc4 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Added ability for file transfer proxy to bind to address provided in network.interface. JM-721

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4029 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6e7e77ee
......@@ -97,6 +97,7 @@ public class FileTransferProxy extends BasicModule
private ProxyConnectionManager connectionManager;
private FileTransferManager transferManager;
private boolean isFileTransferEnabled;
private InetAddress bindInterface;
public FileTransferProxy() {
......@@ -185,13 +186,28 @@ public class FileTransferProxy extends BasicModule
router = server.getPacketRouter();
// Load the external IP and port information
String interfaceName = JiveGlobals.getXMLProperty("network.interface");
bindInterface = null;
if (interfaceName != null) {
if (interfaceName.trim().length() > 0) {
try {
bindInterface = InetAddress.getByName(interfaceName);
}
catch (UnknownHostException e) {
Log.error("Error binding to network.interface", e);
}
}
}
try {
proxyIP = JiveGlobals.getProperty("xmpp.proxy.externalip",
InetAddress.getLocalHost().getHostAddress());
(bindInterface != null ? bindInterface.getHostAddress()
: InetAddress.getLocalHost().getHostAddress()));
}
catch (UnknownHostException e) {
Log.error("Couldn't discover local host", e);
}
transferManager = getFileTransferManager();
connectionManager = new ProxyConnectionManager(transferManager);
isFileTransferEnabled = isFileTransferEnabled();
......@@ -213,7 +229,7 @@ public class FileTransferProxy extends BasicModule
}
private void startProxy() {
connectionManager.processConnections(getProxyPort());
connectionManager.processConnections(bindInterface, getProxyPort());
routingTable.addRoute(getAddress(), this);
XMPPServer server = XMPPServer.getInstance();
......
......@@ -21,6 +21,7 @@ import org.xmpp.packet.JID;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.InetAddress;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
......@@ -56,10 +57,9 @@ public class ProxyConnectionManager {
private ProxyTracker proxyTracker;
@SuppressWarnings({"unchecked"})
public ProxyConnectionManager(FileTransferManager manager) {
String cacheName = "File Transfer";
connectionMap = CacheManager.initializeCache(cacheName, "fileproxytransfer", -1, 1000 * 60 * 10);
connectionMap = new Cache<String, ProxyTransfer>(cacheName, -1, 1000 * 60 * 10);
className = JiveGlobals.getProperty("provider.transfer.proxy",
"org.jivesoftware.wildfire.filetransfer.spi.DefaultProxyTransfer");
......@@ -72,16 +72,16 @@ public class ProxyConnectionManager {
* Processes the clients connecting to the proxy matching the initiator and target together.
* This is the main loop of the manager which will run until the process is canceled.
*/
synchronized void processConnections(final int port) {
synchronized void processConnections(final InetAddress bindInterface, final int port) {
if (port == proxyPort) {
return;
}
reset(port);
reset();
socketProcess = executor.submit(new Runnable() {
public void run() {
try {
serverSocket = new ServerSocket(port);
serverSocket = new ServerSocket(port, -1, bindInterface);
}
catch (IOException e) {
Log.error("Error creating server socket", e);
......@@ -319,18 +319,13 @@ public class ProxyConnectionManager {
}
public void disable() {
reset(-1);
reset();
}
private void reset(int port) {
private void reset() {
if (socketProcess != null) {
if (port != proxyPort) {
socketProcess.cancel(true);
socketProcess = null;
}
else {
return;
}
socketProcess.cancel(true);
socketProcess = null;
}
if (serverSocket != null) {
try {
......
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