From 0f86b8797fd4144fc13bf498869d08b8c4e33dab Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Fri, 24 Feb 2017 09:30:21 -0600 Subject: [PATCH 1/2] feat: Handles pairs discovered late, after the Agent has completed/terminated. --- src/main/java/org/ice4j/ice/Agent.java | 49 +++++++++++--------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index 9f09f70..d8a9fe0 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -1541,19 +1541,8 @@ public class Agent String localUFrag, boolean useCandidate) { - if (isOver()) - { - //means we already completed ICE and are happily running media - //the only reason we are called is most probably because the remote - //party is still sending Binding Requests our way and making sure we - //are still alive. - return; - } - String ufrag = null; - LocalCandidate localCandidate = null; - - localCandidate = findLocalCandidate(localAddress); + LocalCandidate localCandidate = findLocalCandidate(localAddress); if (localCandidate == null) { @@ -1563,9 +1552,8 @@ public class Agent } Component parentComponent = localCandidate.getParentComponent(); - RemoteCandidate remoteCandidate = null; - - remoteCandidate = new RemoteCandidate( + RemoteCandidate remoteCandidate + = new RemoteCandidate( remoteAddress, parentComponent, CandidateType.PEER_REFLEXIVE_CANDIDATE, @@ -1588,25 +1576,30 @@ public class Agent synchronized(startLock) { - if (isStarted()) - { - //we are started, which means we have the remote candidates - //so it's now safe to go and see whether this is a new PR cand. - if (triggeredPair.getParentComponent().getSelectedPair() == null) - { - logger.info("Received check from " - + triggeredPair.toShortString() + " triggered a check. " - + "Local ufrag " + getLocalUfrag()); - } - triggerCheck(triggeredPair); - } - else + if (state == IceProcessingState.WAITING) { logger.fine("Receive STUN checks before our ICE has started"); //we are not started yet so we'd better wait until we get the //remote candidates in case we are holding to a new PR one. this.preDiscoveredPairsQueue.add(triggeredPair); } + else if (state == IceProcessingState.FAILED) + { + // Failure is permanent, currently. + } + else //Running, Connected or Terminated. + { + if (logger.isLoggable(Level.FINE)) + { + logger.debug("Received check from " + + triggeredPair.toShortString() + " triggered a check. " + + "Local ufrag " + getLocalUfrag()); + } + + // We have been started, and have not failed (yet). If this is + // a new pair, handle it (even if we have already completed). + triggerCheck(triggeredPair); + } } } From 6bfe2ac5e54359413de3c913c30a1d590fd74224 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Fri, 24 Feb 2017 09:34:55 -0600 Subject: [PATCH 2/2] feat: Allows adding sockets to an Agent late, after the Agent has completed/terminated. --- .../ice4j/ice/harvest/SinglePortUdpHarvester.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java index accb4a5..87d2bbe 100644 --- a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java @@ -26,7 +26,7 @@ import java.io.*; import java.net.*; import java.util.*; import java.util.concurrent.*; -import java.util.logging.Logger; // Disambiguation +import java.util.logging.*; /** * A harvester implementation which binds to a single DatagramSocket @@ -337,11 +337,16 @@ public class SinglePortUdpHarvester IceProcessingState state = component.getParentStream().getParentAgent().getState(); - if (!IceProcessingState.WAITING.equals(state) - && !IceProcessingState.RUNNING.equals(state)) + if (state == IceProcessingState.FAILED) { throw new IOException( - "Agent state is " + state + ". Cannot add socket."); + "Cannot add socket to an Agent in state FAILED."); + } + else if (state != null && state.isOver() + && logger.isLoggable(Level.FINE)) + { + logger.fine( + "Adding a socket to a completed Agent, state=" + state); } MultiplexingDatagramSocket multiplexing