diff --git a/src/main/java/org/ice4j/ice/LocalCandidate.java b/src/main/java/org/ice4j/ice/LocalCandidate.java index 560938c..b362b0d 100644 --- a/src/main/java/org/ice4j/ice/LocalCandidate.java +++ b/src/main/java/org/ice4j/ice/LocalCandidate.java @@ -153,6 +153,21 @@ public abstract class LocalCandidate */ protected abstract IceSocketWrapper getCandidateIceSocketWrapper(); + /** + * @return the {@link IceSocketWrapper} instance for this candidate, + * associated with a particular remote address. + * @param remoteAddress the remote address for which to return an + * associated socket. + */ + protected IceSocketWrapper getCandidateIceSocketWrapper( + SocketAddress remoteAddress) + { + // The default implementation just refers to the method which doesn't + // involve a remove address. Extenders which support multiple instances + // mapped by remote address should override. + return getCandidateIceSocketWrapper(); + } + /** * Creates if necessary and returns a DatagramSocket that would * capture all STUN packets arriving on this candidate's socket. If the diff --git a/src/main/java/org/ice4j/ice/TcpHostCandidate.java b/src/main/java/org/ice4j/ice/TcpHostCandidate.java index 2b70642..7d3254f 100644 --- a/src/main/java/org/ice4j/ice/TcpHostCandidate.java +++ b/src/main/java/org/ice4j/ice/TcpHostCandidate.java @@ -54,6 +54,23 @@ public class TcpHostCandidate super(transportAddress, parentComponent); } + /** + * {@inheritDoc} + */ + @Override + protected IceSocketWrapper getCandidateIceSocketWrapper( + SocketAddress remoteAddress) + { + for (IceSocketWrapper socket : sockets) + { + if (socket.getTCPSocket().getRemoteSocketAddress() + .equals(remoteAddress)) + return socket; + } + + return null; + } + public void addSocket(IceSocketWrapper socket) { sockets.add(socket); diff --git a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java index c0df2e3..accb4a5 100644 --- a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java @@ -376,5 +376,15 @@ public class SinglePortUdpHarvester sockets.put(remoteAddress, socket); } } + /** + * {@inheritDoc} + */ + @Override + protected IceSocketWrapper getCandidateIceSocketWrapper( + SocketAddress remoteAddress) + { + return candidateSockets.get(remoteAddress); + } + } }