public abstract class Candidate<T extends Candidate<?>> extends Object implements Comparable<T>
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.
Modifier and Type | Field and Description |
---|---|
private T |
base
The base of a server reflexive candidate is the host candidate
from which it was derived.
|
private CandidateType |
candidateType
The type of this candidate.
|
private String |
foundation
An arbitrary string that is the same for two candidates
that have the same type, base IP address, protocol (UDP, TCP,
etc.) and STUN or TURN server.
|
private TransportAddress |
mappedAddress
The address that our TURN/STUN server returned as mapped if this is a
relayed or a reflexive Candidate.
|
static int |
MAX_LOCAL_PREFERENCE
The maximum value for a candidate's local preference.
|
static int |
MAX_TYPE_PREFERENCE
The maximum value for a candidate's type preference.
|
static int |
MIN_LOCAL_PREFERENCE
The minimum value for a candidate's local preference.
|
static int |
MIN_TYPE_PREFERENCE
The minimum value for a candidate's type preference.
|
private Component |
parentComponent
The component that this candidate was created for.
|
protected long |
priority
A unique priority number that MUST be a positive integer between 1 and
(2**32 - 1).
|
private T |
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.
|
private TransportAddress |
relayServerAddress
The address of the relay server (i.e.
|
private TransportAddress |
stunServerAddress
The address of the STUN server that was used to obtain this
Candidate.
|
private CandidateTcpType |
tcpType
The CandidateTcpType for this Candidate.
|
private TransportAddress |
transportAddress
The transport address represented by this candidate.
|
private boolean |
virtual
Specifies whether the address associated with this candidate belongs to
a VPN interface.
|
Constructor and Description |
---|
Candidate(TransportAddress transportAddress,
Component parentComponent,
CandidateType type,
T relatedCandidate)
Creates a candidate for the specified transport address and properties.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canReach(Candidate<?> dst)
Determines whether this Candidate'sTransportAddress is
theoretically usable for communication with that of dst.
|
int |
compareTo(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.
|
long |
computeGTalkPriority()
Computes the priority for this Candidate based on the procedures
defined in the Google Talk specification.
|
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.
|
long |
computePriority()
Computes the priority for this Candidate based on the procedures
defined in the ICE specification..
|
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.
|
boolean |
equals(Object obj)
Indicates whether some other Candidate is "equal to" this one.
|
protected abstract T |
findRelatedCandidate(TransportAddress relatedAddress)
Find the candidate corresponding to the address given in parameter.
|
T |
getBase()
Returns this Candidate's base.
|
protected int |
getDefaultPreference()
Returns an integer indicating the preference that this Candidate
should be considered with for becoming a default candidate.
|
String |
getFoundation()
Returns a String containing the foundation of this
Candidate.
|
TransportAddress |
getHostAddress()
Returns this candidate host address.
|
private int |
getLocalPreference()
Calculates and returns the local preference for this Candidate
|
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.
|
Component |
getParentComponent()
Returns a reference to the Component that this candidate belongs
to.
|
long |
getPriority()
Returns the priority of this candidate.
|
TransportAddress |
getReflexiveAddress()
Returns this candidate reflexive address.
|
TransportAddress |
getRelatedAddress()
Returns a TransportAddress related to this Candidate.
|
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.
|
TransportAddress |
getRelayedAddress()
Returns this candidate relayed address.
|
TransportAddress |
getRelayServerAddress()
Returns the address of the relay server (i.e.
|
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.
|
CandidateTcpType |
getTcpType()
Gets the CandidateTcpType for this Candidate.
|
Transport |
getTransport()
Returns the Transport for this Candidate.
|
TransportAddress |
getTransportAddress()
Returns the transport address that this candidate is representing.
|
CandidateType |
getType()
Returns the type of this candidate which should be an instance of the
CandidateType enumeration. |
private static int |
getTypePreference(CandidateType candidateType)
Returns the type preference that should be used when computing priority
for Candidates of the specified candidateType.
|
abstract String |
getUfrag()
Get the local ufrag.
|
int |
hashCode() |
abstract boolean |
isDefault()
Determines whether this Candidate is the default one for its
parent component.
|
boolean |
isVirtual()
Determines whether the address associated with this candidate belongs to
a VPN interface.
|
void |
setBase(T base)
Sets this Candidate's base.
|
void |
setCandidateType(CandidateType candidateType)
Sets the type of this candidate which should be an instance of the
CandidateType enumeration. |
void |
setFoundation(String foundation)
Sets this Candidate's foundation.
|
protected 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.
|
protected void |
setRelayServerAddress(TransportAddress address)
Sets the address of the relay server (i.e.
|
protected void |
setStunServerAddress(TransportAddress address)
Sets the address of the STUN server that was used to obtain this
Candidate.
|
void |
setTcpType(CandidateTcpType tcpType)
Sets the CandidateTcpType for this Candidate.
|
void |
setVirtual(boolean virtual)
Specifies whether the address associated with this candidate belongs to
a VPN interface.
|
String |
toShortString()
Returns short String representation of this Candidate.
|
String |
toString()
Returns a String representation of this Candidate
containing its TransportAddress, base, foundation, priority and
whatever other properties may be relevant.
|
public static final int MAX_TYPE_PREFERENCE
public static final int MIN_TYPE_PREFERENCE
public static final int MAX_LOCAL_PREFERENCE
public static final int MIN_LOCAL_PREFERENCE
private final TransportAddress transportAddress
private CandidateType candidateType
private String foundation
private T extends Candidate<?> base
protected long priority
private boolean virtual
private final Component parentComponent
private TransportAddress stunServerAddress
private TransportAddress relayServerAddress
private TransportAddress mappedAddress
private T extends Candidate<?> relatedCandidate
private CandidateTcpType tcpType
public Candidate(TransportAddress transportAddress, Component parentComponent, CandidateType type, T relatedCandidate)
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.
- null for a peer reflexive candidate : there is no way to know the
related address.public CandidateType getType()
CandidateType
enumeration.public void setCandidateType(CandidateType candidateType)
CandidateType
enumeration.candidateType
- a CandidateType instance indicating the
type of this Candidate.public String getFoundation()
public void setFoundation(String foundation)
foundation
- the foundation of this Candidate.public T getBase()
public void setBase(T base)
base
- the base Candidate of this Candidate.public long getPriority()
public TransportAddress getTransportAddress()
public boolean equals(Object obj) throws NullPointerException
equals
in class Object
obj
- the reference object with which to compare.
true
if this Candidate is equal to the
obj argument; false
otherwise.NullPointerException
- if obj is null;public Component getParentComponent()
public long computePriority()
public long computeGTalkPriority()
public long computePriorityForType(CandidateType candidateType)
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.candidateType
- the hypothetical type that we'd like to use when
computing the priority for this Candidate.public long computeGTalkPriorityForType(CandidateType candidateType)
candidateType
- the hypothetical type that we'd like to use when
computing the priority for this Candidate.private static int getTypePreference(CandidateType candidateType)
candidateType
- the CandidateType that we'd like to obtain
a preference for.private int getLocalPreference()
The local preference MUST be an integer from 0 to 65535 inclusive. It represents a preference for the particular IP address from which the candidate was obtained, in cases where an agent is multihomed. 65535 represents the highest preference, and a zero, the lowest. When there is only a single IP address, this value SHOULD be set to 65535. More generally, if there are multiple candidates for a particular component for a particular media stream which have the same type, the local preference MUST be unique for each one. In this specification, this only happens for multihomed hosts. If a host is multihomed because it is dual stacked, the local preference SHOULD be set equal to the precedence value for IP addresses described in RFC 3484.
public boolean isVirtual()
public void setVirtual(boolean virtual)
virtual
- true if we were able to determine that the
address associated with this Candidate comes from a virtual
interface and false if otherwise.public TransportAddress getStunServerAddress()
protected void setStunServerAddress(TransportAddress address)
address
- the address of the STUN server that was used to obtain
this Candidate or null if this is not a server
reflexive candidate.public TransportAddress getRelayServerAddress()
protected void setRelayServerAddress(TransportAddress address)
address
- the address of the relay server that was used to obtain
this Candidate or null if this is not a relayed
candidate.public TransportAddress getMappedAddress()
protected void setMappedAddress(TransportAddress address)
address
- the address that our TURN/STUN server returned as mapped
if this is a relayed or a reflexive Candidate.public Transport getTransport()
public TransportAddress getRelatedAddress()
protected abstract T findRelatedCandidate(TransportAddress relatedAddress)
relatedAddress
- The related address:
- 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.public String toString()
public String toShortString()
protected int getDefaultPreference()
public boolean canReach(Candidate<?> dst)
getTransportAddress().canReach(dst.getTransportAddress())
dst
- the Candidate that we'd like to check for
reachability from this one.Candidate
shares the same
Transport and family as dst or false
otherwise.public abstract boolean isDefault()
public abstract String getUfrag()
public TransportAddress getHostAddress()
public TransportAddress getReflexiveAddress()
public TransportAddress getRelayedAddress()
public T getRelatedCandidate()
public int compareTo(T candidate)
compareTo
in interface Comparable<T extends Candidate<?>>
candidate
- the second Candidate to compare.public CandidateTcpType getTcpType()
public void setTcpType(CandidateTcpType tcpType)
tcpType
- the CandidateTcpType to set.Copyright © 2018. All rights reserved.