Fixes GitHub issue #24: Wrong preference for choosing default candidate (not in accordance with rfc5245).

This commit is contained in:
Lyubomir Marinov 2015-07-28 11:35:07 -05:00
parent 469f045b9b
commit 75c2a52f9e
3 changed files with 40 additions and 24 deletions

14
pom.xml
View File

@ -35,6 +35,20 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*TestSuite.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
<profiles> <profiles>
<profile> <profile>
<activation> <activation>

View File

@ -773,24 +773,32 @@ public abstract class Candidate<T extends Candidate<?>>
*/ */
protected int getDefaultPreference() protected int getDefaultPreference()
{ {
if( getType() == CandidateType.RELAYED_CANDIDATE) // https://tools.ietf.org/html/rfc5245#section-4.1.4
//
// It is RECOMMENDED that default candidates be chosen based on the
// likelihood of those candidates to work with the peer that is being
// contacted. It is RECOMMENDED that the default candidates are the
// relayed candidates (if relayed candidates are available), server
// reflexive candidates (if server reflexive candidates are available),
// and finally host candidates.
switch (getType())
{
case RELAYED_CANDIDATE:
return 30; return 30;
if( getType() == CandidateType.SERVER_REFLEXIVE_CANDIDATE) case SERVER_REFLEXIVE_CANDIDATE:
return 10; return 20;
if( getType() == CandidateType.HOST_CANDIDATE) case HOST_CANDIDATE:
{ // Prefer IPv4 as default since many servers would still freak out
//prefer IPv4 as default since many servers would still freak out // when seeing IPv6 address.
//when seeing IPv6 address. return getTransportAddress().isIPv6() ? 10 : 15;
if(getTransportAddress().isIPv6())
return 20; default:
else // WTF?
return 25; return 5;
} }
//WTF?
return 5;
} }
/** /**

View File

@ -691,21 +691,15 @@ public class Component
{ {
synchronized(localCandidates) synchronized(localCandidates)
{ {
Iterator<LocalCandidate> localCandsIter Iterator<LocalCandidate> localCandsIter = localCandidates.iterator();
= localCandidates.iterator();
while (localCandsIter.hasNext()) while (localCandsIter.hasNext())
{ {
LocalCandidate cand = localCandsIter.next(); LocalCandidate cand = localCandsIter.next();
if(this.defaultCandidate == null) if ((defaultCandidate == null)
{ || (defaultCandidate.getDefaultPreference()
this.defaultCandidate = cand; < cand.getDefaultPreference()))
continue;
}
if( defaultCandidate.getDefaultPreference()
< cand.getDefaultPreference())
{ {
defaultCandidate = cand; defaultCandidate = cand;
} }