Add the possibility to use SIP Communicator STUN server in case no other STUN servers are available.

cusax-fix
Sebastien Vincent 16 years ago
parent 445bbb0ce1
commit 14910ef05c

@ -693,6 +693,7 @@ plugin.jabberaccregwizz.ADDITIONAL_STUN_SERVERS=Additional STUN servers
plugin.jabberaccregwizz.NO_STUN_ADDRESS=Please fill a valid STUN server address in order to continue.
plugin.jabberaccregwizz.NO_STUN_USERNAME=Please fill a valid STUN server username in order to continue.
plugin.jabberaccregwizz.STUN_ALREADY_EXIST=The STUN server you specified already exist.
plugin.jabberaccregwizz.USE_DEFAULT_STUN_SERVER=Use SIP Communicator STUN server in case no other servers are available.
# mailbox
plugin.mailbox.OUTGOING=Outgoing Message:
@ -1078,4 +1079,4 @@ plugin.provisioning.DHCP=DHCP
plugin.provisioning.DNS=DNS
plugin.provisioning.BONJOUR=Bonjour
plugin.provisioning.MANUAL=Manually specify a provisioning URI
plugin.provisioning.URI=URI
plugin.provisioning.URI=URI

@ -58,6 +58,16 @@ public class IceUdpTransportManager
*/
private final Agent iceAgent;
/**
* Default STUN server address.
*/
private static final String DEFAULT_STUN_SERVER_ADDRESS = "stun.jitsi.net";
/**
* Default STUN server port.
*/
private static final int DEFAULT_STUN_SERVER_PORT = 3478;
/**
* Creates a new instance of this transport manager, binding it to the
* specified peer.
@ -84,7 +94,7 @@ private Agent createIceAgent()
CallPeerJabberImpl peer = getCallPeer();
ProtocolProviderServiceJabberImpl provider = peer.getProtocolProvider();
NetworkAddressManagerService namSer = getNetAddrMgr();
boolean atLeastOneStunServer = false;
Agent agent = namSer.createIceAgent();
/*
@ -115,7 +125,10 @@ private Agent createIceAgent()
logger.info("Auto discovered harvester is " + autoHarvester);
if (autoHarvester != null)
{
atLeastOneStunServer = true;
agent.addCandidateHarvester(autoHarvester);
}
}
//now create stun server descriptors for whatever other STUN/TURN
@ -146,9 +159,31 @@ private Agent createIceAgent()
if (logger.isInfoEnabled())
logger.info("Adding pre-configured harvester " + harvester);
atLeastOneStunServer = true;
agent.addCandidateHarvester(harvester);
}
if(!atLeastOneStunServer)
{
/* we have no configured or discovered STUN server so takes the
* default provided by us if user allows it
*/
if(accID.isUseDefaultStunServer())
{
TransportAddress addr = new TransportAddress(
DEFAULT_STUN_SERVER_ADDRESS,
DEFAULT_STUN_SERVER_PORT,
Transport.UDP);
StunCandidateHarvester harvester =
new StunCandidateHarvester(addr);
if(harvester != null)
{
agent.addCandidateHarvester(harvester);
}
}
}
return agent;
}

@ -92,4 +92,20 @@ public boolean isStunServerDiscoveryEnabled()
ProtocolProviderFactory.AUTO_DISCOVER_STUN,
false);
}
/**
* Determines whether this account's provider use the default STUN server
* provided by SIP Communicator if there is no other STUN/TURN server
* discovered/configured.
*
* @return <tt>true</tt> if this provider would use the default STUN server,
* <tt>false</tt> otherwise
*/
public boolean isUseDefaultStunServer()
{
return
getAccountPropertyBoolean(
ProtocolProviderFactory.USE_DEFAULT_STUN_SERVER,
false);
}
}

@ -167,6 +167,8 @@ public void commitPage()
registration.setUseIce(iceConfigPanel.isUseIce());
registration.setAutoDiscoverStun(iceConfigPanel.isAutoDiscoverStun());
registration.setUseDefaultStunServer(
iceConfigPanel.isUseDefaultStunServer());
//we will be reentering all stun servers so let's make sure we clear
//the servers vector in case we already did that with a "Next".

