Adds CandidateExtendedType to list the different available methods to discover new Candidates: HOST, UPNP, STUN_PEER_REFLEXIVE, STUN_SERVER_REFLEXIVE, TURN_RELAYED, GOOGLE_TURN_RELAYED, GOOGLE_TCP_TURN_RELAYED and JINGLE_NODE.

This commit is contained in:
chenzo 2012-03-01 10:45:18 +00:00
parent e7aafa2e1a
commit c6f54124d5
9 changed files with 220 additions and 15 deletions

View File

@ -0,0 +1,134 @@
/*
* ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
* Maintained by the SIP Communicator community (http://sip-communicator.org).
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.ice4j.ice;
/**
* Enumeration which lists the different available methods used to discover new
* candidates.
*
* @author Vincent Lucas
*/
public enum CandidateExtendedType
{
/**
* There candidate is discovered directly by the host.
*/
HOST_CANDIDATE("host"),
/**
* There candidate is discovered by using UPNP method.
*/
UPNP_CANDIDATE("upnp"),
/**
* There candidate is discovered by using STUN peer reflexive method (cf.
* RFC5389).
*/
STUN_PEER_REFLEXIVE_CANDIDATE("stun peer reflexive"),
/**
* There candidate is discovered by using STUN server reflexive method (cf.
* RFC5389).
*/
STUN_SERVER_REFLEXIVE_CANDIDATE("stun server reflexive"),
/**
* There candidate is discovered by using TURN relayed method (cf. RFC5766).
*/
TURN_RELAYED_CANDIDATE("turn relayed"),
/**
* There candidate is discovered by using TURN relayed method (cf. RFC5766).
*/
GOOGLE_TURN_RELAYED_CANDIDATE("google turn relayed"),
/**
* There candidate is discovered by using TURN relayed method and using TCP
* (cf. RFC5766).
*/
GOOGLE_TCP_TURN_RELAYED_CANDIDATE("google tcp turn relayed"),
/**
* There candidate is discovered by using JINGLE NODE method (cf. XEP-0278).
*/
JINGLE_NODE_CANDIDATE("jingle node");
/**
* The name of this <tt>CandidateExtendedType</tt> instance.
*/
private final String extendedTypeName;
/**
* Creates a <tt>CandidateExtendedType</tt> instance with the specified
* name.
*
* @param extendedTypeName the name of the <tt>CandidateExtendedType</tt>
* instance we'd like to create.
*/
private CandidateExtendedType(String extendedTypeName)
{
this.extendedTypeName = extendedTypeName;
}
/**
* Returns the name of this <tt>CandidateExtendedType</tt> (e.g. "host",
* "upnp", "stun peer reflexive", "stun server reflexive", "turn relayed",
* "google turn relayed" or "jingle node").
*
* @return The name of this <tt>CandidateExtendedType</tt> (e.g. "host",
* "upnp", "stun peer reflexive", "stun server reflexive", "turn relayed",
* "google turn relayed", "google tcp turn relayed" or "jingle node").
*/
@Override
public String toString()
{
return extendedTypeName;
}
/**
* Returns a <tt>CandidateExtendedType</tt> instance corresponding to the
* specified <tt>extendedTypeName</tt>. For example, for name "host", this
* method would return {@link #HOST_CANDIDATE}.
*
* @param extendedTypeName the name that we'd like to parse.
*
* @return a <tt>CandidateExtendedType</tt> instance corresponding to the
* specified <tt>extendedTypeName</tt>.
*
* @throws IllegalArgumentException in case <tt>extendedTypeName</tt> is
* not a valid or currently supported candidate extended type.
*/
public static CandidateExtendedType parse(String extendedTypeName)
throws IllegalArgumentException
{
if(HOST_CANDIDATE.toString().equals(extendedTypeName))
return HOST_CANDIDATE;
else if(UPNP_CANDIDATE.toString().equals(extendedTypeName))
return UPNP_CANDIDATE;
else if(STUN_PEER_REFLEXIVE_CANDIDATE.toString().equals(
extendedTypeName))
return STUN_PEER_REFLEXIVE_CANDIDATE;
else if(STUN_SERVER_REFLEXIVE_CANDIDATE.toString().equals(
extendedTypeName))
return STUN_SERVER_REFLEXIVE_CANDIDATE;
else if(TURN_RELAYED_CANDIDATE.toString().equals(extendedTypeName))
return TURN_RELAYED_CANDIDATE;
else if(GOOGLE_TURN_RELAYED_CANDIDATE.toString().equals(
extendedTypeName))
return GOOGLE_TURN_RELAYED_CANDIDATE;
else if(GOOGLE_TCP_TURN_RELAYED_CANDIDATE.toString().equals(
extendedTypeName))
return GOOGLE_TCP_TURN_RELAYED_CANDIDATE;
else if(JINGLE_NODE_CANDIDATE.toString().equals(extendedTypeName))
return JINGLE_NODE_CANDIDATE;
throw new IllegalArgumentException(
extendedTypeName
+ " is not a currently supported CandidateExtendedType");
}
}

