Commit 3e1aa057 authored by Thiago Camargo's avatar Thiago Camargo Committed by thiago

Multiple STUN Servers Support

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@7647 b35dd754-fafc-0310-a699-88a17e54d16e
parent d0159f47
......@@ -2124,5 +2124,14 @@ stun.settings.secondaryaddress = Sekund\u00e1rn\u00ed adresa
stun.settings.primaryport = Prim\u00e1rn\u00ed port
stun.settings.secondaryport = Sekund\u00e1rn\u00ed
stun.settings.enabled = Povoleno
stun.settings.change = Zm\u011bna
stun.settings.change = Zm\u011bna\
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
index.certificate-warning=Found RSA certificate that is not valid for the server domain.
\ No newline at end of file
......@@ -2043,6 +2043,14 @@ stun.settings.primaryport = Primary Port Value
stun.settings.secondaryport = Secondary Port Value
stun.settings.enabled = Enabled
stun.settings.change = Change
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
admin.console.restarting=Restarting admin console...
global.click_test=Click to test...
global.day=day
......
......@@ -2340,7 +2340,15 @@ stun.settings.secondaryaddress = Secondary Address
stun.settings.primaryport = Primary Port Value
stun.settings.secondaryport = Secondary Port Value
stun.settings.enabled = Enabled
stun.settings.localenabled = Local Server Enabled
stun.settings.change = Change
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
# Import signed certificate page
......
......@@ -2123,4 +2123,12 @@ stun.settings.primaryport = Puerto Primario
stun.settings.secondaryport = Puerto Secundario
stun.settings.enabled = Habilitado
stun.settings.change = Cambiar
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
index.certificate-warning=Se ha encontrado un certificado RSA que no es v\u00e1lido para el dominio del servidor.
\ No newline at end of file
......@@ -1710,6 +1710,14 @@ stun.settings.primaryport = Primary Port Value
stun.settings.secondaryport = Secondary Port Value
stun.settings.enabled = Enabled
stun.settings.change = Change
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
httpbind.settings.enabled.legend=Service Enabled
httpbind.settings.info=HTTP binding allows clients using the HTTP protocol to connect to Wildfire.
httpbind.settings.label_disable=Disabled
......
......@@ -2050,6 +2050,14 @@ stun.settings.primaryport = Primary Port Value
stun.settings.secondaryport = Secondary Port Value
stun.settings.enabled = Enabled
stun.settings.change = Change
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
admin.console.restarting=Restarting admin console...
global.click_test=Click to test...
global.day=day
......
......@@ -2025,6 +2025,14 @@ stun.settings.primaryport = Primary Port Value
stun.settings.secondaryport = Secondary Port Value
stun.settings.enabled = Enabled
stun.settings.change = Change
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
global.click_test=Click to test...
global.day=day
global.days=days
......
......@@ -2123,4 +2123,12 @@ stun.settings.primaryport = Porta Prim\u00e1ria
stun.settings.secondaryport = Porta Secund\u00e1ria
stun.settings.enabled = Habilitado
stun.settings.change = Modificar
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
setup.admin.settings.username-error=Nenhum usu\u00e1rio informado, ou o usu\u00e1rio informado n\u00e3o foi encontrado.
\ No newline at end of file
......@@ -1903,4 +1903,12 @@ stun.settings.secondaryaddress = \u4e8c\u7ea7\u5730\u5740
stun.settings.primaryport = \u4e00\u7ea7\u7aef\u53e3\u503c
stun.settings.secondaryport = \u4e8c\u7ea7\u7aef\u53e3\u503c
stun.settings.enabled = \u542f\u7528
stun.settings.change = \u53d8\u66f4
stun.settings.change = \u53d8\u66f4\
stun.external.title = External Stun Servers
stun.external.comment = Server will also send the following address(es) to client.
stun.external.server = Server
stun.external.port = Port
stun.external.error = You must inform Server and Port.
stun.external.add = Add
stun.external.delete = Delete
......@@ -50,14 +50,14 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
private StunServer stunServer = null;
private String name = "stun";
private boolean enabled = false;
private boolean localEnabled = false;
private String primaryAddress;
private String secondaryAddress;
private int primaryPort = 3478;
private int secondaryPort = 3479;
private String externalServerAddress = null;
private int externalServerPort = 3478;
private List<StunServerAddress> externalServers = null;
public static final String NAMESPACE = "google:jingleinfo";
......@@ -72,11 +72,11 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
* Load config using JiveGlobals
*/
private void loadSTUNConfig() {
primaryAddress = JiveGlobals.getProperty("stun.address.primary");
secondaryAddress = JiveGlobals.getProperty("stun.address.secondary");
externalServerAddress = JiveGlobals.getProperty("stun.external.address");
externalServerAddress = JiveGlobals.getProperty("stun.external.port");
externalServers = getStunServerAddresses(JiveGlobals.getProperty("stun.external.addresses"));
if (primaryAddress == null || primaryAddress.equals(""))
primaryAddress = JiveGlobals.getProperty("xmpp.domain",
......@@ -99,6 +99,7 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
}
this.enabled = JiveGlobals.getBooleanProperty("stun.enabled", true);
this.localEnabled = JiveGlobals.getBooleanProperty("stun.local.enabled", true);
}
......@@ -118,13 +119,15 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
public void start() {
if (isEnabled()) {
startServer();
startService();
if (isLocalEnabled())
startLocalServer();
} else {
XMPPServer.getInstance().getIQDiscoItemsHandler().removeServerItemsProvider(this);
}
}
public void startServer() {
public void startLocalServer() {
try {
InetAddress primary = InetAddress.getByName(primaryAddress);
......@@ -136,34 +139,37 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
stunServer.start();
} else
setEnabled(false);
setLocalEnabled(false);
} catch (SocketException e) {
Log.error("Disabling STUN server", e);
setEnabled(false);
setLocalEnabled(false);
} catch (UnknownHostException e) {
Log.error("Disabling STUN server", e);
setEnabled(false);
setLocalEnabled(false);
}
}
if (stunServer != null) {
public void startService() {
routingTable.addRoute(getAddress(), this);
XMPPServer server = XMPPServer.getInstance();
server.getIQDiscoItemsHandler().addServerItemsProvider(this);
}
}
public void stop() {
super.stop();
this.enabled = false;
if (stunServer != null)
stunServer.stop();
stunServer = null;
XMPPServer.getInstance().getIQDiscoItemsHandler().removeComponentItem(getAddress().toString());
if (routingTable != null)
routingTable.removeRoute(getAddress());
}
public void stopLocal() {
if (stunServer != null)
stunServer.stop();
stunServer = null;
}
public String getName() {
return serviceName;
}
......@@ -210,10 +216,19 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
return;
} else if (NAMESPACE.equals(namespace)) {
if (isEnabled()) {
Element stun = childElementCopy.addElement("stun");
if (isLocalEnabled()) {
Element server = stun.addElement("server");
server.addAttribute("host", primaryAddress);
server.addAttribute("udp", String.valueOf(primaryPort));
}
for (StunServerAddress stunServerAddress : externalServers) {
Element server = stun.addElement("server");
server.addAttribute("host", stunServerAddress.getServer());
server.addAttribute("udp", stunServerAddress.getPort());
}
}
} else {
// Answer an error since the server can't handle the requested namespace
......@@ -245,6 +260,31 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
return new JID(null, getServiceDomain(), null);
}
public List<StunServerAddress> getExternalServers() {
return externalServers;
}
public void addExternalServer(String server, String port) {
externalServers.add(new StunServerAddress(server, port));
String property = "";
for (StunServerAddress stunServerAddress : externalServers) {
if (!property.equals("")) property += ";";
property += stunServerAddress.getServer() + ":" + stunServerAddress.getPort();
}
JiveGlobals.setProperty("stun.external.addresses", property);
}
public void removeExternalServer(int index) {
externalServers.remove(index);
String property = "";
for (StunServerAddress stunServerAddress : externalServers) {
if (!property.equals("")) property += ";";
property += stunServerAddress.getServer() + ":" + stunServerAddress.getPort();
}
JiveGlobals.setProperty("stun.external.addresses", property);
}
public Iterator<DiscoServerItem> getItems() {
List<DiscoServerItem> items = new ArrayList<DiscoServerItem>();
if (!isEnabled()) {
......@@ -313,20 +353,46 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
return enabled;
}
/**
* Get if the local STUN Server is enabled.
*
* @return enabled
*/
public boolean isLocalEnabled() {
return localEnabled;
}
/**
* Set the service enable status.
*
* @param enabled boolean to enable or disable
* @param localEnabled local Server enable or disable
*/
public void setEnabled(boolean enabled) {
public void setEnabled(boolean enabled, boolean localEnabled) {
this.enabled = enabled;
this.localEnabled = localEnabled;
if (isEnabled()) {
startServer();
startService();
if (isLocalEnabled())
startLocalServer();
} else {
stop();
}
}
/**
* Set the Local STUN Server enable status.
*
* @param enabled boolean to enable or disable
*/
public void setLocalEnabled(boolean enabled) {
this.localEnabled = enabled;
if (isLocalEnabled())
startLocalServer();
else
stopLocal();
}
/**
* Get the secondary Port used by the STUN server
*
......@@ -378,7 +444,62 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
}
}
} catch (Exception e) {
// Do Nothing
}
return list;
}
/**
* Provides easy abstract to store STUN Server Addresses and Ports
*/
public class StunServerAddress {
private String server;
private String port;
public StunServerAddress(String server, String port) {
this.server = server;
this.port = port;
}
/**
* Get the Host Address
*
* @return Host Address
*/
public String getServer() {
return server;
}
/**
* Get STUN port
*
* @return the Server Port
*/
public String getPort() {
return port;
}
}
/**
* Abstraction method used to convert a String into a STUN Server Address List
*
* @param addresses the String representation of Server Addresses with their respective Ports (server1:port1;server2:port2)
* @return STUN Server Addresses List
*/
public List<StunServerAddress> getStunServerAddresses(String addresses) {
List<StunServerAddress> list = new ArrayList<StunServerAddress>();
if (addresses == null || addresses.equals("")) return list;
String servers[] = addresses.split(";");
for (String server : servers) {
String address[] = server.split(":");
list.add(new StunServerAddress(address[0], address[1]));
}
return list;
}
}
This diff is collapsed.
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