-
- All Implemented Interfaces:
-
java.lang.Comparable
public abstract class Candidate<T extends Candidate<out Object>> implements Comparable<T>
A candidate represents a transport address that is a potential point of contact for receipt of media. Candidates also have properties - their type (server reflexive, relayed or host), priority, foundation, and base.
At this point this class only supports UDP candidates. Implementation of support for other transport protocols should mean that this class should become abstract and some transport specific components like to socket for example should be brought down the inheritance chain.
-
-
Field Summary
Fields Modifier and Type Field Description public final static intMAX_TYPE_PREFERENCEpublic final static intMIN_TYPE_PREFERENCEpublic final static intMAX_LOCAL_PREFERENCEpublic final static intMIN_LOCAL_PREFERENCEprivate final TransportAddresstransportAddressprivate CandidateTypecandidateTypeprivate Stringfoundationprivate Tbaseprotected longpriorityprivate booleanvirtualprivate final ComponentparentComponentprivate TransportAddressstunServerAddressprivate TransportAddressrelayServerAddressprivate TransportAddressmappedAddressprivate TrelatedCandidateprivate CandidateTcpTypetcpType
-
Constructor Summary
Constructors Constructor Description Candidate(TransportAddress transportAddress, Component parentComponent, CandidateType type, T relatedCandidate)Creates a candidate for the specified transport address and properties.
-
Method Summary
Modifier and Type Method Description TransportAddressgetTransportAddress()Returns the transport address that this candidate is representing. voidsetCandidateType(CandidateType candidateType)Sets the type of this candidate which should be an instance of the CandidateType enumeration. StringgetFoundation()Returns a String containing the foundation of this Candidate. voidsetFoundation(String foundation)Sets this Candidate's foundation. TgetBase()Returns this Candidate's base. voidsetBase(T base)Sets this Candidate's base. longgetPriority()Returns the priority of this candidate. voidsetVirtual(boolean virtual)Specifies whether the address associated with this candidate belongs to a VPN interface. ComponentgetParentComponent()Returns a reference to the Component that this candidate belongs to. TransportAddressgetStunServerAddress()Returns the address of the STUN server that was used to obtain this Candidate or null if this is not a server reflexive candidate. voidsetStunServerAddress(TransportAddress address)Sets the address of the STUN server that was used to obtain this Candidate. TransportAddressgetRelayServerAddress()Returns the address of the relay server (i.e. voidsetRelayServerAddress(TransportAddress address)Sets the address of the relay server (i.e. TransportAddressgetMappedAddress()Returns the address that was returned to us a "mapped address" from a TURN or a STUN server in case this Candidate is relayed or reflexive and null otherwise. voidsetMappedAddress(TransportAddress address)Sets the address that was returned to us a "mapped address" from a TURN or a STUN server in case this Candidate is relayed. TgetRelatedCandidate()Returns the related candidate corresponding to the address given in parameter: - null for a host candidate, - the base address (host candidate) for a reflexive candidate, - the mapped address (the mapped address of the TURN allocate response) for a relayed candidate. CandidateTcpTypegetTcpType()Gets the CandidateTcpType for this Candidate. voidsetTcpType(CandidateTcpType tcpType)Sets the CandidateTcpType for this Candidate. CandidateTypegetType()Returns the type of this candidate which should be an instance of the CandidateType enumeration. booleanequals(Object obj)Indicates whether some other Candidate is "equal to" this one. inthashCode()longcomputePriority()Computes the priority for this Candidate based on the procedures defined in the ICE specification.. longcomputeGTalkPriority()Computes the priority for this Candidate based on the procedures defined in the Google Talk specification. longcomputePriorityForType(CandidateType candidateType)Computes the priority this Candidate would have if it were of the specified candidateType and based on the procedures defined in the ICE specification. longcomputeGTalkPriorityForType(CandidateType candidateType)Computes the priority this Candidate would have if it were of the specified candidateType and based on the procedures defined in the Google Talk specification. booleanisVirtual()Determines whether the address associated with this candidate belongs to a VPN interface. TransportgetTransport()Returns the Transport for this Candidate. TransportAddressgetRelatedAddress()Returns a TransportAddress related to this Candidate. StringtoString()Returns a String representation of this Candidate containing its TransportAddress, base, foundation, priority and whatever other properties may be relevant. StringtoShortString()Returns short String representation of this Candidate. booleancanReach(Candidate<out Object> dst)Determines whether this Candidate'sTransportAddress is theoretically usable for communication with that of dst. abstract booleanisDefault()Determines whether this Candidate is the default one for its parent component. abstract StringgetUfrag()Get the local ufrag. TransportAddressgetHostAddress()Returns this candidate host address. TransportAddressgetReflexiveAddress()Returns this candidate reflexive address. TransportAddressgetRelayedAddress()Returns this candidate relayed address. intcompareTo(T candidate)Compares this Candidate with the specified one based on their priority and returns a negative integer, zero, or a positive integer if this Candidate has a lower, equal, or greater priority than the second. -
-
Constructor Detail
-
Candidate
Candidate(TransportAddress transportAddress, Component parentComponent, CandidateType type, T relatedCandidate)
Creates a candidate for the specified transport address and properties.- Parameters:
transportAddress- the transport address that this candidate is encapsulating.parentComponent- the Component that this candidate belongs to.type- the CandidateType for this Candidate.relatedCandidate- The related candidate: - null for a host candidate, - the base address (host candidate) for a reflexive candidate, - the mapped address (the mapped address of the TURN allocate response) for a relayed candidate.
-
-
Method Detail
-
getTransportAddress
TransportAddress getTransportAddress()
Returns the transport address that this candidate is representing.
-
setCandidateType
void setCandidateType(CandidateType candidateType)
Sets the type of this candidate which should be an instance of the CandidateType enumeration.
- Parameters:
candidateType- a CandidateType instance indicating the type of this Candidate.
-
getFoundation
String getFoundation()
Returns a String containing the foundation of this Candidate. A foundation is an arbitrary String that is the same for candidates that have the same type, base IP address, transport protocol (UDP, TCP, etc.) and STUN or TURN server. If any of these are different then the foundation will be different. Two candidate pairs with the same foundation pairs are likely to have similar network characteristics. Typically, candidates for RTP and RTCP streams will share the same foundation. Foundations are used in the frozen algorithm.
-
setFoundation
void setFoundation(String foundation)
Sets this Candidate's foundation. A foundation is an arbitrary string that is always the same for candidates that have the same type, base IP address, protocol (UDP, TCP, etc.) and STUN or TURN server. If any of these are different then the foundation will be different. Two candidate pairs with the same foundation pairs are likely to have similar network characteristics. Foundations are used in the frozen algorithm.
- Parameters:
foundation- the foundation of this Candidate.
-
getBase
T getBase()
Returns this Candidate's base. The base of a server reflexive candidate is the host candidate from which it was derived. A host candidate is also said to have a base, equal to that candidate itself. Similarly, the base of a relayed candidate is that candidate itself.
-
setBase
void setBase(T base)
Sets this Candidate's base. The base of a server reflexive candidate is the host candidate from which it was derived. A host candidate is also said to have a base, equal to that candidate itself. Similarly, the base of a relayed candidate is that candidate itself.
- Parameters:
base- the base Candidate of this Candidate.
-
getPriority
long getPriority()
Returns the priority of this candidate. Priority is a unique priority number that MUST be a positive integer between 1 and (2**32 - 1). This priority will be set and used by ICE algorithms to determine the order of the connectivity checks and the relative preference for candidates.
-
setVirtual
void setVirtual(boolean virtual)
Specifies whether the address associated with this candidate belongs to a VPN interface. In many cases (e.g. when running on a 1.5 JVM) we won't be able to determine whether an interface is virtual or not. If we are however (that is when running a more recent JVM) we will reflect it in this property. Note that the isVirtual property is not really an ICE concept. The ICE specs only mention it and give basic guidelines as to how it should be handled so other implementations maybe dealing with it differently.
- Parameters:
virtual- true if we were able to determine that the address associated with this Candidate comes from a virtual interface and false if otherwise.
-
getParentComponent
Component getParentComponent()
Returns a reference to the Component that this candidate belongs to.
-
getStunServerAddress
TransportAddress getStunServerAddress()
Returns the address of the STUN server that was used to obtain this Candidate or null if this is not a server reflexive candidate.
-
setStunServerAddress
void setStunServerAddress(TransportAddress address)
Sets the address of the STUN server that was used to obtain this Candidate. Only makes sense if this is a relayed candidate.
- Parameters:
address- the address of the STUN server that was used to obtain this Candidate or null if this is not a server reflexive candidate.
-
getRelayServerAddress
TransportAddress getRelayServerAddress()
Returns the address of the relay server (i.e. TURN, Jingle Nodes, ...) that was used to obtain this Candidate or null if this is not a relayed candidate.
-
setRelayServerAddress
void setRelayServerAddress(TransportAddress address)
Sets the address of the relay server (i.e. TURN, Jingle Nodes, ...) that was used to obtain this Candidate. Only makes sense if this is a relayed candidate.
- Parameters:
address- the address of the relay server that was used to obtain this Candidate or null if this is not a relayed candidate.
-
getMappedAddress
TransportAddress getMappedAddress()
Returns the address that was returned to us a "mapped address" from a TURN or a STUN server in case this Candidate is relayed or reflexive and null otherwise. Note that the address returned by this method would be equal to the transport address for reflexive Candidates but not for relayed ones.
-
setMappedAddress
void setMappedAddress(TransportAddress address)
Sets the address that was returned to us a "mapped address" from a TURN or a STUN server in case this Candidate is relayed.
- Parameters:
address- the address that our TURN/STUN server returned as mapped if this is a relayed or a reflexive Candidate.
-
getRelatedCandidate
T getRelatedCandidate()
Returns the related candidate corresponding to the address given in parameter: - null for a host candidate, - the base address (host candidate) for a reflexive candidate, - the mapped address (the mapped address of the TURN allocate response) for a relayed candidate. - null for a peer reflexive candidate : there is no way to know the related address.
-
getTcpType
CandidateTcpType getTcpType()
Gets the CandidateTcpType for this Candidate.
-
setTcpType
void setTcpType(CandidateTcpType tcpType)
Sets the CandidateTcpType for this Candidate.
- Parameters:
tcpType- the CandidateTcpType to set.
-
getType
CandidateType getType()
Returns the type of this candidate which should be an instance of the CandidateType enumeration.
-
equals
boolean equals(Object obj)
Indicates whether some other Candidate is "equal to" this one. We consider candidates equal when they are redundant, i.e.
- Parameters:
obj- the reference object with which to compare.
-
hashCode
int hashCode()
-
computePriority
long computePriority()
Computes the priority for this Candidate based on the procedures defined in the ICE specification..
-
computeGTalkPriority
long computeGTalkPriority()
Computes the priority for this Candidate based on the procedures defined in the Google Talk specification.
-
computePriorityForType
long computePriorityForType(CandidateType candidateType)
Computes the priority this Candidate would have if it were of the specified candidateType and based on the procedures defined in the ICE specification. The reason we need this method in addition to the computePriority one is the need to be able to compute the priority of a peer reflexive candidate that we might learn during connectivity checks through this Candidate.
- Parameters:
candidateType- the hypothetical type that we'd like to use when computing the priority for this Candidate.
-
computeGTalkPriorityForType
long computeGTalkPriorityForType(CandidateType candidateType)
Computes the priority this Candidate would have if it were of the specified candidateType and based on the procedures defined in the Google Talk specification.
- Parameters:
candidateType- the hypothetical type that we'd like to use when computing the priority for this Candidate.
-
isVirtual
boolean isVirtual()
Determines whether the address associated with this candidate belongs to a VPN interface. In many cases (e.g. when running on a 1.5 JVM) we won't be able to determine whether an interface is virtual or not. If we are however (that is when running a more recent JVM) we will reflect it in this property. Note that the isVirtual property is not really an ICE concept. The ICE specs only mention it and give basic guidelines as to how it should be handled so other implementations maybe dealing with it differently.
-
getTransport
Transport getTransport()
Returns the Transport for this Candidate. This is a convenience method only and it is equivalent to retrieving the transport of this Candidate's transport address.
-
getRelatedAddress
TransportAddress getRelatedAddress()
Returns a TransportAddress related to this Candidate. Related addresses are present for server reflexive, peer reflexive and relayed candidates. If a candidate is server or peer reflexive, the related address is equal to the base of this Candidate. If the candidate is relayed, the returned address is equal to the mapped address. If the candidate is a host candidate then the method returns null.
-
toString
String toString()
Returns a String representation of this Candidate containing its TransportAddress, base, foundation, priority and whatever other properties may be relevant.
-
toShortString
String toShortString()
Returns short String representation of this Candidate.
-
canReach
boolean canReach(Candidate<out Object> dst)
Determines whether this Candidate'sTransportAddress is theoretically usable for communication with that of dst. Same as calling:
getTransportAddress().canReach(dst.getTransportAddress())
- Parameters:
dst- the Candidate that we'd like to check for reachability from this one.
-
isDefault
abstract boolean isDefault()
Determines whether this Candidate is the default one for its parent component.
-
getHostAddress
TransportAddress getHostAddress()
Returns this candidate host address.
-
getReflexiveAddress
TransportAddress getReflexiveAddress()
Returns this candidate reflexive address.
-
getRelayedAddress
TransportAddress getRelayedAddress()
Returns this candidate relayed address.
-
-
-
-