public abstract class AbstractTcpListener extends Object
acceptThread
and
readThread
. The 'accept' thread just accepts new Sockets
and passes them over to the 'read' thread. The 'read' thread reads a STUN
message from an accepted socket and, based on the STUN username, passes it
to the appropriate session.Modifier and Type | Class and Description |
---|---|
private class |
AbstractTcpListener.AcceptThread
A Thread which will accept new SocketChannels from all
ServerSocketChannels in
serverSocketChannels . |
private static class |
AbstractTcpListener.ChannelDesc
Contains a SocketChannel that ReadThread is reading
from.
|
protected static class |
AbstractTcpListener.PushBackIceSocketWrapper
An IceSocketWrapper implementation which allows a
DatagramPacket to be pushed back and received on the first call
to
AbstractTcpListener.PushBackIceSocketWrapper.receive(DatagramPacket) . |
private class |
AbstractTcpListener.ReadThread |
Modifier and Type | Field and Description |
---|---|
private AbstractTcpListener.AcceptThread |
acceptThread
The thread which accepts TCP connections from the sockets in
serverSocketChannels . |
private boolean |
close
Triggers the termination of the threads of this instance.
|
protected List<TransportAddress> |
localAddresses
The list of transport addresses which we have found to be listening on,
and which may be, for example, advertises as ICE candidates.
|
private static Logger |
logger
Our class logger.
|
private List<SocketChannel> |
newChannels
Channels pending to be added to the list that
readThread reads
from. |
private Selector |
readSelector
The Selector used by
readThread . |
private AbstractTcpListener.ReadThread |
readThread
The thread which reads from the already accepted sockets.
|
private List<ServerSocketChannel> |
serverSocketChannels
The list of ServerSocketChannels that we will accept
on.
|
protected Object |
sessionsSyncRoot
The object used to synchronize access to the collection of sessions that
the implementation of this class uses.
|
Constructor and Description |
---|
AbstractTcpListener(int port)
Initializes a new TcpHarvester, which is to
listen on port number port on all IP addresses on all available
interfaces.
|
AbstractTcpListener(int port,
List<NetworkInterface> interfaces)
Initializes a new TcpHarvester, which is to listen on port
number port on all the IP addresses on the specified
NetworkInterfaces.
|
AbstractTcpListener(List<TransportAddress> transportAddresses)
Initializes a new TcpHarvester, which is to listen on the
specified list of TransportAddresses.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
acceptSession(Socket socket,
String ufrag,
DatagramPacket pushback)
Accepts a session.
|
protected void |
addLocalAddresses(List<TransportAddress> transportAddresses)
Adds to
localAddresses those addresses from
transportAddresses which are found suitable for candidate
allocation. |
private void |
addSocketChannel(InetSocketAddress address)
Initializes one of the channels in
serverSocketChannels , |
void |
close()
Triggers the termination of the threads of this
MultiplexingTcpHarvester.
|
(package private) static void |
closeNoExceptions(Channel channel)
Closes a
Channel and swallows any IOException . |
private static List<TransportAddress> |
getLocalAddresses(int port,
List<NetworkInterface> interfaces)
Returns a list of all addresses on the interfaces in interfaces
which are found suitable for candidate allocations (are not loopback, are
up, and are allowed by the configuration).
|
protected void |
init()
Initializes
serverSocketChannels , creates and starts the threads
used by this instance. |
private static boolean |
isFirstDatagramPacket(DatagramPacket p)
Determines whether a specific
DatagramPacket is the first
expected (i.e. |
private static final Logger logger
private AbstractTcpListener.AcceptThread acceptThread
serverSocketChannels
.private boolean close
protected final List<TransportAddress> localAddresses
private final List<SocketChannel> newChannels
readThread
reads
from.private final Selector readSelector
readThread
.private AbstractTcpListener.ReadThread readThread
private final List<ServerSocketChannel> serverSocketChannels
protected final Object sessionsSyncRoot
public AbstractTcpListener(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 AbstractTcpListener(int port, List<NetworkInterface> interfaces) throws IOException
port
- the port to listen on.interfaces
- the interfaces to listen on.IOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values, or
if an I/O error occurs.public AbstractTcpListener(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.static void closeNoExceptions(Channel channel)
Channel
and swallows any IOException
.channel
- the Channel
to closeprivate static List<TransportAddress> getLocalAddresses(int port, List<NetworkInterface> interfaces) throws IOException
port
- the port to use.interfaces
- the list of interfaces to use.IOException
private static boolean isFirstDatagramPacket(DatagramPacket p)
DatagramPacket
is the first
expected (i.e. supported) to be received from an accepted
SocketChannel
by this AbstractTcpListener
. This is true
if it is contains the hard-coded SSL client handshake (
GoogleTurnSSLCandidateHarvester.SSL_CLIENT_HANDSHAKE
), or
a STUN Binding Request.p
- the DatagramPacket
to examinetrue
if p
looks like the first
DatagramPacket
expected to be received from an accepted
SocketChannel
by this TcpHarvester
;
otherwise, false
protected void addLocalAddresses(List<TransportAddress> transportAddresses) throws IOException
localAddresses
those addresses from
transportAddresses which are found suitable for candidate
allocation.transportAddresses
- the list of addresses to add.IOException
- when StackProperties.ALLOWED_ADDRESSES
or
StackProperties.BLOCKED_ADDRESSES
contains invalid values.public void close()
protected void init() throws IOException
serverSocketChannels
, creates and starts the threads
used by this instance.IOException
- if an I/O error occursprivate void addSocketChannel(InetSocketAddress address) throws IOException
serverSocketChannels
,IOException
- if an I/O error occursprotected abstract void acceptSession(Socket socket, String ufrag, DatagramPacket pushback) throws IOException, IllegalStateException
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.IllegalStateException
IOException
Copyright © 2018. All rights reserved.