From 3cc3c94b636daf47b100597c673cbf32af9c332b Mon Sep 17 00:00:00 2001 From: seb Date: Fri, 7 Oct 2011 15:23:49 +0000 Subject: [PATCH] Search the candidate pair with local and remote frag rather than local and remote address for Google ICE. Handles the TCP connect in separate threads in order to not block the start of ICE. --- src/org/ice4j/ice/Agent.java | 15 +++- .../ice4j/ice/ConnectivityCheckClient.java | 9 ++- src/org/ice4j/ice/IceMediaStream.java | 73 ++++++++++++------- 3 files changed, 62 insertions(+), 35 deletions(-) diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 9dedf26..439814c 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -1244,7 +1244,6 @@ public class Agent } Component parentComponent = localCandidate.getParentComponent(); - RemoteCandidate remoteCandidate = null; // we need to find the username for the couple @@ -1281,7 +1280,6 @@ public class Agent CandidatePair triggeredPair = new CandidatePair(localCandidate, remoteCandidate); - logger.info("set use-candidate " + useCandidate + " for pair " + triggeredPair.toShortString()); if(useCandidate) @@ -1322,9 +1320,17 @@ public class Agent { //first check whether we already know about the remote address in case //we've just discovered a peer-reflexive candidate. - CandidatePair knownPair = this.findCandidatePair( + CandidatePair knownPair = null; + + if(compatibilityMode == CompatibilityMode.RFC5245) + knownPair = this.findCandidatePair( triggerPair.getLocalCandidate().getTransportAddress(), triggerPair.getRemoteCandidate().getTransportAddress()); + else + knownPair = findCandidatePair( + ((RemoteCandidate)triggerPair.getRemoteCandidate()). + getUfrag(), + triggerPair.getLocalCandidate().getUfrag()); IceMediaStream parentStream = triggerPair.getLocalCandidate() .getParentComponent().getParentStream(); @@ -1364,7 +1370,8 @@ public class Agent //ICE processing state. checkListStatesUpdated(); } - else if(!isControlling()) + else if(compatibilityMode != CompatibilityMode.RFC5245 && + !isControlling()) { //next time we will see a request it will be considered as // having USE-CANDIDATE diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index 1bba663..ab17ffc 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -308,7 +308,8 @@ class ConnectivityCheckClient = (CandidatePair) evt.getTransactionID().getApplicationData(); //make sure that the response came from the right place. - if (!checkSymmetricAddresses(evt)) + if (parentAgent.getCompatibilityMode() == CompatibilityMode.RFC5245 && + !checkSymmetricAddresses(evt)) { logger.fine("Received a non-symmetric response for pair: " + checkedPair.toShortString() + ". Failing"); @@ -673,7 +674,8 @@ class ConnectivityCheckClient if((parentAgent.isControlling() && request.containsAttribute(Attribute.USE_CANDIDATE)) || ((parentAgent.getCompatibilityMode() == - CompatibilityMode.GTALK) && //validPair.isNominated())) + CompatibilityMode.GTALK) && + //validPair.isNominated())) checkedPair.useCandidateSent())) { if(validPair.getParentComponent().getSelectedPair() == null) @@ -693,7 +695,8 @@ class ConnectivityCheckClient //itself had the USE-CANDIDATE attribute. This case is described in //Section 7.2.1.5, and may now result in setting the nominated flag for //the pair learned from the original request. - else if(!parentAgent.isControlling() && + else if(parentAgent.getCompatibilityMode() == + CompatibilityMode.RFC5245 && !parentAgent.isControlling() && checkedPair.useCandidateReceived() && !checkedPair.isNominated()) { diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index c2f69d4..c4368f6 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -347,8 +347,8 @@ public class IceMediaStream * pair and extract. * @param checkList the list that we need to update with the new pairs. */ - private void createCheckList(Component component, - List checkList) + private void createCheckList(final Component component, + final List checkList) { List localCnds = component.getLocalCandidates(); List remoteCnds = component.getRemoteCandidates(); @@ -377,36 +377,53 @@ public class IceMediaStream parentAgent.getCompatibilityMode() == CompatibilityMode.GTALK) { - /* for TCP, create a new Candidate (a new connection) - * to each of remote TCP candidates - */ - try - { - Socket sock = new MultiplexingSocket(); - int timeout = sock.getSoTimeout(); - sock.setSoTimeout(1000); + final LocalCandidate loc = localCnd; + final Candidate remot = remoteCnd; - sock.connect(new InetSocketAddress( - remoteCnd.getTransportAddress().getAddress(), - remoteCnd.getTransportAddress().getPort()), - 1000); - - sock.setSoTimeout(timeout); - LocalCandidate tmp = - new HostCandidate(new IceTcpSocketWrapper(sock), - component); - tmp.setUfrag(localCnd.getUfrag()); - localCnd = tmp; - } - catch (IOException e) + new Thread() { - logger.info("Failed to TCP connect to " + - remoteCnd.getTransportAddress()); - continue; - } + public void run() + { + /* for TCP, create a new Candidate (a new + * connection) to each of remote TCP candidates + */ + try + { + Socket sock = new MultiplexingSocket(); + int timeout = sock.getSoTimeout(); + sock.setSoTimeout(1000); + + sock.connect(new InetSocketAddress( + remot.getTransportAddress(). + getAddress(), + remot.getTransportAddress(). + getPort()), + 1000); + + sock.setSoTimeout(timeout); + LocalCandidate tmp = + new HostCandidate( + new IceTcpSocketWrapper(sock), + component); + tmp.setUfrag(loc.getUfrag()); + + CandidatePair pair = new CandidatePair(tmp, + remot); + checkList.add(pair); + } + catch (IOException e) + { + logger.info("Failed to TCP connect to " + + remot.getTransportAddress()); + return; + } + } + }.start(); + return; } - CandidatePair pair = new CandidatePair(localCnd, remoteCnd); + CandidatePair pair = new CandidatePair(localCnd, + remoteCnd); checkList.add(pair); } }