diff --git a/src/org/ice4j/ice/Component.java b/src/org/ice4j/ice/Component.java index 0d2d665..10f8e1d 100644 --- a/src/org/ice4j/ice/Component.java +++ b/src/org/ice4j/ice/Component.java @@ -251,8 +251,32 @@ public class Component logger.info("Update remote candidate for " + toShortString() + ": " + candidate.getTransportAddress()); + List existingCandidates + = new LinkedList(); + synchronized (remoteCandidates) + { + existingCandidates.addAll(remoteCandidates); + } + synchronized(remoteUpdateCandidates) { + existingCandidates.addAll(remoteUpdateCandidates); + + // Make sure we add no duplicates + TransportAddress transportAddress = candidate.getTransportAddress(); + CandidateType type = candidate.getType(); + for (RemoteCandidate existingCandidate : existingCandidates) + { + if (transportAddress + .equals(existingCandidate.getTransportAddress()) + && type == existingCandidate.getType()) + { + logger.info("Not adding duplicate remote candidate: " + + candidate.getTransportAddress()); + return; + } + } + remoteUpdateCandidates.add(candidate); } } @@ -331,12 +355,16 @@ public class Component public void updateRemoteCandidates() { List checkList = null; + List newRemoteCandidates; synchronized(remoteUpdateCandidates) { if(remoteUpdateCandidates.size() == 0) return; + newRemoteCandidates + = new LinkedList(remoteUpdateCandidates); + List localCnds = getLocalCandidates(); // remove UPnP base from local candidate @@ -388,6 +416,11 @@ public class Component remoteUpdateCandidates.clear(); } + synchronized (remoteCandidates) + { + remoteCandidates.addAll(newRemoteCandidates); + } + //sort and prune update checklist Collections.sort(checkList, CandidatePair.comparator); parentStream.pruneCheckList(checkList);