- * 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. - * - * @return the TransportAddress that the remote party indicated - * as "related" for this Candidate or null if they didn't - * include it in SDP. - */ - @Override - public TransportAddress getRelatedAddress() - { - return raddr; - } - - /** - * Specifies the TransportAddress that the remote party indicated - * as "related" for this Candidate. - * - * @param relatedAddr the TransportAddress that the remote party - * indicated as "related" for this Candidate. - */ - public void setRelatedAddress(TransportAddress relatedAddr) - { - this.raddr = relatedAddr; - } - /** * Get the remote ufrag. * @@ -165,76 +138,28 @@ public class RemoteCandidate } /** - * Returns this candidate host address. + * Find the candidate corresponding to the address given in parameter. * - * @return This candidate host address. - */ - public TransportAddress getHostAddress() - { - switch (getType()) - { - case SERVER_REFLEXIVE_CANDIDATE: - if(getBase() != null) - { - return getBase().getTransportAddress(); - } - return null; - case PEER_REFLEXIVE_CANDIDATE: - if(getBase() != null) - { - return getBase().getTransportAddress(); - } - return null; - case RELAYED_CANDIDATE: - // If we are able to find the base address of the mapped - // address, it will be a great enhancement. - // i.e. but not working - // getMappedAddress().getBase().getTransportAddress(); - return null; - default: //host candidate - return getTransportAddress(); - } - } - - /** - * Returns this candidate reflexive address. + * @param 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. * - * @return This candidate reflexive address. Null if this candidate - * does not use a peer/server reflexive address. + * @return 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. */ - public TransportAddress getReflexiveAddress() + protected RemoteCandidate findRelatedCandidate( + TransportAddress relatedAddress) { - switch (getType()) - { - case SERVER_REFLEXIVE_CANDIDATE: - return getTransportAddress(); - case PEER_REFLEXIVE_CANDIDATE: - return getTransportAddress(); - case RELAYED_CANDIDATE: - return getMappedAddress(); - default: //host candidate - return null; - } - } - - /** - * Returns this candidate relayed address. - * - * @return This candidate relayed address. Null if this candidate - * does not use a relay. - */ - public TransportAddress getRelayedAddress() - { - switch (getType()) - { - case SERVER_REFLEXIVE_CANDIDATE: - return null; - case PEER_REFLEXIVE_CANDIDATE: - return null; - case RELAYED_CANDIDATE: - return getTransportAddress(); - default: //host candidate - return null; - } + return getParentComponent().findRemoteCandidate(relatedAddress); } } diff --git a/src/org/ice4j/ice/ServerReflexiveCandidate.java b/src/org/ice4j/ice/ServerReflexiveCandidate.java index ae73ed2..8adac57 100644 --- a/src/org/ice4j/ice/ServerReflexiveCandidate.java +++ b/src/org/ice4j/ice/ServerReflexiveCandidate.java @@ -52,14 +52,12 @@ public class ServerReflexiveCandidate TransportAddress stunSrvrAddr, CandidateExtendedType extendedType) { - super(address, - base.getParentComponent(), - CandidateType.SERVER_REFLEXIVE_CANDIDATE, - extendedType); - - setBase(base); - setStunServerAddress(stunSrvrAddr); - stunHarvest = null; + this( + address, + base, + stunSrvrAddr, + null, + extendedType); } /** @@ -87,7 +85,8 @@ public class ServerReflexiveCandidate super(address, base.getParentComponent(), CandidateType.SERVER_REFLEXIVE_CANDIDATE, - extendedType); + extendedType, + base); setBase(base); setStunServerAddress(stunSrvrAddr); diff --git a/src/org/ice4j/ice/UPNPCandidate.java b/src/org/ice4j/ice/UPNPCandidate.java index 1680234..10f49d7 100644 --- a/src/org/ice4j/ice/UPNPCandidate.java +++ b/src/org/ice4j/ice/UPNPCandidate.java @@ -44,7 +44,8 @@ public class UPNPCandidate transportAddress, parentComponent, CandidateType.SERVER_REFLEXIVE_CANDIDATE, - CandidateExtendedType.UPNP_CANDIDATE); + CandidateExtendedType.UPNP_CANDIDATE, + base); this.setBase(base); this.device = device; diff --git a/test/test/Ice.java b/test/test/Ice.java index fedfd7e..09bb83a 100644 --- a/test/test/Ice.java +++ b/test/test/Ice.java @@ -245,7 +245,8 @@ public class Ice localComponent, rCand.getType(), rCand.getFoundation(), - rCand.getPriority())); + rCand.getPriority(), + null)); } } diff --git a/test/test/SdpUtils.java b/test/test/SdpUtils.java index 939f188..31eacf6 100644 --- a/test/test/SdpUtils.java +++ b/test/test/SdpUtils.java @@ -229,13 +229,9 @@ public class SdpUtils if(component == null) return null; - RemoteCandidate cand = new RemoteCandidate(transAddr, component, type, - foundation, priority); - - component.addRemoteCandidate(cand); - // check if there's a related address property + RemoteCandidate relatedCandidate = null; if (tokenizer.countTokens() >= 4) { tokenizer.nextToken(); // skip the raddr element @@ -246,9 +242,14 @@ public class SdpUtils TransportAddress raddr = new TransportAddress( relatedAddr, relatedPort, Transport.UDP); - cand.setRelatedAddress(raddr); + relatedCandidate = component.findRemoteCandidate(raddr); } + RemoteCandidate cand = new RemoteCandidate(transAddr, component, type, + foundation, priority, relatedCandidate); + + component.addRemoteCandidate(cand); + return cand; }