diff --git a/src/org/ice4j/ice/CandidateExtendedType.java b/src/org/ice4j/ice/CandidateExtendedType.java new file mode 100644 index 0000000..1606482 --- /dev/null +++ b/src/org/ice4j/ice/CandidateExtendedType.java @@ -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 CandidateExtendedType instance. + */ + private final String extendedTypeName; + + /** + * Creates a CandidateExtendedType instance with the specified + * name. + * + * @param extendedTypeName the name of the CandidateExtendedType + * instance we'd like to create. + */ + private CandidateExtendedType(String extendedTypeName) + { + this.extendedTypeName = extendedTypeName; + } + + /** + * Returns the name of this CandidateExtendedType (e.g. "host", + * "upnp", "stun peer reflexive", "stun server reflexive", "turn relayed", + * "google turn relayed" or "jingle node"). + * + * @return The name of this CandidateExtendedType (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 CandidateExtendedType instance corresponding to the + * specified extendedTypeName. For example, for name "host", this + * method would return {@link #HOST_CANDIDATE}. + * + * @param extendedTypeName the name that we'd like to parse. + * + * @return a CandidateExtendedType instance corresponding to the + * specified extendedTypeName. + * + * @throws IllegalArgumentException in case extendedTypeName 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"); + } +} diff --git a/src/org/ice4j/ice/GoogleRelayedCandidate.java b/src/org/ice4j/ice/GoogleRelayedCandidate.java index dde63c6..a73ad52 100644 --- a/src/org/ice4j/ice/GoogleRelayedCandidate.java +++ b/src/org/ice4j/ice/GoogleRelayedCandidate.java @@ -80,7 +80,14 @@ public class GoogleRelayedCandidate super( transportAddress, 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.username = username; @@ -190,4 +197,4 @@ public class GoogleRelayedCandidate } return socket; } -} \ No newline at end of file +} diff --git a/src/org/ice4j/ice/HostCandidate.java b/src/org/ice4j/ice/HostCandidate.java index f22f1d3..648d846 100644 --- a/src/org/ice4j/ice/HostCandidate.java +++ b/src/org/ice4j/ice/HostCandidate.java @@ -49,7 +49,8 @@ public class HostCandidate extends LocalCandidate super(new TransportAddress(socket.getLocalAddress(), socket.getLocalPort(), Transport.UDP), parentComponent, - CandidateType.HOST_CANDIDATE); + CandidateType.HOST_CANDIDATE, + CandidateExtendedType.HOST_CANDIDATE); this.socket = socket; setBase(this); @@ -71,7 +72,8 @@ public class HostCandidate extends LocalCandidate super(new TransportAddress(socket.getLocalAddress(), socket.getLocalPort(), transport), parentComponent, - CandidateType.HOST_CANDIDATE); + CandidateType.HOST_CANDIDATE, + CandidateExtendedType.HOST_CANDIDATE); this.socket = socket; setBase(this); diff --git a/src/org/ice4j/ice/LocalCandidate.java b/src/org/ice4j/ice/LocalCandidate.java index 1d22036..2a81104 100644 --- a/src/org/ice4j/ice/LocalCandidate.java +++ b/src/org/ice4j/ice/LocalCandidate.java @@ -25,6 +25,13 @@ import org.ice4j.stack.*; public abstract class LocalCandidate 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 */ @@ -46,12 +53,18 @@ public abstract class LocalCandidate * @param parentComponent the Component that this candidate * belongs to. * @param type the CandidateType for 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 LocalCandidate(TransportAddress transportAddress, Component parentComponent, - CandidateType type) + CandidateType type, + CandidateExtendedType extendedType) { super(transportAddress, parentComponent, type); + this.extendedType = extendedType; } /** @@ -306,4 +319,33 @@ public abstract class LocalCandidate { 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; + } } diff --git a/src/org/ice4j/ice/PeerReflexiveCandidate.java b/src/org/ice4j/ice/PeerReflexiveCandidate.java index 1f0983a..1be6881 100644 --- a/src/org/ice4j/ice/PeerReflexiveCandidate.java +++ b/src/org/ice4j/ice/PeerReflexiveCandidate.java @@ -42,8 +42,11 @@ public class PeerReflexiveCandidate LocalCandidate base, long priority) { - super(transportAddress, parentComponent, - CandidateType.PEER_REFLEXIVE_CANDIDATE); + super( + transportAddress, + parentComponent, + CandidateType.PEER_REFLEXIVE_CANDIDATE, + CandidateExtendedType.STUN_PEER_REFLEXIVE_CANDIDATE); super.setBase(base); super.priority = priority; } diff --git a/src/org/ice4j/ice/RelayedCandidate.java b/src/org/ice4j/ice/RelayedCandidate.java index 4b724db..0d9d534 100644 --- a/src/org/ice4j/ice/RelayedCandidate.java +++ b/src/org/ice4j/ice/RelayedCandidate.java @@ -66,7 +66,8 @@ public class RelayedCandidate super( transportAddress, turnCandidateHarvest.hostCandidate.getParentComponent(), - CandidateType.RELAYED_CANDIDATE); + CandidateType.RELAYED_CANDIDATE, + CandidateExtendedType.TURN_RELAYED_CANDIDATE); this.turnCandidateHarvest = turnCandidateHarvest; diff --git a/src/org/ice4j/ice/ServerReflexiveCandidate.java b/src/org/ice4j/ice/ServerReflexiveCandidate.java index 1f99cd7..ae73ed2 100644 --- a/src/org/ice4j/ice/ServerReflexiveCandidate.java +++ b/src/org/ice4j/ice/ServerReflexiveCandidate.java @@ -42,14 +42,20 @@ public class ServerReflexiveCandidate * candidate was obtained through. * @param stunSrvrAddr the {@link TransportAddress} of the stun server that * 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, HostCandidate base, - TransportAddress stunSrvrAddr) + TransportAddress stunSrvrAddr, + CandidateExtendedType extendedType) { super(address, base.getParentComponent(), - CandidateType.SERVER_REFLEXIVE_CANDIDATE); + CandidateType.SERVER_REFLEXIVE_CANDIDATE, + extendedType); setBase(base); setStunServerAddress(stunSrvrAddr); @@ -67,15 +73,21 @@ public class ServerReflexiveCandidate * @param stunSrvrAddr the {@link TransportAddress} of the stun server that * reflected this candidate. * @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, HostCandidate base, TransportAddress stunSrvrAddr, - StunCandidateHarvest stunHarvest) + StunCandidateHarvest stunHarvest, + CandidateExtendedType extendedType) { super(address, base.getParentComponent(), - CandidateType.SERVER_REFLEXIVE_CANDIDATE); + CandidateType.SERVER_REFLEXIVE_CANDIDATE, + extendedType); setBase(base); setStunServerAddress(stunSrvrAddr); diff --git a/src/org/ice4j/ice/UPNPCandidate.java b/src/org/ice4j/ice/UPNPCandidate.java index d06c303..1680234 100644 --- a/src/org/ice4j/ice/UPNPCandidate.java +++ b/src/org/ice4j/ice/UPNPCandidate.java @@ -40,8 +40,11 @@ public class UPNPCandidate LocalCandidate base, Component parentComponent, GatewayDevice device) { - super(transportAddress, parentComponent, - CandidateType.SERVER_REFLEXIVE_CANDIDATE); + super( + transportAddress, + parentComponent, + CandidateType.SERVER_REFLEXIVE_CANDIDATE, + CandidateExtendedType.UPNP_CANDIDATE); this.setBase(base); this.device = device; diff --git a/src/org/ice4j/ice/harvest/StunCandidateHarvest.java b/src/org/ice4j/ice/harvest/StunCandidateHarvest.java index 9d61eab..e8a7ede 100644 --- a/src/org/ice4j/ice/harvest/StunCandidateHarvest.java +++ b/src/org/ice4j/ice/harvest/StunCandidateHarvest.java @@ -391,7 +391,8 @@ public class StunCandidateHarvest new ServerReflexiveCandidate( transportAddress, hostCandidate, - harvester.stunServer); + harvester.stunServer, + CandidateExtendedType.STUN_SERVER_REFLEXIVE_CANDIDATE); } /**