public class RelayedCandidateDatagramSocket extends DatagramSocket implements MessageEventHandler
Modifier and Type | Class and Description |
---|---|
private class |
RelayedCandidateDatagramSocket.Channel
Represents a channel which relays data sent through this
RelayedCandidateDatagramSocket to a specific
TransportAddress via the TURN server associated with this
RelayedCandidateDatagramSocket.
|
Modifier and Type | Field and Description |
---|---|
private static char |
CHANNEL_NUMBER_NOT_SPECIFIED
The constant which represents a channel number value signaling that no
channel number has been explicitly specified.
|
private static int |
CHANNELDATA_CHANNELNUMBER_LENGTH
The length in bytes of the Channel Number field of a TURN ChannelData
message.
|
private static int |
CHANNELDATA_LENGTH_LENGTH
The length in bytes of the Length field of a TURN ChannelData message.
|
private DatagramSocket |
channelDataSocket
The DatagramSocket through which this
RelayedCandidateDatagramSocket actually sends and receives the
data it has been asked to
send(DatagramPacket) and
receive(DatagramPacket) . |
private List<RelayedCandidateDatagramSocket.Channel> |
channels
The list of per-peer Channels through which this
RelayedCandidateDatagramSockets relays data send to it to
peer TransportAddresses.
|
private boolean |
closed
The indicator which determines whether this instance has started
executing or has executed its
close() method. |
private static DatagramPacketFilter |
connectivityCheckRecognizer
The DatagramPacketFilter which is able to determine whether a
specific DatagramPacket sent through a
RelayedCandidateDatagramSocket is part of the ICE connectivity
checks.
|
private static Logger |
logger
The Logger used by the RelayedCandidateDatagramSocket
class and its instances for logging output.
|
private static char |
MAX_CHANNEL_NUMBER
The maximum channel number which is valid for TURN ChannelBind
Request.
|
private static char |
MIN_CHANNEL_NUMBER
The minimum channel number which is valid for TURN ChannelBind
Requests.
|
private char |
nextChannelNumber
The next free channel number to be returned by
getNextChannelNumber() and marked as non-free. |
private List<DatagramPacket> |
packetsToReceive
The DatagramPackets which are to be received through this
DatagramSocket upon calls to its
receive(DatagramPacket) method. |
private List<DatagramPacket> |
packetsToSend
The DatagramSockets which have been sent through this
DatagramSocket using its
send(DatagramPacket) method
and which are to be relayed through its associated TURN server in the
form of Send indications. |
private static long |
PERMISSION_LIFETIME
The lifetime in milliseconds of a TURN permission created using a
CreatePermission request.
|
private static long |
PERMISSION_LIFETIME_LEEWAY
The time in milliseconds before a TURN permission expires that a
RelayedCandidateDatagramSocket is to try to reinstall it.
|
private Thread |
receiveChannelDataThread
The Thread which receives DatagramPackets from
channelDataSocket and queues them in packetsToReceive . |
private RelayedCandidate |
relayedCandidate
The RelayedCandidate which uses this instance as the value of
its socket property.
|
private Thread |
sendThread
The Thread which is to send the
packetsToSend to the
associated TURN server. |
private TurnCandidateHarvest |
turnCandidateHarvest
The TurnCandidateHarvest which has harvested
relayedCandidate . |
Constructor and Description |
---|
RelayedCandidateDatagramSocket(RelayedCandidate relayedCandidate,
TurnCandidateHarvest turnCandidateHarvest)
Initializes a new RelayedCandidateDatagramSocket instance which
is to be the socket of a specific RelayedCandidate
harvested by a specific TurnCandidateHarvest.
|
Modifier and Type | Method and Description |
---|---|
private boolean |
channelDataSocketAccept(DatagramPacket p)
Determines whether a specific DatagramPacket is accepted by
channelDataSocket (i.e. |
private boolean |
channelDataSocketAcceptMethod(char method)
Determines whether
channelDataSocket accepts
DatagramPackets which represent STUN messages with a specific
method. |
void |
close()
Closes this datagram socket.
|
private void |
createReceiveChannelDataThread()
Creates
receiveChannelDataThread which is to receive
DatagramPackets from channelDataSocket and queue them
in packetsToReceive . |
private void |
createSendThread()
Creates
sendThread which is to send packetsToSend to
the associated TURN server. |
InetAddress |
getLocalAddress()
Gets the local address to which the socket is bound.
|
int |
getLocalPort()
Returns the port number on the local host to which this socket is bound.
|
InetSocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or
null if it is not bound yet.
|
private char |
getNextChannelNumber()
Gets the next free channel number to be allocated to a Channel
and marked as non-free.
|
RelayedCandidate |
getRelayedCandidate()
Gets the RelayedCandidate which uses this instance as the value
of its socket property.
|
void |
handleMessageEvent(StunMessageEvent e)
Notifies this MessageEventHandler that a specific STUN message
has been received, parsed and is ready for delivery.
|
boolean |
processErrorOrFailure(Response response,
Request request)
Notifies this RelayedCandidateDatagramSocket that a specific
Request it has sent has either failed or received a STUN error
Response.
|
void |
processSuccess(Response response,
Request request)
Notifies this RelayedCandidateDatagramSocket that a specific
Request it has sent has received a STUN success
Response.
|
void |
receive(DatagramPacket p)
Receives a datagram packet from this socket.
|
private void |
runInReceiveChannelDataThread()
Runs in
receiveChannelDataThread to receive
DatagramPackets from channelDataSocket and queue them
in packetsToReceive . |
private void |
runInSendThread()
Runs in
sendThread to send packetsToSend to the
associated TURN server. |
void |
send(DatagramPacket p)
Sends a datagram packet from this socket.
|
private void |
setChannelBound(Request request,
boolean bound)
Sets the bound property of a Channel the installation
of which has been attempted by sending a specific Request.
|
private void |
setChannelNumberIsConfirmed(Request request,
boolean channelNumberIsConfirmed)
Sets the channelNumberIsConfirmed property of a Channel
which has attempted to allocate a specific channel number by sending a
specific ChannelBind Request.
|
bind, connect, connect, disconnect, getBroadcast, getChannel, getInetAddress, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoTimeout, getTrafficClass, isBound, isClosed, isConnected, setBroadcast, setDatagramSocketImplFactory, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSoTimeout, setTrafficClass
private static final Logger logger
private static final char CHANNEL_NUMBER_NOT_SPECIFIED
private static final int CHANNELDATA_CHANNELNUMBER_LENGTH
private static final int CHANNELDATA_LENGTH_LENGTH
private static final char MAX_CHANNEL_NUMBER
private static final char MIN_CHANNEL_NUMBER
private static final long PERMISSION_LIFETIME
private static final long PERMISSION_LIFETIME_LEEWAY
private final DatagramSocket channelDataSocket
send(DatagramPacket)
and
receive(DatagramPacket)
. Since data can be exchanged with a TURN
server using STUN messages (i.e. Send and Data indications),
RelayedCandidateDatagramSocket may send and receive data using
the associated StunStack and not channelDataSocket.
However, using channelDataSocket is supposed to be more
efficient than using StunStack.private final List<RelayedCandidateDatagramSocket.Channel> channels
private boolean closed
close()
method.private static final DatagramPacketFilter connectivityCheckRecognizer
private char nextChannelNumber
getNextChannelNumber()
and marked as non-free.private final List<DatagramPacket> packetsToReceive
receive(DatagramPacket)
method. They have been received from the
TURN server in the form of Data indications.private final List<DatagramPacket> packetsToSend
send(DatagramPacket)
method
and which are to be relayed through its associated TURN server in the
form of Send indications.private Thread receiveChannelDataThread
channelDataSocket
and queues them in packetsToReceive
.private final RelayedCandidate relayedCandidate
private Thread sendThread
packetsToSend
to the
associated TURN server.private final TurnCandidateHarvest turnCandidateHarvest
relayedCandidate
.public RelayedCandidateDatagramSocket(RelayedCandidate relayedCandidate, TurnCandidateHarvest turnCandidateHarvest) throws SocketException
relayedCandidate
- the RelayedCandidate which is to use the
new instance as the value of its socket propertyturnCandidateHarvest
- the TurnCandidateHarvest which has
harvested relayedCandidateSocketException
- if anything goes wrong while initializing the new
RelayedCandidateDatagramSocket instanceprivate boolean channelDataSocketAccept(DatagramPacket p)
channelDataSocket
(i.e. whether channelDataSocket
understands p and p is meant to be received by
channelDataSocket).p
- the DatagramPacket which is to be checked whether it is
accepted by channelDataSocketprivate boolean channelDataSocketAcceptMethod(char method)
channelDataSocket
accepts
DatagramPackets which represent STUN messages with a specific
method.method
- the method of the STUN messages represented in
DatagramPackets which is accepted by channelDataSocketpublic void close()
close
in interface Closeable
close
in interface AutoCloseable
close
in class DatagramSocket
DatagramSocket.close()
private void createReceiveChannelDataThread()
receiveChannelDataThread
which is to receive
DatagramPackets from channelDataSocket
and queue them
in packetsToReceive
.private void createSendThread()
sendThread
which is to send packetsToSend
to
the associated TURN server.public InetAddress getLocalAddress()
If there is a security manager, its checkConnect method is first called with the host address and -1 as its arguments to see if the operation is allowed.
getLocalAddress
in class DatagramSocket
getLocalSocketAddress()
,
DatagramSocket.getLocalAddress()
public int getLocalPort()
getLocalPort
in class DatagramSocket
getLocalSocketAddress()
,
DatagramSocket.getLocalPort()
public InetSocketAddress getLocalSocketAddress()
getLocalSocketAddress
in class DatagramSocket
DatagramSocket.getLocalSocketAddress()
private char getNextChannelNumber()
public final RelayedCandidate getRelayedCandidate()
public void handleMessageEvent(StunMessageEvent e)
handleMessageEvent
in interface MessageEventHandler
e
- a StunMessageEvent which encapsulates the received STUN
messagepublic boolean processErrorOrFailure(Response response, Request request)
response
- the Response which responds to requestrequest
- the Request sent by this instance to which
response respondspublic void processSuccess(Response response, Request request)
response
- the Response which responds to requestrequest
- the Request sent by this instance to which
response respondspublic void receive(DatagramPacket p) throws IOException
receive
in class DatagramSocket
p
- the DatagramPacket into which to place the incoming
dataIOException
- if an I/O error occursDatagramSocket.receive(DatagramPacket)
private void runInReceiveChannelDataThread() throws SocketException
receiveChannelDataThread
to receive
DatagramPackets from channelDataSocket
and queue them
in packetsToReceive
.SocketException
- if anything goes wrong while receiving
DatagramPackets from channelDataSocket
and
receiveChannelDataThread
is to no longer existprivate void runInSendThread()
sendThread
to send packetsToSend
to the
associated TURN server.public void send(DatagramPacket p) throws IOException
send
in class DatagramSocket
p
- the DatagramPacket to be sentIOException
- if an I/O error occursDatagramSocket.send(DatagramPacket)
private void setChannelBound(Request request, boolean bound)
request
- the Request which has been attempted in order to
install a Channelbound
- true if the bound property of the
Channel is to be set to true; otherwise, falseprivate void setChannelNumberIsConfirmed(Request request, boolean channelNumberIsConfirmed)
request
- the Request which has been sent to allocate a
specific channel number for a ChannelchannelNumberIsConfirmed
- true if the channel number has
been successfully allocated; otherwise, falseCopyright © 2018. All rights reserved.