Starts work on receiving semantics for Trickle ICE

This commit is contained in:
emcho 2013-06-26 01:53:45 +00:00
parent 207a963196
commit e46ec4c494

View File

@ -25,7 +25,6 @@ import org.ice4j.socket.*;
* <p> * <p>
* *
* @author Emil Ivov * @author Emil Ivov
* @author Namal Senarathne
* @author Sebastien Vincent * @author Sebastien Vincent
*/ */
public class Component public class Component
@ -276,21 +275,58 @@ public class Component
/* for TCP, create a new Candidate to each of remote /* for TCP, create a new Candidate to each of remote
* TCP candidates * TCP candidates
*/ */
try for(LocalCandidate localCnd : getLocalCandidates())
{ {
for(LocalCandidate l : getLocalCandidates()) if(localCnd.getTransport() != Transport.TCP
{ || (localCnd.getType() != CandidateType.LOCAL_CANDIDATE
if(l.getTransport() != Transport.TCP || && localCnd.getType() != CandidateType.HOST_CANDIDATE)
(l.getType() != CandidateType.LOCAL_CANDIDATE && || !(localCnd.getIceSocketWrapper()
l.getType() != CandidateType.HOST_CANDIDATE) || instanceof IceTcpServerSocketWrapper)
!(l.getIceSocketWrapper() instanceof || !localCnd.getTransportAddress().canReach(
IceTcpServerSocketWrapper) || candidate.getTransportAddress())
!l.getTransportAddress().canReach( )
candidate.getTransportAddress()))
{ {
continue; continue;
} }
LocalCandidate newLocalCandidate
= createLocalTcpCandidate4GTalk(candidate, localCnd);
if (newLocalCandidate == null)
{
//sth wen wrong but we've already logged so ...
continue;
}
synchronized(localCandidates)
{
localCandidates.add(newLocalCandidate);
}
}
}
synchronized(remoteUpdateCandidates)
{
remoteUpdateCandidates.add(candidate);
}
}
/**
* Creates a local TCP candidate for use with a specific remote GTalk TCP
* candidate.
*
* @param remoteCandidate the GTalk TCP candidate that we'd like to connect
* to.
* @param localCandidate the local candidate that we are pairing
* remoteCandidate with and that we should use as a source for the ice
* ufrag and password.
*
* @return the newly created {@link LocalCandidate}
*/
private LocalCandidate createLocalTcpCandidate4GTalk(
RemoteCandidate remoteCandidate,
LocalCandidate localCandidate)
{
MultiplexingSocket sock = new MultiplexingSocket(); MultiplexingSocket sock = new MultiplexingSocket();
try try
{ {
@ -299,22 +335,25 @@ public class Component
int timeout = sock.getSoTimeout(); int timeout = sock.getSoTimeout();
sock.setSoTimeout(1000); sock.setSoTimeout(1000);
sock.connect(new InetSocketAddress( sock.connect(new InetSocketAddress(
candidate.getTransportAddress().getAddress(), remoteCandidate.getTransportAddress().getAddress(),
candidate.getTransportAddress().getPort()), 1000); remoteCandidate.getTransportAddress().getPort()), 1000);
sock.setSoTimeout(timeout); sock.setSoTimeout(timeout);
} }
catch(Exception e) catch(Exception e)
{ {
logger.info("Failed to connect to " + logger.info("Failed to connect to " +
candidate.getTransportAddress()); remoteCandidate.getTransportAddress());
sock.close(); sock.close();
sock = null; return null;
continue;
} }
if(candidate.getTransportAddress().getPort() == 443) try
{ {
//SSLTCP handshake
if(remoteCandidate.getTransportAddress().getPort() == 443)
{
//SSL/TCP handshake
OutputStream outputStream = OutputStream outputStream =
sock.getOriginalOutputStream(); sock.getOriginalOutputStream();
InputStream inputStream = sock.getOriginalInputStream(); InputStream inputStream = sock.getOriginalInputStream();
@ -322,37 +361,23 @@ public class Component
if(!GoogleTurnSSLCandidateHarvester.sslHandshake( if(!GoogleTurnSSLCandidateHarvester.sslHandshake(
inputStream, outputStream)) inputStream, outputStream))
{ {
logger.info("Failed to connect to SSLTCP relay"); logger.info("Failed to connect to SSL/TCP relay");
outputStream = null; return null;
inputStream = null;
continue;
} }
outputStream = null;
inputStream = null;
} }
LocalCandidate tmp = LocalCandidate newLocalCandidate =
new HostCandidate(new IceTcpSocketWrapper(sock), new HostCandidate(new IceTcpSocketWrapper(sock),
this, Transport.TCP); this, Transport.TCP);
parentStream.getParentAgent().getStunStack().addSocket( parentStream.getParentAgent().getStunStack().addSocket(
tmp.getStunSocket(null)); newLocalCandidate.getStunSocket(null));
tmp.setUfrag(l.getUfrag()); newLocalCandidate.setUfrag(localCandidate.getUfrag());
return newLocalCandidate;
synchronized(localCandidates) }
catch(IOException ioe)
{ {
localCandidates.add(tmp); logger.log(Level.INFO, "Failed to connect to SSL/TCP relay", ioe);
} return null;
}
}
catch (IOException e)
{
logger.info("Create TCP client socket error: " + e);
}
}
synchronized(remoteUpdateCandidates)
{
remoteUpdateCandidates.add(candidate);
} }
} }
@ -387,6 +412,7 @@ public class Component
if(localCnd == upnpBase) if(localCnd == upnpBase)
continue; continue;
//don't pair local GTalk TCP candidates with the new remote ones
if(parentStream.getParentAgent(). if(parentStream.getParentAgent().
getCompatibilityMode() == CompatibilityMode.GTALK && getCompatibilityMode() == CompatibilityMode.GTALK &&
localCnd.getIceSocketWrapper() instanceof localCnd.getIceSocketWrapper() instanceof
@ -395,6 +421,7 @@ public class Component
continue; continue;
} }
//pair each of the new remote candidates with each of our locals
for(RemoteCandidate remoteCnd : remoteUpdateCandidates) for(RemoteCandidate remoteCnd : remoteUpdateCandidates)
{ {
if(localCnd.canReach(remoteCnd)) if(localCnd.canReach(remoteCnd))
@ -421,16 +448,15 @@ public class Component
remoteUpdateCandidates.clear(); remoteUpdateCandidates.clear();
} }
/* sort and prune update checklist */ //sort and prune update checklist
Collections.sort(checkList, CandidatePair.comparator); Collections.sort(checkList, CandidatePair.comparator);
parentStream.pruneCheckList(checkList); parentStream.pruneCheckList(checkList);
if(parentStream.getCheckList().getState().equals( if(parentStream.getCheckList().getState().equals(
CheckListState.RUNNING)) CheckListState.RUNNING))
{ {
/* add the update CandidatePair list to the currently running //add the updated CandidatePair list to the currently running
* checklist //checklist
*/
CheckList streamCheckList = parentStream.getCheckList(); CheckList streamCheckList = parentStream.getCheckList();
synchronized(streamCheckList) synchronized(streamCheckList)
{ {