feat: Adds candidates' sockets to the component's merging socket.
This commit is contained in:
parent
c378329b8c
commit
82544254c4
@ -194,7 +194,7 @@ public class GoogleRelayedCandidate
|
|||||||
* @see LocalCandidate#getCandidateIceSocketWrapper()
|
* @see LocalCandidate#getCandidateIceSocketWrapper()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
public synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -129,7 +129,7 @@ public class RelayedCandidate
|
|||||||
* <tt>Candidate</tt>
|
* <tt>Candidate</tt>
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
public synchronized IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
if (socket == null)
|
if (socket == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public class UPNPCandidate
|
|||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected IceSocketWrapper getCandidateIceSocketWrapper()
|
public IceSocketWrapper getCandidateIceSocketWrapper()
|
||||||
{
|
{
|
||||||
return getBase().getCandidateIceSocketWrapper();
|
return getBase().getCandidateIceSocketWrapper();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -133,6 +133,14 @@ public class GoogleTurnCandidateHarvest
|
|||||||
harvester.getStunStack().addSocket(
|
harvester.getStunStack().addSocket(
|
||||||
relayedCandidate.getStunSocket(null));
|
relayedCandidate.getStunSocket(null));
|
||||||
|
|
||||||
|
// Make the relayed candidate's socket available for reading
|
||||||
|
// by the component.
|
||||||
|
IceSocketWrapper candidateSocket
|
||||||
|
= relayedCandidate.getCandidateIceSocketWrapper();
|
||||||
|
|
||||||
|
Component component = relayedCandidate.getParentComponent();
|
||||||
|
component.getSocket().add(candidateSocket);
|
||||||
|
|
||||||
addCandidate(relayedCandidate);
|
addCandidate(relayedCandidate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,7 +121,7 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the host candidate.
|
* Returns the host candidate.
|
||||||
* For UDP it simply returns the candidate passed as paramter
|
* For UDP it simply returns the candidate passed as parameter
|
||||||
*
|
*
|
||||||
* However for TCP, we cannot return the same hostCandidate because in Java
|
* However for TCP, we cannot return the same hostCandidate because in Java
|
||||||
* a "server" socket cannot connect to a destination with the same local
|
* a "server" socket cannot connect to a destination with the same local
|
||||||
@ -146,11 +146,11 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
if(sslHandshake(inputStream, outputStream))
|
if(sslHandshake(inputStream, outputStream))
|
||||||
{
|
{
|
||||||
Component parentComponent = hostCand.getParentComponent();
|
Component parentComponent = hostCand.getParentComponent();
|
||||||
|
MultiplexingSocket multiplexing = new MultiplexingSocket(sock);
|
||||||
|
|
||||||
cand
|
cand
|
||||||
= new HostCandidate(
|
= new HostCandidate(
|
||||||
new IceTcpSocketWrapper(
|
new IceTcpSocketWrapper(multiplexing),
|
||||||
new MultiplexingSocket(sock)),
|
|
||||||
parentComponent,
|
parentComponent,
|
||||||
Transport.TCP);
|
Transport.TCP);
|
||||||
parentComponent
|
parentComponent
|
||||||
@ -158,6 +158,7 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
.getParentAgent()
|
.getParentAgent()
|
||||||
.getStunStack()
|
.getStunStack()
|
||||||
.addSocket(cand.getStunSocket(null));
|
.addSocket(cand.getStunSocket(null));
|
||||||
|
parentComponent.getSocket().add(multiplexing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@ -187,12 +188,12 @@ public class GoogleTurnSSLCandidateHarvester
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Do the SSL handshake (send client certificate and wait for receive server
|
* Do the SSL handshake (send client certificate and wait for receive server
|
||||||
* certificate). We explicitely need <tt>InputStream</tt> and
|
* certificate). We explicitly need <tt>InputStream</tt> and
|
||||||
* <tt>OutputStream</tt> because some <tt>Socket</tt> may redefine
|
* <tt>OutputStream</tt> because some <tt>Socket</tt> may redefine
|
||||||
* getInputStream()/getOutputStream() and we need the original stream.
|
* getInputStream()/getOutputStream() and we need the original stream.
|
||||||
*
|
*
|
||||||
* @param inputStream <tt>InputStream</tt> of the socket
|
* @param inputStream <tt>InputStream</tt> of the socket
|
||||||
* @param outputStream <tt>OuputStream</tt> of the socket
|
* @param outputStream <tt>OutputStream</tt> of the socket
|
||||||
* @return true if the SSL handshake is done
|
* @return true if the SSL handshake is done
|
||||||
* @throws IOException if something goes wrong
|
* @throws IOException if something goes wrong
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -418,6 +418,7 @@ public class HostCandidateHarvester
|
|||||||
// checks. In case we have enabled STUN, we are going to use
|
// checks. In case we have enabled STUN, we are going to use
|
||||||
// them as well while harvesting reflexive candidates.
|
// them as well while harvesting reflexive candidates.
|
||||||
createAndRegisterStunSocket(candidate);
|
createAndRegisterStunSocket(candidate);
|
||||||
|
component.getSocket().add(sock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,8 +570,9 @@ public class HostCandidateHarvester
|
|||||||
sock.setReuseAddress(true);
|
sock.setReuseAddress(true);
|
||||||
sock.bind(new InetSocketAddress(laddr, port));
|
sock.bind(new InetSocketAddress(laddr, port));
|
||||||
IceSocketWrapper socket
|
IceSocketWrapper socket
|
||||||
= new IceTcpServerSocketWrapper(sock,
|
= new IceTcpServerSocketWrapper(
|
||||||
component);
|
new DelegatingServerSocket(sock),
|
||||||
|
component);
|
||||||
|
|
||||||
if(logger.isLoggable(Level.FINEST))
|
if(logger.isLoggable(Level.FINEST))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -441,7 +441,7 @@ public class StunCandidateHarvester
|
|||||||
*/
|
*/
|
||||||
protected HostCandidate getHostCandidate(HostCandidate hostCand)
|
protected HostCandidate getHostCandidate(HostCandidate hostCand)
|
||||||
{
|
{
|
||||||
HostCandidate cand = null;
|
HostCandidate cand;
|
||||||
|
|
||||||
// create a new TCP HostCandidate
|
// create a new TCP HostCandidate
|
||||||
if(hostCand.getTransport() == Transport.TCP)
|
if(hostCand.getTransport() == Transport.TCP)
|
||||||
@ -450,12 +450,15 @@ public class StunCandidateHarvester
|
|||||||
{
|
{
|
||||||
Socket sock = new Socket(stunServer.getAddress(),
|
Socket sock = new Socket(stunServer.getAddress(),
|
||||||
stunServer.getPort());
|
stunServer.getPort());
|
||||||
cand = new HostCandidate(new IceTcpSocketWrapper(
|
MultiplexingSocket multiplexing = new MultiplexingSocket(sock);
|
||||||
new MultiplexingSocket(sock)),
|
cand
|
||||||
hostCand.getParentComponent(), Transport.TCP);
|
= new HostCandidate(
|
||||||
|
new IceTcpSocketWrapper(multiplexing),
|
||||||
|
hostCand.getParentComponent(), Transport.TCP);
|
||||||
hostCand.getParentComponent().getParentStream().
|
hostCand.getParentComponent().getParentStream().
|
||||||
getParentAgent().getStunStack().addSocket(
|
getParentAgent().getStunStack().addSocket(
|
||||||
cand.getStunSocket(null));
|
cand.getStunSocket(null));
|
||||||
|
hostCand.getParentComponent().getSocket().add(multiplexing);
|
||||||
}
|
}
|
||||||
catch(Exception io)
|
catch(Exception io)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -258,6 +258,8 @@ public class TurnCandidateHarvest
|
|||||||
harvester.getStunStack().addSocket(
|
harvester.getStunStack().addSocket(
|
||||||
relayedCandidate.getStunSocket(null));
|
relayedCandidate.getStunSocket(null));
|
||||||
|
|
||||||
|
relayedCandidate.getParentComponent().getSocket().add(
|
||||||
|
relayedCandidate.getCandidateIceSocketWrapper());
|
||||||
addCandidate(relayedCandidate);
|
addCandidate(relayedCandidate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -203,25 +203,27 @@ public class UPNPHarvester
|
|||||||
* @param socket local socket
|
* @param socket local socket
|
||||||
* @param externalIP external IP address
|
* @param externalIP external IP address
|
||||||
* @param port local port
|
* @param port local port
|
||||||
* @param cmp parent component
|
* @param component parent component
|
||||||
* @param device the UPnP gateway device
|
* @param device the UPnP gateway device
|
||||||
* @return a new <tt>UPNPCandidate</tt> instance which
|
* @return a new <tt>UPNPCandidate</tt> instance which
|
||||||
* represents the specified <tt>TransportAddress</tt>
|
* represents the specified <tt>TransportAddress</tt>
|
||||||
* @throws Exception if something goes wrong during candidate creation
|
* @throws Exception if something goes wrong during candidate creation
|
||||||
*/
|
*/
|
||||||
public List<LocalCandidate> createUPNPCandidate(IceSocketWrapper socket,
|
private List<LocalCandidate> createUPNPCandidate(IceSocketWrapper socket,
|
||||||
String externalIP, int port, Component cmp, GatewayDevice device)
|
String externalIP, int port, Component component, GatewayDevice device)
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
List<LocalCandidate> ret = new ArrayList<>();
|
List<LocalCandidate> ret = new ArrayList<>();
|
||||||
TransportAddress addr
|
TransportAddress addr
|
||||||
= new TransportAddress(externalIP, port, Transport.UDP);
|
= new TransportAddress(externalIP, port, Transport.UDP);
|
||||||
|
|
||||||
HostCandidate base = new HostCandidate(socket, cmp);
|
HostCandidate base = new HostCandidate(socket, component);
|
||||||
|
|
||||||
UPNPCandidate candidate = new UPNPCandidate(addr, base, cmp, device);
|
UPNPCandidate candidate
|
||||||
|
= new UPNPCandidate(addr, base, component, device);
|
||||||
IceSocketWrapper stunSocket = candidate.getStunSocket(null);
|
IceSocketWrapper stunSocket = candidate.getStunSocket(null);
|
||||||
candidate.getStunStack().addSocket(stunSocket);
|
candidate.getStunStack().addSocket(stunSocket);
|
||||||
|
component.getSocket().add(candidate.getCandidateIceSocketWrapper());
|
||||||
|
|
||||||
ret.add(candidate);
|
ret.add(candidate);
|
||||||
ret.add(base);
|
ret.add(base);
|
||||||
|
|||||||
@ -195,6 +195,7 @@ public class IceTcpServerSocketWrapper
|
|||||||
component.getParentStream().getParentAgent().
|
component.getParentStream().getParentAgent().
|
||||||
getStunStack().addSocket(
|
getStunStack().addSocket(
|
||||||
new IceTcpSocketWrapper(multiplexingSocket));
|
new IceTcpSocketWrapper(multiplexingSocket));
|
||||||
|
component.getSocket().add(multiplexingSocket);
|
||||||
|
|
||||||
sockets.add(multiplexingSocket);
|
sockets.add(multiplexingSocket);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -147,6 +147,21 @@ public class MergingDatagramSocket
|
|||||||
doAdd(socket);
|
doAdd(socket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the socket instance wrapped by {@code wrapper} to this merging
|
||||||
|
* socket. Note that this will start a thread reading from the added socket.
|
||||||
|
* @param wrapper the wrapper of the socket to add.
|
||||||
|
*/
|
||||||
|
public void add(IceSocketWrapper wrapper)
|
||||||
|
{
|
||||||
|
Object socket = wrapper.getUDPSocket();
|
||||||
|
if (socket == null)
|
||||||
|
{
|
||||||
|
socket = wrapper.getTCPSocket();
|
||||||
|
}
|
||||||
|
doAdd(socket);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a {@link DatagramSocket} instance to this merging socket. Note
|
* Adds a {@link DatagramSocket} instance to this merging socket. Note
|
||||||
* that this will start a thread reading from the added socket.
|
* that this will start a thread reading from the added socket.
|
||||||
@ -171,12 +186,13 @@ public class MergingDatagramSocket
|
|||||||
*/
|
*/
|
||||||
private void doAdd(Object socket)
|
private void doAdd(Object socket)
|
||||||
{
|
{
|
||||||
|
Objects.requireNonNull(socket, "socket");
|
||||||
|
|
||||||
if (!(socket instanceof DelegatingSocket) &&
|
if (!(socket instanceof DelegatingSocket) &&
|
||||||
!(socket instanceof DatagramSocket))
|
!(socket instanceof DatagramSocket))
|
||||||
{
|
{
|
||||||
logger.severe("Unsupported class: "
|
throw new IllegalStateException("Socket type not supported: "
|
||||||
+ (socket == null ? "null" : socket.getClass()));
|
+ socket.getClass().getName());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (socketContainersSyncRoot)
|
synchronized (socketContainersSyncRoot)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user