public class SinglePortUdpHarvester extends AbstractUdpListener implements CandidateHarvester
AbstractUdpListener.thread
) which perpetually reads from the socket.
When harvest(org.ice4j.ice.Component)
is called, this harvester
creates and adds to the component a
SinglePortUdpHarvester.MyCandidate
instance,
and associates the component's local username fragment (ufrag) with this
candidate.
When a STUN Binding Request with a given ufrag is received, if the ufrag
matches one of the registered candidates, then a new socket is created, which
is to receive further packets from the remote address, and the socket is
added to the candidate.Modifier and Type | Class and Description |
---|---|
private class |
SinglePortUdpHarvester.MyCandidate
Implements a Candidate for the purposes of this
SinglePortUdpHarvester.
|
AbstractUdpListener.Buffer, AbstractUdpListener.MySocket
Modifier and Type | Field and Description |
---|---|
private Map<String,SinglePortUdpHarvester.MyCandidate> |
candidates
The map which keeps all currently active Candidates created by
this harvester.
|
private HarvestStatistics |
harvestStatistics
Manages statistics about harvesting time.
|
private static Logger |
logger
Our class logger.
|
localAddress, SO_RCVBUF_PNAME
Constructor and Description |
---|
SinglePortUdpHarvester(TransportAddress localAddress)
Initializes a new SinglePortUdpHarvester instance which is to
bind on the specified local address.
|
Modifier and Type | Method and Description |
---|---|
static List<SinglePortUdpHarvester> |
createHarvesters(int port)
Creates a new SinglePortUdpHarvester instance for each allowed
IP address found on each allowed network interface, with the given port.
|
HarvestStatistics |
getHarvestStatistics()
Returns the statistics describing how well the various harvests of this
harvester went.
|
Collection<LocalCandidate> |
harvest(Component component)
Gathers all candidate addresses of the type that this
CandidateHarvester supports.
|
boolean |
isHostHarvester()
Returns true if this CandidateHarvester is to be
considered a harvester for host candidates.
|
protected void |
maybeAcceptNewSession(AbstractUdpListener.Buffer buf,
InetSocketAddress remoteAddress,
String ufrag)
Handles the reception of a STUN Binding Request with a valid USERNAME
attribute, from a "new" remote address (one which is not in
AbstractUdpListener.sockets ). |
addSocket, close, getAllowedAddresses, getUfrag
private static final Logger logger
private final Map<String,SinglePortUdpHarvester.MyCandidate> candidates
private HarvestStatistics harvestStatistics
public SinglePortUdpHarvester(TransportAddress localAddress) throws IOException
localAddress
- the address to bind to.IOException
- if initialization fails.public static List<SinglePortUdpHarvester> createHarvesters(int port)
port
- the UDP port number to use.public HarvestStatistics getHarvestStatistics()
getHarvestStatistics
in interface CandidateHarvester
HarvestStatistics
describing this harvester's
harvests.protected void maybeAcceptNewSession(AbstractUdpListener.Buffer buf, InetSocketAddress remoteAddress, String ufrag)
AbstractUdpListener.sockets
).
Implementations may choose to e.g. create a socket and pass it to their
ICE stack.
Note that this is meant to only be executed by
AbstractUdpListener
's read thread, and should not be called from
implementing classes.
Looks for an ICE candidate registered with this harvester, which has a
local ufrag of ufrag
, and if one is found it accepts the new
socket and adds it to the candidate.maybeAcceptNewSession
in class AbstractUdpListener
buf
- the UDP payload of the first datagram received on the newly
accepted socket.remoteAddress
- the remote address from which the datagram was
received.ufrag
- the local ICE username fragment of the received STUN Binding
Request.public Collection<LocalCandidate> harvest(Component component)
Component.addLocalCandidate(LocalCandidate)
as soon as they are
discovered.harvest
in interface CandidateHarvester
component
- the Component
that we'd like to gather candidate
addresses for.public boolean isHostHarvester()
isHostHarvester
in interface CandidateHarvester
Copyright © 2018. All rights reserved.