public class TcpHarvester extends AbstractTcpListener implements CandidateHarvester
AbstractTcpListener
which acts as a
CandidateHarvester
. Sessions are accepted if their ufrag matches
a Component
registered with this harvester, and the known addresses
of AbstractTcpListener
are added as local host candidates (with type
"tcp" and tcptype "passive") when harvesting.AbstractTcpListener.PushBackIceSocketWrapper
Modifier and Type | Field and Description |
---|---|
private Map<String,WeakReference<Component>> |
components
Maps a local "ufrag" to the single Component instance with that
"ufrag".
|
private HarvestStatistics |
harvestStatistics
Manages statistics about harvesting time.
|
private static Logger |
logger
Our class logger.
|
private Map<InetAddress,InetAddress> |
mappedAddresses
Maps a public address to a local address.
|
private Set<Integer> |
mappedPorts
Sets of additional ports, for which server reflexive candidates will be
added.
|
private static int |
PURGE_INTERVAL
The constant which specifies how often to perform purging on
components . |
private int |
purgeCounter
A counter used to decide when to purge
components . |
private boolean |
ssltcp
Whether to advertise candidates with type "ssltcp" (if true) or "tcp"
(if false).
|
localAddresses, sessionsSyncRoot
Constructor and Description |
---|
TcpHarvester(int port)
Initializes a new TcpHarvester, which is to
listen on port number port on all IP addresses on all available
interfaces.
|
TcpHarvester(int port,
boolean ssltcp)
Initializes a new TcpHarvester, which is to
listen on port number port on all IP addresses on all available
interfaces.
|
TcpHarvester(int port,
List<NetworkInterface> interfaces,
boolean ssltcp)
Initializes a new TcpHarvester, which is to
listen on port number port on all the IP addresses on the
specified NetworkInterfaces.
|
TcpHarvester(List<TransportAddress> transportAddresses)
Initializes a new TcpHarvester, which is to
listen on the specified list of TransportAddresses.
|
TcpHarvester(List<TransportAddress> transportAddresses,
boolean ssltcp)
Initializes a new TcpHarvester, which is to
listen on the specified list of TransportAddresses.
|
Modifier and Type | Method and Description |
---|---|
protected void |
acceptSession(Socket socket,
String ufrag,
DatagramPacket pushback)
Accepts a session.
|
void |
addMappedAddress(InetAddress publicAddress,
InetAddress localAddress)
Adds a mapping between publicAddress and localAddress.
|
private void |
addMappedAddresses()
Adds the mapped addresses known from
MappingCandidateHarvesters . |
void |
addMappedPort(int port)
Adds port as an additional port.
|
private void |
addSocketToComponent(Socket socket,
Component component,
DatagramPacket datagramPacket)
Makes socket available to component and pushes back
datagramPacket into the STUN socket.
|
private List<LocalCandidate> |
createLocalCandidates(Component component)
Creates and returns the list of LocalCandidates which are to be
added by this TcpHarvester to a specific
Component.
|
private TcpHostCandidate |
findCandidate(Component component,
Socket socket)
Searches among the local candidates of Component for a
TcpHostCandidate with the same transport address as the
local transport address of socket.
|
private Component |
getComponent(String localUfrag)
Returns the Component instance, if any, for a given local
"ufrag".
|
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.
|
private void |
purgeComponents()
Removes entries from
components for which the
WeakReference has been cleared. |
addLocalAddresses, close, closeNoExceptions, init
private static final Logger logger
private static final int PURGE_INTERVAL
components
.private final Map<String,WeakReference<Component>> components
private final Map<InetAddress,InetAddress> mappedAddresses
private final Set<Integer> mappedPorts
private int purgeCounter
components
.private final boolean ssltcp
private HarvestStatistics harvestStatistics
public TcpHarvester(int port) throws IOException
port
- the port to listen on.IOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values, or
if an I/O error occurs.public TcpHarvester(int port, boolean ssltcp) throws IOException
port
- the port to listen on.ssltcp
- true to use ssltcp; otherwise, falseIOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values, or
if an I/O error occurs.public TcpHarvester(int port, List<NetworkInterface> interfaces, boolean ssltcp) throws IOException
port
- the port to listen on.interfaces
- the interfaces to listen on.ssltcp
- true to use ssltcp; otherwise, falseIOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values, or
if an I/O error occurs.public TcpHarvester(List<TransportAddress> transportAddresses) throws IOException
transportAddresses
- the transport addresses to listen on.IOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values, or
if an I/O error occurs.public TcpHarvester(List<TransportAddress> transportAddresses, boolean ssltcp) throws IOException
transportAddresses
- the transport addresses to listen on.ssltcp
- true to use ssltcp; otherwise, falseIOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values, or
if an I/O error occurs.private void addMappedAddresses()
MappingCandidateHarvesters
.public void addMappedAddress(InetAddress publicAddress, InetAddress localAddress)
publicAddress
- the public address.localAddress
- the local address.public void addMappedPort(int port)
port
- the port to add.private List<LocalCandidate> createLocalCandidates(Component component)
component
- the Component for which to create candidates.private Component getComponent(String localUfrag)
localUfrag
- the local "ufrag"public Collection<LocalCandidate> harvest(Component component)
Component.addLocalCandidate(LocalCandidate)
as soon as they are
discovered.
Saves a (weak) reference to Component, so that it can be
notified if/when a socket for one of it LocalCandidates is
accepted.
The method does not perform any network operations and should return quickly.
harvest
in interface CandidateHarvester
component
- the Component
that we'd like to gather candidate
addresses for.private void purgeComponents()
components
for which the
WeakReference has been cleared.protected void acceptSession(Socket socket, String ufrag, DatagramPacket pushback) throws IOException, IllegalStateException
acceptSession
in class AbstractTcpListener
socket
- the Socket
for the session.ufrag
- the local username fragment for the session.pushback
- the first "datagram" (RFC4571-framed), already read from
the socket's stream.IOException
IllegalStateException
private void addSocketToComponent(Socket socket, Component component, DatagramPacket datagramPacket) throws IOException, IllegalStateException
socket
- the Socket.component
- the Component.datagramPacket
- the DatagramPacket to push back.IllegalStateException
- if the ICE state is incorrect, or an
appropriate candidate could not be found.IOException
- if creation of some of the required socket instances
failed.private TcpHostCandidate findCandidate(Component component, Socket socket)
component
- the Component to search.socket
- the Socket to match the local transport
address of.public boolean isHostHarvester()
isHostHarvester
in interface CandidateHarvester
public HarvestStatistics getHarvestStatistics()
getHarvestStatistics
in interface CandidateHarvester
HarvestStatistics
describing this harvester's
harvests.Copyright © 2018. All rights reserved.