@ -44,6 +44,13 @@ public class IceConfigPanel
private final JCheckBox autoDiscoverBox = new SIPCommCheckBox(
Resources.getString("plugin.jabberaccregwizz.AUTO_DISCOVER_STUN"));
/**
* The check box allowing the user to choose to use the default
* SIP Communicator STUN server.
*/
private final JCheckBox defaultStunBox = new SIPCommCheckBox(
Resources.getString("plugin.jabberaccregwizz.USE_DEFAULT_STUN_SERVER"));
/**
* The table model for our additional stun servers table.
*/
@ -63,6 +70,7 @@ public IceConfigPanel()
iceBox.setAlignmentX(Component.LEFT_ALIGNMENT);
autoDiscoverBox.setAlignmentX(Component.LEFT_ALIGNMENT);
defaultStunBox.setAlignmentX(Component.LEFT_ALIGNMENT);
/* ICE and STUN/TURN discovery are enabled by default for a new account,
* these properties will be overridden for existing account when
@ -70,10 +78,12 @@ public IceConfigPanel()
*/
iceBox.setSelected(true);
autoDiscoverBox.setSelected(true);
defaultStunBox.setSelected(true);
JPanel checkBoxPanel = new TransparentPanel(new GridLayout(0, 1));
checkBoxPanel.add(iceBox);
checkBoxPanel.add(autoDiscoverBox);
checkBoxPanel.add(defaultStunBox);
add(checkBoxPanel);
add(Box.createVerticalStrut(10));
@ -638,6 +648,26 @@ void setAutoDiscoverStun(boolean isAutoDiscover)
autoDiscoverBox.setSelected(isAutoDiscover);
}
/**
* Indicates if the default stun server should be used
* @return <tt>true</tt> if the default stun server should be used,
* otherwise returns <tt>false</tt>.
*/
boolean isUseDefaultStunServer()
{
return defaultStunBox.isSelected();
}
/**
* Sets the <tt>defaultStun</tt> property.
* @param isDefaultStun <tt>true</tt> to indicate that the default stun
* server should be used, <tt>false</tt> otherwise.
*/
void setUseDefaultStunServer(boolean isDefaultStun)
{
defaultStunBox.setSelected(isDefaultStun);
}
/**
* Returns the list of additional stun servers entered by the user.
*

@ -93,6 +93,11 @@ public class JabberAccountRegistration
*/
private boolean isAutoDiscoverStun = false;
/**
* Indicates if default STUN server should be used.
*/
private boolean isUseDefaultStunServer = false;
/**
* The list of additional STUN servers entered by user.
*/
@ -316,6 +321,27 @@ public void setAutoDiscoverStun(boolean isAutoDiscover)
this.isAutoDiscoverStun = isAutoDiscover;
}
/**
* Indicates if the stun server should be automatically discovered.
* @return <tt>true</tt> if the stun server should be automatically
* discovered, otherwise returns <tt>false</tt>.
*/
public boolean isUseDefaultStunServer()
{
return isUseDefaultStunServer;
}
/**
* Sets the <tt>useDefaultStunServer</tt> property.
* @param isUseDefaultStunServer <tt>true</tt> to indicate that default
* stun server should be used if no others are available, <tt>false</tt>
* otherwise.
*/
public void setUseDefaultStunServer(boolean isUseDefaultStunServer)
{
this.isUseDefaultStunServer = isUseDefaultStunServer;
}
/**
* Adds the given <tt>stunServer</tt> to the list of additional stun servers.
*

@ -261,10 +261,14 @@ public ProtocolProviderService installAccount(
accountProperties.put(ProtocolProviderFactory.AUTO_DISCOVER_STUN,
String.valueOf(registration.isAutoDiscoverStun()));
accountProperties.put(ProtocolProviderFactory.USE_DEFAULT_STUN_SERVER,
String.valueOf(registration.isUseDefaultStunServer()));
List<StunServerDescriptor> stunServers
= registration.getAdditionalStunServers();
int serverIndex = -1;
for(StunServerDescriptor stunServer : stunServers)
{
serverIndex ++;

@ -111,7 +111,7 @@ public abstract class ProtocolProviderFactory
/**
* The name of the property which defines whether proxy is auto configured
* bu the protocol by using known methods such as specific DNS queries.
* by the protocol by using known methods such as specific DNS queries.
*/
public static final String PROXY_AUTO_CONFIG = "PROXY_AUTO_CONFIG";
@ -137,8 +137,8 @@ public abstract class ProtocolProviderFactory
public static final String PROXY_TYPE = "PROXY_TYPE";
/**
* The name of the property under which we store the the username for the proxy
* stored against the PROXY_ADDRESS property.
* The name of the property under which we store the the username for the
* proxy stored against the PROXY_ADDRESS property.
*/
public static final String PROXY_USERNAME = "PROXY_USERNAME";
@ -168,8 +168,8 @@ public abstract class ProtocolProviderFactory
public static final String PREFERRED_TRANSPORT = "PREFERRED_TRANSPORT";
/**
* The name of the property under which we store resources such as the jabber
* resource property.
* The name of the property under which we store resources such as the
* jabber resource property.
*/
public static final String RESOURCE = "RESOURCE";
@ -179,14 +179,17 @@ public abstract class ProtocolProviderFactory
public static final String RESOURCE_PRIORITY = "RESOURCE_PRIORITY";
/**
* The name of the property which defines that the call is encrypted by default
* The name of the property which defines that the call is encrypted by
* default
*/
public static final String DEFAULT_ENCRYPTION = "DEFAULT_ENCRYPTION";
/**
* The name of the property which defines if to include the ZRTP attribute to SIP/SDP
* The name of the property which defines if to include the ZRTP attribute
* to SIP/SDP
*/
public static final String DEFAULT_SIPZRTP_ATTRIBUTE = "DEFAULT_SIPZRTP_ATTRIBUTE";
public static final String DEFAULT_SIPZRTP_ATTRIBUTE =
"DEFAULT_SIPZRTP_ATTRIBUTE";
/**
* The name of the property under which we store the boolean value
@ -271,6 +274,13 @@ public abstract class ProtocolProviderFactory
*/
public static final String AUTO_DISCOVER_STUN = "AUTO_DISCOVER_STUN";
/**
* Indicates if default STUN server would be used if no other STUN/TURN
* server are available.
*/
public static final String USE_DEFAULT_STUN_SERVER =
"USE_DEFAULT_STUN_SERVER";
/**
* The property name prefix for all stun server properties. We generally use
* this prefix in conjunction with an index which is how we store multiple
@ -381,7 +391,7 @@ public BundleContext getBundleContext()
* @throws java.lang.NullPointerException if any of the arguments is null.
*/
public abstract AccountID installAccount(String userID,
Map<String, String> accountProperties)
Map<String, String> accountProperties)
throws IllegalArgumentException,
IllegalStateException,
NullPointerException;
@ -441,9 +451,9 @@ public ServiceReference getProviderForAccount(AccountID accountID)
/**
* Removes the specified account from the list of accounts that this
* provider factory is handling. If the specified accountID is unknown to the
* ProtocolProviderFactory, the call has no effect and false is returned.
* This method is persistent in nature and once called the account
* provider factory is handling. If the specified accountID is unknown to
* the ProtocolProviderFactory, the call has no effect and false is
* returned. This method is persistent in nature and once called the account
* corresponding to the specified ID will not be loaded during future runs
* of the project.
*
@ -473,7 +483,7 @@ public boolean uninstallAccount(AccountID accountID)
catch (OperationFailedException ex)
{
logger
.error("Failed to unregister protocol provider for account : "
.error("Failed to unregister protocol provider for account: "
+ accountID + " caused by: " + ex);
}
}
@ -485,8 +495,8 @@ public boolean uninstallAccount(AccountID accountID)
registration = registeredAccounts.remove(accountID);
}
// first remove the stored account so when PP is unregistered we can distinguish
// between deleted or just disabled account
// first remove the stored account so when PP is unregistered we can
// distinguish between deleted or just disabled account
wasAccountExisting = removeStoredAccount(accountID);
if (registration != null)
@ -882,8 +892,9 @@ public static String findAccountPrefix(BundleContext bundleContext,
= (ConfigurationService) bundleContext.getService(confReference);
//first retrieve all accounts that we've registered
List<String> storedAccounts = configurationService.getPropertyNamesByPrefix(
sourcePackageName, true);
List<String> storedAccounts =
configurationService.getPropertyNamesByPrefix(sourcePackageName,
true);
//find an account with the corresponding id.
for (String accountRootPropertyName : storedAccounts)

Loading…
Cancel
Save