diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index ccf8372..f509ba4 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -1306,7 +1306,7 @@ public class Agent useCandidate = pair2.useCandidateReceived(); } - ufrag = ((RemoteCandidate)pair.getRemoteCandidate()).getUfrag(); + ufrag = pair.getRemoteCandidate().getUfrag(); } remoteCandidate = new RemoteCandidate( remoteAddress, @@ -2102,4 +2102,70 @@ public class Agent } logger.info("KeepAliveThread ends"); } + + /** + * Returns the selected pair for this Agent. + * + * @param streamName The stream name (AUDIO, VIDEO); + * + * @return The selected pair for this Agent. Null if no pair is selected. + */ + private CandidatePair getSelectedPair(String streamName) + { + List iceMediaStreams = this.getStreams(); + for(int i = 0; i < iceMediaStreams.size(); ++i) + { + if(iceMediaStreams.get(i).getName().equals(streamName)) + { + List components = + iceMediaStreams.get(i).getComponents(); + for(int j = 0; j < components.size(); ++j) + { + Component component = components.get(i); + if(component.getComponentID() + == org.ice4j.ice.Component.RTP) + { + return component.getSelectedPair(); + } + } + } + } + return null; + } + + /** + * Returns the selected local candidate for this Agent. + * + * @param streamName The stream name (AUDIO, VIDEO); + * + * @return The selected local candidate for this Agent. Null if no pair is + * selected. + */ + public LocalCandidate getSelectedLocalCandidate(String streamName) + { + CandidatePair candidatePair = this.getSelectedPair(streamName); + if(candidatePair != null) + { + return candidatePair.getLocalCandidate(); + } + return null; + } + + /** + * Returns the selected remote candidate for this Agent. + * + * @param streamName The stream name (AUDIO, VIDEO); + * + * @return The selected remote candidate for this Agent. Null if no pair is + * selected. + */ + public RemoteCandidate getSelectedRemoteCandidate(String streamName) + { + CandidatePair candidatePair = this.getSelectedPair(streamName); + if(candidatePair != null) + { + return candidatePair.getRemoteCandidate(); + } + return null; + } } diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java index f9e8569..fe83b6c 100644 --- a/src/org/ice4j/ice/CandidatePair.java +++ b/src/org/ice4j/ice/CandidatePair.java @@ -32,7 +32,7 @@ public class CandidatePair /** * The remote candidate of this pair. */ - private Candidate remoteCandidate; + private RemoteCandidate remoteCandidate; /** * Priority of the candidate-pair @@ -96,7 +96,7 @@ public class CandidatePair * @param remoteCandidate the remote candidate of the pair. */ public CandidatePair(LocalCandidate localCandidate, - Candidate remoteCandidate) + RemoteCandidate remoteCandidate) { this.localCandidate = localCandidate; @@ -150,7 +150,7 @@ public class CandidatePair * * @return the remote Candidate of this CandidatePair. */ - public Candidate getRemoteCandidate() + public RemoteCandidate getRemoteCandidate() { return remoteCandidate; } @@ -161,7 +161,7 @@ public class CandidatePair * @param remoteCnd the local Candidate of this * CandidatePair. */ - protected void setRemoteCandidate( Candidate remoteCnd) + protected void setRemoteCandidate(RemoteCandidate remoteCnd) { this.remoteCandidate = remoteCnd; } diff --git a/src/org/ice4j/ice/Component.java b/src/org/ice4j/ice/Component.java index 9feb902..b626569 100644 --- a/src/org/ice4j/ice/Component.java +++ b/src/org/ice4j/ice/Component.java @@ -78,14 +78,15 @@ public class Component /** * The list of candidates that the peer agent sent for this stream. */ - private List remoteCandidates = new LinkedList(); + private List remoteCandidates + = new LinkedList(); /** * The list of candidates that the peer agent sent for this stream after * connectivity establishment. */ - private List remoteUpdateCandidates = - new LinkedList(); + private List remoteUpdateCandidates = + new LinkedList(); /** * A Comparator that we use for sorting Candidates by @@ -208,7 +209,7 @@ public class Component * * @param candidate the Candidate instance to add. */ - public void addRemoteCandidate(Candidate candidate) + public void addRemoteCandidate(RemoteCandidate candidate) { logger.info("Add remote candidate for " + toShortString() + ": " + candidate.getTransportAddress()); @@ -225,7 +226,7 @@ public class Component * * @param candidate new Candidate to add. */ - public void addUpdateRemoteCandidate(Candidate candidate) + public void addUpdateRemoteCandidate(RemoteCandidate candidate) { logger.info("Update remote candidate for " + toShortString() + ": " + candidate.getTransportAddress()); @@ -356,7 +357,7 @@ public class Component continue; } - for(Candidate remoteCnd : remoteUpdateCandidates) + for(RemoteCandidate remoteCnd : remoteUpdateCandidates) { if(localCnd.canReach(remoteCnd)) { @@ -372,8 +373,8 @@ public class Component } } - CandidatePair pair = new CandidatePair(localCnd, - remoteCnd); + CandidatePair pair + = new CandidatePair(localCnd, remoteCnd); logger.info("new Pair added: " + pair.toShortString()); checkList.add(pair); } @@ -410,11 +411,11 @@ public class Component * @return Returns a copy of the list containing all remote candidates * currently registered in this Component. */ - public List getRemoteCandidates() + public List getRemoteCandidates() { synchronized(remoteCandidates) { - return new ArrayList(remoteCandidates); + return new ArrayList(remoteCandidates); } } @@ -437,7 +438,7 @@ public class Component * @param candidates the List of Candidates reported by * the remote agent for this component. */ - public void addRemoteCandidates(List candidates) + public void addRemoteCandidates(List candidates) { synchronized(remoteCandidates) { @@ -539,7 +540,7 @@ public class Component + getDefaultRemoteCandidate()); synchronized(remoteCandidates) { - for (Candidate cand : remoteCandidates) + for (RemoteCandidate cand : remoteCandidates) { buff.append("\n" + cand.toString()); } diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index 8197ca1..dbb4547 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -177,7 +177,7 @@ class ConnectivityCheckClient { /* Google Talk ICE dialect just need the username */ String localUserName = parentAgent.generateLocalUserName( - (RemoteCandidate)candidatePair.getRemoteCandidate(), + candidatePair.getRemoteCandidate(), candidatePair.getLocalCandidate()); UsernameAttribute unameAttr = @@ -531,7 +531,7 @@ class ConnectivityCheckClient .findLocalCandidate(mappedAddress); } - Candidate validRemoteCandidate = checkedPair.getRemoteCandidate(); + RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate(); // RFC 5245: The agent checks the mapped address from the STUN // response. If the transport address does not match any of the diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index dd802b8..e9a7f52 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -351,7 +351,7 @@ public class IceMediaStream final List checkList) { List localCnds = component.getLocalCandidates(); - List remoteCnds = component.getRemoteCandidates(); + List remoteCnds = component.getRemoteCandidates(); LocalCandidate upnpBase = null; for(LocalCandidate lc : localCnds) @@ -368,7 +368,7 @@ public class IceMediaStream if(localCnd == upnpBase) continue; - for(Candidate remoteCnd : remoteCnds) + for(RemoteCandidate remoteCnd : remoteCnds) { if(localCnd.canReach(remoteCnd)) { @@ -377,7 +377,7 @@ public class IceMediaStream CompatibilityMode.GTALK) { final LocalCandidate loc = localCnd; - final Candidate remot = remoteCnd; + final RemoteCandidate remot = remoteCnd; new Thread() { @@ -625,8 +625,7 @@ public class IceMediaStream for( CandidatePair pair : checkList) { LocalCandidate local = pair.getLocalCandidate(); - RemoteCandidate remote = - (RemoteCandidate)pair.getRemoteCandidate(); + RemoteCandidate remote = pair.getRemoteCandidate(); if(local.getUfrag().equals(remoteUFrag) && remote.getUfrag().equals(localUFrag)) diff --git a/src/org/ice4j/ice/LocalCandidate.java b/src/org/ice4j/ice/LocalCandidate.java index 2a81104..08f7465 100644 --- a/src/org/ice4j/ice/LocalCandidate.java +++ b/src/org/ice4j/ice/LocalCandidate.java @@ -348,4 +348,78 @@ public abstract class LocalCandidate { this.extendedType = extendedType; } + + /** + * Returns this candidate host address. + * + * @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(getBase() != null) + { + return getBase().getTransportAddress(); + } + return null; + default: //host candidate + return getTransportAddress(); + } + } + + /** + * Returns this candidate reflexive address. + * + * @return This candidate reflexive address. Null if this candidate + * does not use a peer/server reflexive address. + */ + public TransportAddress getReflexiveAddress() + { + 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; + } + } } diff --git a/src/org/ice4j/ice/RemoteCandidate.java b/src/org/ice4j/ice/RemoteCandidate.java index cfa6e04..949c0a9 100644 --- a/src/org/ice4j/ice/RemoteCandidate.java +++ b/src/org/ice4j/ice/RemoteCandidate.java @@ -43,13 +43,15 @@ public class RemoteCandidate * @param priority the RemoteCandidate's priority as reported * by the session description protocol. */ - public RemoteCandidate(TransportAddress transportAddress, - Component parentComponent, - CandidateType type, - String foundation, - long priority) + public RemoteCandidate( + TransportAddress transportAddress, + Component parentComponent, + CandidateType type, + String foundation, + long priority) { - this(transportAddress, + this( + transportAddress, parentComponent, type, foundation, @@ -72,12 +74,13 @@ public class RemoteCandidate * by the session description protocol. * @param ufrag ufrag for the remote candidate */ - public RemoteCandidate(TransportAddress transportAddress, - Component parentComponent, - CandidateType type, - String foundation, - long priority, - String ufrag) + public RemoteCandidate( + TransportAddress transportAddress, + Component parentComponent, + CandidateType type, + String foundation, + long priority, + String ufrag) { super(transportAddress, parentComponent, type); setFoundation(foundation); @@ -160,4 +163,78 @@ public class RemoteCandidate { return ufrag; } + + /** + * Returns this candidate host address. + * + * @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. + * + * @return This candidate reflexive address. Null if this candidate + * does not use a peer/server reflexive address. + */ + public TransportAddress getReflexiveAddress() + { + 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; + } + } }