View File

@ -80,7 +80,14 @@ public class GoogleRelayedCandidate
super( super(
transportAddress, transportAddress,
turnCandidateHarvest.hostCandidate.getParentComponent(), turnCandidateHarvest.hostCandidate.getParentComponent(),
CandidateType.RELAYED_CANDIDATE); CandidateType.RELAYED_CANDIDATE,
CandidateExtendedType.GOOGLE_TURN_RELAYED_CANDIDATE);
if(transportAddress.getTransport() == Transport.TCP)
{
super.setExtendedType(
CandidateExtendedType.GOOGLE_TCP_TURN_RELAYED_CANDIDATE);
}
this.turnCandidateHarvest = turnCandidateHarvest; this.turnCandidateHarvest = turnCandidateHarvest;
this.username = username; this.username = username;

View File

@ -49,7 +49,8 @@ public class HostCandidate extends LocalCandidate
super(new TransportAddress(socket.getLocalAddress(), super(new TransportAddress(socket.getLocalAddress(),
socket.getLocalPort(), Transport.UDP), socket.getLocalPort(), Transport.UDP),
parentComponent, parentComponent,
CandidateType.HOST_CANDIDATE); CandidateType.HOST_CANDIDATE,
CandidateExtendedType.HOST_CANDIDATE);
this.socket = socket; this.socket = socket;
setBase(this); setBase(this);
@ -71,7 +72,8 @@ public class HostCandidate extends LocalCandidate
super(new TransportAddress(socket.getLocalAddress(), super(new TransportAddress(socket.getLocalAddress(),
socket.getLocalPort(), transport), socket.getLocalPort(), transport),
parentComponent, parentComponent,
CandidateType.HOST_CANDIDATE); CandidateType.HOST_CANDIDATE,
CandidateExtendedType.HOST_CANDIDATE);
this.socket = socket; this.socket = socket;
setBase(this); setBase(this);

View File

@ -25,6 +25,13 @@ import org.ice4j.stack.*;
public abstract class LocalCandidate public abstract class LocalCandidate
extends Candidate extends Candidate
{ {
/**
* The type of method used to discover this candidate ("host", "upnp", "stun
* peer reflexive", "stun server reflexive", "turn relayed", "google turn
* relayed", "google tcp turn relayed" or "jingle node").
*/
private CandidateExtendedType extendedType = null;
/** /**
* Ufrag for the local candidat * Ufrag for the local candidat
*/ */
@ -46,12 +53,18 @@ public abstract class LocalCandidate
* @param parentComponent the <tt>Component</tt> that this candidate * @param parentComponent the <tt>Component</tt> that this candidate
* belongs to. * belongs to.
* @param type the <tt>CandidateType</tt> for this <tt>Candidate</tt>. * @param type the <tt>CandidateType</tt> for this <tt>Candidate</tt>.
* @param extendedType The type of method used to discover this candidate
* ("host", "upnp", "stun peer reflexive", "stun server reflexive", "turn
* relayed", "google turn relayed", "google tcp turn relayed" or "jingle
* node").
*/ */
public LocalCandidate(TransportAddress transportAddress, public LocalCandidate(TransportAddress transportAddress,
Component parentComponent, Component parentComponent,
CandidateType type) CandidateType type,
CandidateExtendedType extendedType)
{ {
super(transportAddress, parentComponent, type); super(transportAddress, parentComponent, type);
this.extendedType = extendedType;
} }
/** /**
@ -306,4 +319,33 @@ public abstract class LocalCandidate
{ {
return ufrag; return ufrag;
} }
/**
* Returns the type of method used to discover this candidate ("host",
* "upnp", "stun peer reflexive", "stun server reflexive", "turn relayed",
* "google turn relayed", "google tcp turn relayed" or "jingle node").
*
* @return The type of method used to discover this candidate ("host",
* "upnp", "stun peer reflexive", "stun server reflexive", "turn relayed",
* "google turn relayed", "google tcp turn relayed" or "jingle node").
*/
public CandidateExtendedType getExtendedType()
{
return this.extendedType;
}
/**
* Sets the type of method used to discover this candidate ("host", "upnp",
* "stun peer reflexive", "stun server reflexive", "turn relayed", "google
* turn relayed", "google tcp turn relayed" or "jingle node").
*
* @param extendedType The type of method used to discover this candidate
* ("host", "upnp", "stun peer reflexive", "stun server reflexive", "turn
* relayed", "google turn relayed", "google tcp turn relayed" or "jingle
* node").
*/
public void setExtendedType(CandidateExtendedType extendedType)
{
this.extendedType = extendedType;
}
} }

View File

@ -42,8 +42,11 @@ public class PeerReflexiveCandidate
LocalCandidate base, LocalCandidate base,
long priority) long priority)
{ {
super(transportAddress, parentComponent, super(
CandidateType.PEER_REFLEXIVE_CANDIDATE); transportAddress,
parentComponent,
CandidateType.PEER_REFLEXIVE_CANDIDATE,
CandidateExtendedType.STUN_PEER_REFLEXIVE_CANDIDATE);
super.setBase(base); super.setBase(base);
super.priority = priority; super.priority = priority;
} }

