feat: Adds accessors for candidatates' sockets when they have more than one.

This commit is contained in:
Boris Grozev 2016-12-06 11:57:32 -06:00
parent b4a5e2eb83
commit d5410b922b
3 changed files with 42 additions and 0 deletions

View File

@ -153,6 +153,21 @@ public abstract class LocalCandidate
*/ */
protected abstract IceSocketWrapper getCandidateIceSocketWrapper(); 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 <tt>DatagramSocket</tt> that would * Creates if necessary and returns a <tt>DatagramSocket</tt> that would
* capture all STUN packets arriving on this candidate's socket. If the * capture all STUN packets arriving on this candidate's socket. If the

View File

@ -54,6 +54,23 @@ public class TcpHostCandidate
super(transportAddress, parentComponent); 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) public void addSocket(IceSocketWrapper socket)
{ {
sockets.add(socket); sockets.add(socket);

View File

@ -376,5 +376,15 @@ public class SinglePortUdpHarvester
sockets.put(remoteAddress, socket); sockets.put(remoteAddress, socket);
} }
} }
/**
* {@inheritDoc}
*/
@Override
protected IceSocketWrapper getCandidateIceSocketWrapper(
SocketAddress remoteAddress)
{
return candidateSockets.get(remoteAddress);
}
} }
} }