From 3c3f40a38f0d85df3394dc201aea9c59b289c4ec Mon Sep 17 00:00:00 2001 From: emcho Date: Sat, 8 May 2010 21:38:20 +0000 Subject: [PATCH] Adds an IceProcessingState to Agents --- src/org/ice4j/ice/Agent.java | 70 +++++++++++----------- src/org/ice4j/ice/CheckList.java | 4 +- src/org/ice4j/ice/IceMediaStream.java | 23 ++++++++ src/org/ice4j/ice/IceProcessingState.java | 72 +++++++++++++++++++++++ 4 files changed, 130 insertions(+), 39 deletions(-) create mode 100644 src/org/ice4j/ice/IceProcessingState.java diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 88fb465..47fd2d6 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -921,50 +921,24 @@ public class Agent { pairToNominate.nominate(); - //For both controlling and controlled agents, the state of ICE - //processing depends on the presence of nominated candidate pairs in - //the valid list and on the state of the check list. Note that, at any - //time, more than one of the following cases can apply: - - // If there is at least one nominated pair in the valid list for a - // media stream and the state of the check list is Running: Component parentComponent = pairToNominate.getParentComponent(); IceMediaStream parentStream = parentComponent.getParentStream(); CheckList checkList = parentStream.getCheckList(); if( checkList.getState() == CheckListState.RUNNING ) + checkList.handleNomination(pairToNominate); + + //Once there is at least one nominated pair in the valid list for + //every component of the media stream and the state of the + //check list is Running + if(parentStream.allComponentsAreNominated() + && checkList.getState() == CheckListState.RUNNING) { - //The agent MUST remove all Waiting and Frozen pairs in the check - //list and triggered check queue for the same component as the - //nominated pairs for that media stream. - checkList.removeNonCompledPairsForComponent(parentComponent); - /* - //If an In-Progress pair in the check list is for the same - //component as a nominated pair, the agent SHOULD cease - //retransmissions for its check if its pair priority is lower - //than the lowest-priority nominated pair for that component.*/ + //The agent MUST change the state of processing for its check + //list for that media stream to Completed. + checkList.setState(CheckListState.COMPLETED); } - /* - - - o Once there is at least one nominated pair in the valid list for - every component of at least one media stream and the state of the - check list is Running: - - * The agent MUST change the state of processing for its check - list for that media stream to Completed. - - * The agent MUST continue to respond to any checks it may still - receive for that media stream, and MUST perform triggered - checks if required by the processing of Section 7.2. - - * The agent MUST continue retransmitting any In-Progress checks - for that check list. - - * The agent MAY begin transmitting media for this media stream as - described in Section 11.1. - o Once the state of each check list is Completed: * The agent sets the state of ICE processing overall to @@ -973,7 +947,31 @@ public class Agent * If an agent is controlling, it examines the highest-priority nominated candidate pair for each component of each media stream. If any of those candidate pairs differ from the + default candidate pairs in the most recent offer/answer + exchange, the controlling agent MUST generate an updated offer + as described in Section 9. If the controlling agent is using + an aggressive nomination algorithm, this may result in several + updated offers as the pairs selected for media change. An + agent MAY delay sending the offer for a brief interval (one + second is RECOMMENDED) in order to allow the selected pairs to + stabilize. + o If the state of the check list is Failed, ICE has not been able to + complete for this media stream. The correct behavior depends on + the state of the check lists for other media streams: + + * If all check lists are Failed, ICE processing overall is + considered to be in the Failed state, and the agent SHOULD + consider the session a failure, SHOULD NOT restart ICE, and the + controlling agent SHOULD terminate the entire session. + + * If at least one of the check lists for other media streams is + Completed, the controlling agent SHOULD remove the failed media + stream from the session in its updated offer. + + * If none of the check lists for other media streams are + Completed, but at least one is Running, the agent SHOULD let + ICE continue. */ diff --git a/src/org/ice4j/ice/CheckList.java b/src/org/ice4j/ice/CheckList.java index cb03c2b..c42c22c 100644 --- a/src/org/ice4j/ice/CheckList.java +++ b/src/org/ice4j/ice/CheckList.java @@ -296,8 +296,7 @@ public class CheckList * @param nominatedPair the {@link CandidatePair} whose nomination we need * to handle. */ - public synchronized void removeNonCompledPairsForComponent( - CandidatePair nominatedPair) + public synchronized void handleNomination(CandidatePair nominatedPair) { Component cmp = nominatedPair.getParentComponent(); Iterator pairsIter = iterator(); @@ -333,5 +332,4 @@ public class CheckList } } } - } diff --git a/src/org/ice4j/ice/IceMediaStream.java b/src/org/ice4j/ice/IceMediaStream.java index f2ed6be..ced4008 100644 --- a/src/org/ice4j/ice/IceMediaStream.java +++ b/src/org/ice4j/ice/IceMediaStream.java @@ -607,6 +607,29 @@ public class IceMediaStream return true; } + /** + * Returns true if there is at least one nominated {@link + * CandidatePair} in the valid list for every {@link Component} of this + * stream and false otherwise. + * + * @return true if there is at least one nominated {@link + * CandidatePair} in the valid list for every {@link Component} of this + * stream and false otherwise. + */ + public boolean allComponentsAreNominated() + { + List components = getComponents(); + + synchronized (validList) + { + for(CandidatePair pair : validList) + if(pair.isNominated()) + components.remove(pair.getParentComponent()); + } + + return components.size() == 0; + } + /** * Returns the first {@link CandidatePair} stored in this stream's valid * list, that belongs to the specified component. diff --git a/src/org/ice4j/ice/IceProcessingState.java b/src/org/ice4j/ice/IceProcessingState.java new file mode 100644 index 0000000..f3254ac --- /dev/null +++ b/src/org/ice4j/ice/IceProcessingState.java @@ -0,0 +1,72 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package org.ice4j.ice; + +/** + * RFC 5245 mentions that ICE processing across all media streams also has a + * state associated with it. This state is equal to Running while ICE + * processing is under way. The state is Completed when ICE processing is + * complete and Failed if it failed without success. For convenience reasons + * we are also adding an extra Waiting state that reflects the state + * of an {@link Agent} before it starts processing. This is also an {@link + * Agent}'s default state. + * + * @author Emil Ivov + */ +public enum IceProcessingState +{ + /** + * The state is equal to Waiting if ICE processing has not started + * for the corresponding {@link Agent}. + */ + WAITING("Waiting"), + + /** + * The state is equal to Running while ICE processing is under way. + */ + RUNNING("Running"), + + /** + * The state is Completed when ICE processing is complete. + */ + COMPLETED("Completed"), + + /** + * The state is Completed when ICE processing is Failed if processing + * failed without success. + */ + FAILED("Failed"); + + /** + * The name of this IceProcessingState instance. + */ + private final String stateName; + + /** + * Creates an IceProcessingState instance with the specified name. + * + * @param stateName the name of the IceProcessingState instance + * we'd like to create. + */ + private IceProcessingState(String stateName) + { + this.stateName = stateName; + } + + /** + * Returns the name of this IceProcessingState (e.g. "Running", + * "Completed", or "Failed"). + * + * @return the name of this IceProcessingState (e.g. "Running", + * "Completed", or "Failed"). + */ + @Override + public String toString() + { + return stateName; + } +}