Supports server reflexive candidates for single-port UDP, and

automatically detects mappings for EC2.
This commit is contained in:
boris 2015-06-02 12:22:23 +00:00
parent 471f91b364
commit 1f4aeebe38

View File

@ -113,11 +113,20 @@ public class SinglePortUdpHarvester
logger.info("Failed to get network interfaces: " + se); logger.info("Failed to get network interfaces: " + se);
} }
TransportAddress ec2Mask = AwsCandidateHarvester.getMask();
for (TransportAddress address : addresses) for (TransportAddress address : addresses)
{ {
TransportAddress publicAddress = null;
if (ec2Mask != null
&& ec2Mask.getAddress().equals(address.getAddress()))
{
publicAddress = AwsCandidateHarvester.getFace();
}
try try
{ {
harvesters.add(new SinglePortUdpHarvester(address)); harvesters.add(
new SinglePortUdpHarvester(address, publicAddress));
} }
catch (IOException ioe) catch (IOException ioe)
{ {
@ -163,6 +172,11 @@ public class SinglePortUdpHarvester
*/ */
private final DatagramSocket socket; private final DatagramSocket socket;
/**
* The public address that this harvester will use for reflexive candidates.
*/
private TransportAddress publicAddress = null;
/** /**
* The thread reading from {@link #socket}. * The thread reading from {@link #socket}.
*/ */
@ -172,9 +186,12 @@ public class SinglePortUdpHarvester
* Initializes a new <tt>SinglePortUdpHarvester</tt> instance which is to * Initializes a new <tt>SinglePortUdpHarvester</tt> instance which is to
* bind on the specified local address. * bind on the specified local address.
* @param localAddress the address to bind to. * @param localAddress the address to bind to.
* @param publicAddress the public address that this harvester will use for
* reflexive candidates.
* @throws IOException if initialization fails. * @throws IOException if initialization fails.
*/ */
public SinglePortUdpHarvester(TransportAddress localAddress) public SinglePortUdpHarvester(TransportAddress localAddress,
TransportAddress publicAddress)
throws IOException throws IOException
{ {
this.localAddress = localAddress; this.localAddress = localAddress;
@ -196,6 +213,18 @@ public class SinglePortUdpHarvester
thread.start(); thread.start();
} }
/**
* Initializes a new <tt>SinglePortUdpHarvester</tt> instance which is to
* bind on the specified local address.
* @param localAddress the address to bind to.
* @throws IOException if initialization fails.
*/
public SinglePortUdpHarvester(TransportAddress localAddress)
throws IOException
{
this(localAddress, null);
}
/** /**
* Perpetually reads datagrams from {@link #socket} and handles them * Perpetually reads datagrams from {@link #socket} and handles them
* accordingly. * accordingly.
@ -391,6 +420,17 @@ public class SinglePortUdpHarvester
candidates.put(ufrag, candidate); candidates.put(ufrag, candidate);
component.addLocalCandidate(candidate); component.addLocalCandidate(candidate);
if (publicAddress != null)
{
ServerReflexiveCandidate mappedCandidate
= new ServerReflexiveCandidate(
publicAddress,
candidate,
candidate.getStunServerAddress(),
CandidateExtendedType.STATICALLY_MAPPED_CANDIDATE);
component.addLocalCandidate(mappedCandidate);
}
return new ArrayList<LocalCandidate>(Arrays.asList(candidate)); return new ArrayList<LocalCandidate>(Arrays.asList(candidate));
} }