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 ...@@ -97,6 +97,7 @@ public class FileTransferProxy extends BasicModule
private ProxyConnectionManager connectionManager; private ProxyConnectionManager connectionManager;
private FileTransferManager transferManager; private FileTransferManager transferManager;
private boolean isFileTransferEnabled; private boolean isFileTransferEnabled;
private InetAddress bindInterface;
public FileTransferProxy() { public FileTransferProxy() {
...@@ -185,13 +186,28 @@ public class FileTransferProxy extends BasicModule ...@@ -185,13 +186,28 @@ public class FileTransferProxy extends BasicModule
router = server.getPacketRouter(); router = server.getPacketRouter();
// Load the external IP and port information // 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 { try {
proxyIP = JiveGlobals.getProperty("xmpp.proxy.externalip", proxyIP = JiveGlobals.getProperty("xmpp.proxy.externalip",
InetAddress.getLocalHost().getHostAddress()); (bindInterface != null ? bindInterface.getHostAddress()
: InetAddress.getLocalHost().getHostAddress()));
} }
catch (UnknownHostException e) { catch (UnknownHostException e) {
Log.error("Couldn't discover local host", e); Log.error("Couldn't discover local host", e);
} }
transferManager = getFileTransferManager(); transferManager = getFileTransferManager();
connectionManager = new ProxyConnectionManager(transferManager); connectionManager = new ProxyConnectionManager(transferManager);
isFileTransferEnabled = isFileTransferEnabled(); isFileTransferEnabled = isFileTransferEnabled();
...@@ -213,7 +229,7 @@ public class FileTransferProxy extends BasicModule ...@@ -213,7 +229,7 @@ public class FileTransferProxy extends BasicModule
} }
private void startProxy() { private void startProxy() {
connectionManager.processConnections(getProxyPort()); connectionManager.processConnections(bindInterface, getProxyPort());
routingTable.addRoute(getAddress(), this); routingTable.addRoute(getAddress(), this);
XMPPServer server = XMPPServer.getInstance(); XMPPServer server = XMPPServer.getInstance();
......
...@@ -21,6 +21,7 @@ import org.xmpp.packet.JID; ...@@ -21,6 +21,7 @@ import org.xmpp.packet.JID;
import java.io.*; import java.io.*;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.net.Socket; import java.net.Socket;
import java.net.InetAddress;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
...@@ -56,10 +57,9 @@ public class ProxyConnectionManager { ...@@ -56,10 +57,9 @@ public class ProxyConnectionManager {
private ProxyTracker proxyTracker; private ProxyTracker proxyTracker;
@SuppressWarnings({"unchecked"})
public ProxyConnectionManager(FileTransferManager manager) { public ProxyConnectionManager(FileTransferManager manager) {
String cacheName = "File Transfer"; 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", className = JiveGlobals.getProperty("provider.transfer.proxy",
"org.jivesoftware.wildfire.filetransfer.spi.DefaultProxyTransfer"); "org.jivesoftware.wildfire.filetransfer.spi.DefaultProxyTransfer");
...@@ -72,16 +72,16 @@ public class ProxyConnectionManager { ...@@ -72,16 +72,16 @@ public class ProxyConnectionManager {
* Processes the clients connecting to the proxy matching the initiator and target together. * 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. * 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) { if (port == proxyPort) {
return; return;
} }
reset(port); reset();
socketProcess = executor.submit(new Runnable() { socketProcess = executor.submit(new Runnable() {
public void run() { public void run() {
try { try {
serverSocket = new ServerSocket(port); serverSocket = new ServerSocket(port, -1, bindInterface);
} }
catch (IOException e) { catch (IOException e) {
Log.error("Error creating server socket", e); Log.error("Error creating server socket", e);
...@@ -319,19 +319,14 @@ public class ProxyConnectionManager { ...@@ -319,19 +319,14 @@ public class ProxyConnectionManager {
} }
public void disable() { public void disable() {
reset(-1); reset();
} }
private void reset(int port) { private void reset() {
if (socketProcess != null) { if (socketProcess != null) {
if (port != proxyPort) {
socketProcess.cancel(true); socketProcess.cancel(true);
socketProcess = null; socketProcess = null;
} }
else {
return;
}
}
if (serverSocket != null) { if (serverSocket != null) {
try { try {
serverSocket.close(); serverSocket.close();
......
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