Commit 2a372ccc authored by Matt Tucker's avatar Matt Tucker Committed by matt

Stun refactoring in progress.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@7689 b35dd754-fafc-0310-a699-88a17e54d16e
parent 27e1c1ca
......@@ -197,6 +197,7 @@
<include name="**/*.css"/>
<include name="**/*.gif"/>
<include name="**/*.png"/>
<include name="**/favicon.ico"/>
<include name="**/*.js"/>
</patternset>
......@@ -1213,7 +1214,7 @@
<mkdir dir="${plugin.dev.dest.dir}/@{plugin}/jar"/>
<copy todir="${plugin.dev.dest.dir}/@{plugin}/jar" failonerror="false"
overwrite="${overwrite}">
<fileset dir="@{pluginsrc}/@{plugin}" includes="*.xml, *.html, *.gif, *.png"/>
<fileset dir="@{pluginsrc}/@{plugin}" includes="*.xml, *.html, *.gif, *.png, *.ico"/>
</copy>
<!-- Copy the database and i18n file to the target dir, if they exist. -->
......
......@@ -31,75 +31,6 @@
##
## REVISION HISTORY (by Openfire version):
##
## 2.6.0
## Added key: 'audit.policy.maxdays_number'
## Added ket: 'audit.policy.maxtotal_size'
## Added key: 'admin.console.devmode'
## Added key: 'global.unlimited'
## Added key: 'sidebar.system-cache'
## Added key: 'sidebar.system-cache.descr'
## Added key: 'ssl.settings.type'
## Added key: 'startup.starting.pubsub'
## Added section: 'pubsub.*'
## Added section: 'system.cache.*'
## Added section 'upgrade.database.*'
## Removed key: 'audit.policy.maxfile_number'
## Removed key: 'group.summary.list_group'
## Removed key: 'session.summary.info'
## Removed key: 'user.summary.info'
##
## 3.0.0
## Added key: 'index.update.alert'
## Added key: 'index.update.info'
## Added key: 'startup.multiplexer'
## Added key 'plugin.admin.download'
## Added key 'plugin.admin.update-desc'
## Added key: 'upgrade.database.missing_schema'
## Added key: 'tab.tab-plugins'
## Added key: 'tab.tab-plugins.descr'
## Added key: 'sidebar.sidebar-plugin-admin'
## Added key: 'sidebar.plugin-settings'
## Added key: 'sidebar.available-plugins'
## Added key: 'sidebar.available-plugins.descr'
## Added key: 'sidebar.connection-managers-settings'
## Added key: 'sidebar.connection-managers-settings.descr'
## Added key: 'sidebar.connection-managers-session-summary'
## Added key: 'sidebar.connection-managers-session-summary.descr'
## Added key: 'sidebar.manage-updates'
## Added key: 'sidebar.manage-updates.descr'
## Updated key: 'upgrade.database.old_schema'
## Updated key: 'upgrade.database.success'
## Updated key: 'upgrade.database.failure'
## Added section 'connection-manager.*'
## Added section: 'manage-updates.*'
## Added section: 'muc.stats.*'
## Added section: 'plugin.available.*'
## Added section: 'server_bytes.stats.*'
## Added key: 'filetransfer.error.disabled'
## Added key: 'stat.filetransferproxy.transfered.name'
## Added key: 'stat.filetransferproxy.transfered.desc'
## Added key: 'stat.filetransferproxy.transfered.units'
## Added key: 'admin.console'
## Added key: 'calendar.info'
## Added key: 'calendar.about'
## Added key: 'calendar.prev_year'
## Added key: 'calendar.prev_month'
## Added key: 'calendar.go_today'
## Added key: 'calendar.next_month'
## Added key: 'calendar.next_year'
## Added key: 'calendar.select_date'
## Added key: 'calendar.drag_to_move'
## Added key: 'calendar.part_today'
## Added key: 'calendar.day_first'
## Added key: 'calendar.weekend'
## Added key: 'calendar.close'
## Added key: 'calendar.today'
## Added key: 'calendar.time_part'
## Added key: 'calendar.time'
##
## 3.0.1
## Added section: 'manage-updates.proxy.*'
##
## 3.1.0
## Added section: 'server.db_stats.*'
## Added key: 'group.summary.search'
......@@ -219,7 +150,17 @@
## 3.2.1
## Added key: 'index.certificate-warning'
## Added section 'ssl.import.certificate.*'
##
## 3.3.0
## Added key: 'sidebar.sidebar-media-services'
## Added key: 'sidebar.media-proxy'
## Added key: 'sidebar.media-proxy.descr'
## Added key: 'sidebar.stun'
## Added key: 'sidebar.stun.descr'
## Removed key: 'stun.settings.comment'
## Removed key: 'stun.settings.change'
## Removed key: 'stun.external.add'
## Removed key: 'stun.external.delete'
# Openfire
......@@ -276,6 +217,11 @@ tab.server.descr=Click to manage server settings
sidebar.server-compression.descr=Click to view compression settings.
sidebar.transfer-proxy=File Transfer Settings
sidebar.transfer-proxy.descr=Click to view file tranfer settings
sidebar.sidebar-media-services=Media Services
sidebar.media-proxy=Media Proxy
sidebar.media-proxy.descr=Click to view media proxy settings.
sidebar.stun=STUN Settings
sidebar.stun.descr=Click to view STUN settings.
tab.tab-users=Users/Groups
tab.tab-users.descr=Click to manage users and groups
sidebar.sidebar-users=Users
......@@ -2329,12 +2275,15 @@ mediaproxy.summary.stopbutton = Stop Active Sessions
stun.settings.alert.notvalidip = The selected IP values are not valid. Please select different IPs.
stun.settings.alert.notvalidport = The selected port numbers are not valid. Please select different port numbers.
stun.settings.title = STUN Server Settings
stun.settings.desc = Use the form below to manage STUN Server settings. \
A STUN need at least two different IPs in the same machine to run and two different port numbers on each IP.
stun.settings.title = STUN Settings
stun.settings.desc = STUN is a protocol that lets clients discover their network settings, \
including firewall and NAT device configuration. Use of the protocol is required for clients \
to establish peer to peer media sessions. The server can be configured as a STUN service itself, or it \
can send third-party STUN server addresses to clients.<br/><br/> \
In order to act as a STUN server, two different public IP addresses on the \
same machine are required, as well as two different port numbers for each IP.
stun.settings.success = Settings updated successfully.
stun.settings.error = Server cannot start. Check your port numbers and Primary and Secondary addresses.
stun.settings.comment = The settings will just take effects after savings settings.
stun.settings.error = STUN server cannot start. Check your port numbers and Primary and Secondary addresses.
stun.settings.primaryaddress = Primary Address
stun.settings.secondaryaddress = Secondary Address
stun.settings.primaryport = Primary Port Value
......@@ -2342,13 +2291,12 @@ 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.title = External STUN Servers
stun.external.comment = The server will also send the following address(es) for third-party STUN \
services to clients. Clients will try each STUN service until able to find one that is working.
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
stun.external.error = Invalid server or port.
# Import signed certificate page
......
......@@ -35,13 +35,15 @@ import java.net.UnknownHostException;
import java.util.*;
/**
* STUN Server and Service Module
* Provides especial Address discovery for p2p sessions to be used for media transmission and receiving of UDP packets.
* Especialy used for behind NAT users to ensure connectivity between parties.
* STUN server and service module. It provides address discovery for p2p sessions to be
* used for media transmission and receiving of UDP packets. It's especially useful for
* clients behind NAT devices.
*
* @author Thiago Camargo
*/
public class STUNService extends BasicModule implements ServerItemsProvider, RoutableChannelHandler, DiscoInfoProvider, DiscoItemsProvider {
public class STUNService extends BasicModule implements ServerItemsProvider, RoutableChannelHandler,
DiscoInfoProvider, DiscoItemsProvider
{
private String serviceName;
private RoutingTable routingTable;
......@@ -52,16 +54,16 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
private boolean enabled = false;
private boolean localEnabled = false;
private String primaryAddress;
private String secondaryAddress;
private int primaryPort = 3478;
private int secondaryPort = 3479;
private String primaryAddress = null;
private String secondaryAddress = null;
private int primaryPort;
private int secondaryPort;
private SessionManager sessionManager = null;
private List<StunServerAddress> externalServers = null;
private String defaultExternalAddresses = "stun.xten.net:3478;jivesoftware.com:3478;igniterealtime.org:3478";
private String defaultExternalAddresses = "stun.xten.net:3478;jivesoftware.com:3478;igniterealtime.org:3478;stun.fwdnet.net:3478";
public static final String NAMESPACE = "google:jingleinfo";
......@@ -86,29 +88,20 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
externalServers = getStunServerAddresses(addresses);
if (primaryAddress == null || primaryAddress.equals(""))
primaryAddress = JiveGlobals.getProperty("xmpp.domain",
JiveGlobals.getXMLProperty("network.interface", "localhost"));
if (secondaryAddress == null || secondaryAddress.equals(""))
secondaryAddress = "127.0.0.1";
try {
primaryPort = Integer.valueOf(JiveGlobals.getProperty("stun.port.primary"));
}
catch (NumberFormatException e) {
// Do nothing let the default values to be used.
}
try {
secondaryPort = Integer.valueOf(JiveGlobals.getProperty("stun.port.secondary"));
}
catch (NumberFormatException e) {
// Do nothing let the default values to be used.
}
primaryPort = JiveGlobals.getIntProperty("stun.port.primary", 3478);
secondaryPort = JiveGlobals.getIntProperty("stun.port.secondary", 3479);
this.enabled = JiveGlobals.getBooleanProperty("stun.enabled", true);
this.localEnabled = JiveGlobals.getBooleanProperty("stun.local.enabled", true);
this.localEnabled = JiveGlobals.getBooleanProperty("stun.local.enabled", false);
// If the local server is supposed to be enabled, ensure that primary and secondary
// addresses are defined.
if (localEnabled) {
if (primaryAddress == null || secondaryAddress == null) {
Log.warn("STUN server cannot be enabled. Primary and secondary addresses must be defined.");
enabled = false;
}
}
}
public void destroy() {
......@@ -129,31 +122,33 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
public void start() {
if (isEnabled()) {
startService();
if (isLocalEnabled())
if (isLocalEnabled()) {
startLocalServer();
} else {
}
}
else {
XMPPServer.getInstance().getIQDiscoItemsHandler().removeServerItemsProvider(this);
}
}
public void startLocalServer() {
try {
InetAddress primary = InetAddress.getByName(primaryAddress);
InetAddress secondary = InetAddress.getByName(secondaryAddress);
if (primary != null && secondary != null) {
stunServer = new StunServer(primaryPort, primary, secondaryPort, secondary);
stunServer.start();
} else
}
else {
setLocalEnabled(false);
} catch (SocketException e) {
}
}
catch (SocketException e) {
Log.error("Disabling STUN server", e);
setLocalEnabled(false);
} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
Log.error("Disabling STUN server", e);
setLocalEnabled(false);
}
......@@ -169,13 +164,15 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
super.stop();
this.enabled = false;
XMPPServer.getInstance().getIQDiscoItemsHandler().removeComponentItem(getAddress().toString());
if (routingTable != null)
if (routingTable != null) {
routingTable.removeRoute(getAddress());
}
}
public void stopLocal() {
if (stunServer != null)
if (stunServer != null) {
stunServer.stop();
}
stunServer = null;
}
......@@ -218,13 +215,14 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
reply = XMPPServer.getInstance().getIQDiscoInfoHandler().handleIQ(iq);
router.route(reply);
return;
} else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
}
else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
// a component
reply = XMPPServer.getInstance().getIQDiscoItemsHandler().handleIQ(iq);
router.route(reply);
return;
} else if (NAMESPACE.equals(namespace)) {
}
else if (NAMESPACE.equals(namespace)) {
if (isEnabled()) {
Element stun = childElementCopy.addElement("stun");
......@@ -249,13 +247,14 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
Element publicIp = childElementCopy.addElement("publicip");
publicIp.addAttribute("ip", ip);
}
} catch (UnknownHostException e) {
}
catch (UnknownHostException e) {
e.printStackTrace();
}
}
} else {
}
else {
// Answer an error since the server can't handle the requested namespace
reply.setError(PacketError.Condition.service_unavailable);
}
......@@ -294,7 +293,9 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
String property = "";
for (StunServerAddress stunServerAddress : externalServers) {
if (!property.equals("")) property += ";";
if (!property.equals("")) {
property += ";";
}
property += stunServerAddress.getServer() + ":" + stunServerAddress.getPort();
}
JiveGlobals.setProperty("stun.external.addresses", property);
......@@ -304,7 +305,9 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
externalServers.remove(index);
String property = "";
for (StunServerAddress stunServerAddress : externalServers) {
if (!property.equals("")) property += ";";
if (!property.equals("")) {
property += ";";
}
property += stunServerAddress.getServer() + ":" + stunServerAddress.getPort();
}
JiveGlobals.setProperty("stun.external.addresses", property);
......@@ -370,7 +373,7 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
}
/**
* Get if the service is enabled.
* Returns true if the service is enabled.
*
* @return enabled
*/
......@@ -379,7 +382,7 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
}
/**
* Get if the local STUN Server is enabled.
* Returns true if the local STUN server is enabled.
*
* @return enabled
*/
......@@ -390,7 +393,7 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
/**
* Set the service enable status.
*
* @param enabled boolean to enable or disable
* @param enabled boolean to enable or disable
* @param localEnabled local Server enable or disable
*/
public void setEnabled(boolean enabled, boolean localEnabled) {
......@@ -398,9 +401,11 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
this.localEnabled = localEnabled;
if (isEnabled()) {
startService();
if (isLocalEnabled())
if (isLocalEnabled()) {
startLocalServer();
} else {
}
}
else {
stop();
}
}
......@@ -412,10 +417,12 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
*/
public void setLocalEnabled(boolean enabled) {
this.localEnabled = enabled;
if (isLocalEnabled())
if (isLocalEnabled()) {
startLocalServer();
else
}
else {
stopLocal();
}
}
/**
......@@ -477,25 +484,27 @@ public class STUNService extends BasicModule implements ServerItemsProvider, Rou
/**
* 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
* @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.equals("")) return list;
if (addresses.equals("")) {
return list;
}
String servers[] = addresses.split(";");
for (String server : servers) {
String address[] = server.split(":");
StunServerAddress aux = new StunServerAddress(address[0], address[1]);
if (!list.contains(aux))
if (!list.contains(aux)) {
list.add(aux);
}
}
return list;
}
}
}
\ No newline at end of file
......@@ -130,16 +130,16 @@
</sidebar>
<!-- Server Settings -->
<sidebar id="sidebar-media-services" name="Media Services">
<sidebar id="sidebar-media-services" name="${sidebar.sidebar-media-services}">
<!-- Media Proxy Settings -->
<item id="media-proxy-service" name="Media Proxy"
<item id="media-proxy-service" name="${sidebar.media-proxy}"
url="media-proxy.jsp"
description="Media proxy settings"/>
description="${sidebar.media-proxy.desc}"/>
<!-- STUN Server Settings -->
<item id="stun-settings" name="STUN Server Settings"
<item id="stun-settings" name="${sidebar.stun}"
url="stun-settings.jsp"
description="STUN Server Settings"/>
description="${sidebar.stun.desc}"/>
</sidebar>
</tab>
......
<%--
- $Revision: 5321 $
- $Date: 2006-09-11 01:22:53 -0300 (seg, 11 set 2006) $
-
- Copyright (C) 2004-2005 Jive Software. All rights reserved.
- Copyright (C) 2007 Jive Software. All rights reserved.
-
- This software is published under the terms of the GNU Public License (GPL),
- a copy of which is included in this distribution.
......@@ -11,9 +8,9 @@
<%@ page import="org.jivesoftware.util.ParamUtils" %>
<%@ page import="org.jivesoftware.wildfire.XMPPServer" %>
<%@ page import="org.jivesoftware.wildfire.stun.STUNService" %>
<%@ page import="org.jivesoftware.wildfire.stun.StunServerAddress" %>
<%@ page import="java.net.InetAddress" %>
<%@ page import="java.util.List" %>
<%@ page import="org.jivesoftware.wildfire.stun.StunServerAddress" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
......@@ -89,10 +86,12 @@
success = stunService.isEnabled() == enabled && stunService.isLocalEnabled() == localEnabled;
} else if (remove > -1) {
}
else if (remove > -1) {
stunService.removeExternalServer(remove);
success = true;
} else if (add) {
}
else if (add) {
String server = ParamUtils.getParameter(request, "externalServer", true);
String port = ParamUtils.getParameter(request, "externalPort", true);
......@@ -181,62 +180,58 @@
<fmt:message key="stun.settings.title"/>
</div>
<div class="jive-contentBox">
<p>
<fmt:message key="stun.settings.comment"/>
</p>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<table cellpadding="3" cellspacing="5" border="0">
<tbody>
<tr>
<td align="left" colspan="2">
<fmt:message key="stun.settings.localenabled"/>
:&nbsp<input type="checkbox"
name="localEnabled"
<%=stunService.isLocalEnabled()?"checked":""%>
align="left">
</td>
</tr>
<tr>
<td align="left">
<fmt:message key="stun.settings.primaryaddress"/>
:&nbsp<select size="1"
maxlength="100"
name="primaryAddress"
align="left">
<option value="<%=stunService.getPrimaryAddress()%>"><%=stunService.getPrimaryAddress()%>
<%
List<InetAddress> addresses = stunService.getAddresses();
for(InetAddress iaddress:addresses){
if(!iaddress.getHostAddress().equals(stunService.getPrimaryAddress())){
%>
<option value="<%=iaddress.getHostAddress()%>"><%=iaddress.getHostAddress()%>
</option>
<fmt:message key="stun.settings.primaryaddress"/>:
</td><td>
<select size="1" name="primaryAddress">
<option value="CHOOSE">-- Select Address --</option>
<%
}
}
String sname = JiveGlobals.getProperty("xmpp.domain", JiveGlobals.getXMLProperty("network.interface", "localhost"));
List<InetAddress> addresses = stunService.getAddresses();
for (InetAddress iaddress : addresses) {
String hostAddress = iaddress.getHostAddress();
boolean isPrimaryAddress = hostAddress.equals(stunService.getPrimaryAddress());
%>
<option value="<%=sname%>"><%=sname%>
<option value="<%= hostAddress %>" <% if(isPrimaryAddress) { %>selected <% } %> ><%= hostAddress %>
</option>
<% } %>
</td>
</tr>
<tr>
<td align="left">
<fmt:message key="stun.settings.secondaryaddress"/>
:&nbsp<select size="1"
maxlength="100"
name="secondaryAddress"
align="left">
<option value="<%=stunService.getSecondaryAddress()%>"><%=stunService.getSecondaryAddress()%>
</option>
<fmt:message key="stun.settings.secondaryaddress"/>:
</td><td>
<select size="1" name="secondaryAddress">
<option value="CHOOSE">-- Select Address --</option>
<%
for (InetAddress iaddress : addresses) {
if (!iaddress.getHostAddress().equals(stunService.getSecondaryAddress())) {
String hostAddress = iaddress.getHostAddress();
boolean isSecondaryAddress = hostAddress.equals(stunService.getSecondaryAddress());
%>
<option value="<%=iaddress.getHostAddress()%>"><%=iaddress.getHostAddress()%>
<option value="<%= hostAddress %>" <% if(isSecondaryAddress) { %>selected <% } %> ><%= hostAddress %>
</option>
<% }
}%>
<option value="127.0.0.1">127.0.0.1</option>
<% } %>
</select>
</td>
</tr>
<tr>
<td align="left">
<fmt:message key="stun.settings.primaryport"/>
:&nbsp<input type="text" size="20"
maxlength="100"
<fmt:message key="stun.settings.primaryport"/>:
</td><td>
<input type="text" size="6"
maxlength="10"
name="primaryPort"
value="<%=stunService.getPrimaryPort()%>"
align="left">
......@@ -244,41 +239,19 @@
</tr>
<tr>
<td align="left">
<fmt:message key="stun.settings.secondaryport"/>
:&nbsp<input type="text" size="20"
maxlength="100"
<fmt:message key="stun.settings.secondaryport"/>:
</td><td>
<input type="text" size="6"
maxlength="10"
name="secondaryPort"
value="<%=stunService.getSecondaryPort()%>"
align="left">
</td>
</tr>
<tr>
<td align="left">
<fmt:message key="stun.settings.localenabled"/>
:&nbsp<input type="checkbox"
name="localEnabled"
<%=stunService.isLocalEnabled()?"checked":""%>
align="left">
</td>
</tr>
<tr>
<td align="left">
<fmt:message key="stun.settings.enabled"/>
:&nbsp<input type="checkbox"
name="enabled"
<%=stunService.isEnabled()?"checked":""%>
align="left">
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
</tr>
<tr>
<td>
<input type="hidden" name="save">
<input type="button" name="set" value="<fmt:message key="stun.settings.change" />"
<input type="button" name="set" value="<fmt:message key="global.save_settings" />"
onclick="checkAndSubmit()">
</td>
</tr>
......@@ -305,7 +278,7 @@
<fmt:message key="stun.external.port"/>
</th>
<th nowrap align="left">
<fmt:message key="stun.external.delete"/>
<fmt:message key="global.delete"/>
</th>
</tr>
</thead>
......@@ -347,7 +320,7 @@
</tr>
<tr>
<td>
<input type="submit" name="add" value="<fmt:message key="stun.external.add"/>">
<input type="submit" name="add" value="<fmt:message key="global.add"/>">
</td>
</tr>
</tbody>
......
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