View File

@ -66,7 +66,8 @@ public class RelayedCandidate
super( super(
transportAddress, transportAddress,
turnCandidateHarvest.hostCandidate.getParentComponent(), turnCandidateHarvest.hostCandidate.getParentComponent(),
CandidateType.RELAYED_CANDIDATE); CandidateType.RELAYED_CANDIDATE,
CandidateExtendedType.TURN_RELAYED_CANDIDATE);
this.turnCandidateHarvest = turnCandidateHarvest; this.turnCandidateHarvest = turnCandidateHarvest;

View File

@ -42,14 +42,20 @@ public class ServerReflexiveCandidate
* candidate was obtained through. * candidate was obtained through.
* @param stunSrvrAddr the {@link TransportAddress} of the stun server that * @param stunSrvrAddr the {@link TransportAddress} of the stun server that
* reflected this candidate. * reflected this candidate.
* @param extendedType The type of method used to discover this candidate
* ("host", "upnp", "stun peer reflexive", "stun server reflexive", "turn
* relayed", "google turn relayed", "google tcp turn relayed" or "jingle
* node").
*/ */
public ServerReflexiveCandidate(TransportAddress address, public ServerReflexiveCandidate(TransportAddress address,
HostCandidate base, HostCandidate base,
TransportAddress stunSrvrAddr) TransportAddress stunSrvrAddr,
CandidateExtendedType extendedType)
{ {
super(address, super(address,
base.getParentComponent(), base.getParentComponent(),
CandidateType.SERVER_REFLEXIVE_CANDIDATE); CandidateType.SERVER_REFLEXIVE_CANDIDATE,
extendedType);
setBase(base); setBase(base);
setStunServerAddress(stunSrvrAddr); setStunServerAddress(stunSrvrAddr);
@ -67,15 +73,21 @@ public class ServerReflexiveCandidate
* @param stunSrvrAddr the {@link TransportAddress} of the stun server that * @param stunSrvrAddr the {@link TransportAddress} of the stun server that
* reflected this candidate. * reflected this candidate.
* @param stunHarvest the {@link StunCandidateHarvest} * @param stunHarvest the {@link StunCandidateHarvest}
* @param extendedType The type of method used to discover this candidate
* ("host", "upnp", "stun peer reflexive", "stun server reflexive", "turn
* relayed", "google turn relayed", "google tcp turn relayed" or "jingle
* node").
*/ */
public ServerReflexiveCandidate(TransportAddress address, public ServerReflexiveCandidate(TransportAddress address,
HostCandidate base, HostCandidate base,
TransportAddress stunSrvrAddr, TransportAddress stunSrvrAddr,
StunCandidateHarvest stunHarvest) StunCandidateHarvest stunHarvest,
CandidateExtendedType extendedType)
{ {
super(address, super(address,
base.getParentComponent(), base.getParentComponent(),
CandidateType.SERVER_REFLEXIVE_CANDIDATE); CandidateType.SERVER_REFLEXIVE_CANDIDATE,
extendedType);
setBase(base); setBase(base);
setStunServerAddress(stunSrvrAddr); setStunServerAddress(stunSrvrAddr);

View File

@ -40,8 +40,11 @@ public class UPNPCandidate
LocalCandidate base, Component parentComponent, LocalCandidate base, Component parentComponent,
GatewayDevice device) GatewayDevice device)
{ {
super(transportAddress, parentComponent, super(
CandidateType.SERVER_REFLEXIVE_CANDIDATE); transportAddress,
parentComponent,
CandidateType.SERVER_REFLEXIVE_CANDIDATE,
CandidateExtendedType.UPNP_CANDIDATE);
this.setBase(base); this.setBase(base);
this.device = device; this.device = device;

View File

@ -391,7 +391,8 @@ public class StunCandidateHarvest
new ServerReflexiveCandidate( new ServerReflexiveCandidate(
transportAddress, transportAddress,
hostCandidate, hostCandidate,
harvester.stunServer); harvester.stunServer,
CandidateExtendedType.STUN_SERVER_REFLEXIVE_CANDIDATE);
} }
/** /**