diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index 1c6fe8b..59be43b 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -761,9 +761,9 @@ public class Agent */ public void addStateChangeListener(PropertyChangeListener l) { - synchronized(stateListeners) + synchronized (stateListeners) { - if(!stateListeners.contains(l)) + if (!stateListeners.contains(l)) stateListeners.add(l); } } @@ -776,7 +776,7 @@ public class Agent */ public void removeStateChangeListener(PropertyChangeListener l) { - synchronized(stateListeners) + synchronized (stateListeners) { stateListeners.remove(l); } @@ -794,7 +794,7 @@ public class Agent { PropertyChangeListener[] stateListenersCopy; - synchronized(stateListeners) + synchronized (stateListeners) { stateListenersCopy = stateListeners.toArray(NO_STATE_CHANGE_LISTENERS); @@ -808,7 +808,7 @@ public class Agent PROPERTY_ICE_PROCESSING_STATE, oldState, newState); - for(PropertyChangeListener l : stateListenersCopy) + for (PropertyChangeListener l : stateListenersCopy) l.propertyChange(evt); } } diff --git a/src/main/java/org/ice4j/ice/CandidatePair.java b/src/main/java/org/ice4j/ice/CandidatePair.java index f0a165f..03a54b8 100644 --- a/src/main/java/org/ice4j/ice/CandidatePair.java +++ b/src/main/java/org/ice4j/ice/CandidatePair.java @@ -290,13 +290,13 @@ public class CandidatePair this.state = newState; - if(newState == CandidatePairState.IN_PROGRESS) + if (newState == CandidatePairState.IN_PROGRESS) { if (tranID == null) { throw new IllegalArgumentException( "Putting a pair into the In-Progress state MUST be" - + " accomapnied with the TransactionID of the" + + " accompanied with the TransactionID of the" + " connectivity check."); } } diff --git a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java index 196e643..3aad967 100644 --- a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java @@ -175,7 +175,7 @@ class ConnectivityCheckClient indication, candidatePair.getRemoteCandidate().getTransportAddress(), localCandidate.getBase().getTransportAddress()); - if(logger.isLoggable(Level.FINEST)) + if (logger.isLoggable(Level.FINEST)) { logger.finest( "sending binding indication to pair " + candidatePair); @@ -185,7 +185,7 @@ class ConnectivityCheckClient { IceSocketWrapper stunSocket = localCandidate.getStunSocket(null); - if(stunSocket != null) + if (stunSocket != null) { logger.log( Level.INFO, @@ -282,7 +282,7 @@ class ConnectivityCheckClient .getParentComponent().getParentStream().getName(); String localUserName = parentAgent.generateLocalUserName(media); - if(localUserName == null) + if (localUserName == null) return null; UsernameAttribute unameAttr @@ -322,7 +322,7 @@ class ConnectivityCheckClient originalWaitInterval, maxWaitInterval, maxRetransmissions); - if(logger.isLoggable(Level.FINEST)) + if (logger.isLoggable(Level.FINEST)) { logger.finest( "checking pair " + candidatePair + " tid " + tran); @@ -334,13 +334,13 @@ class ConnectivityCheckClient IceSocketWrapper stunSocket = localCandidate.getStunSocket(null); - if(stunSocket != null) + if (stunSocket != null) { String msg = "Failed to send " + request + " through " + stunSocket.getLocalSocketAddress() + "."; - if((ex instanceof NoRouteToHostException) + if ((ex instanceof NoRouteToHostException) || (ex.getMessage() != null && ex.getMessage().equals("No route to host"))) { @@ -383,9 +383,9 @@ class ConnectivityCheckClient char messageType = response.getMessageType(); //handle error responses. - if(messageType == Response.BINDING_ERROR_RESPONSE) + if (messageType == Response.BINDING_ERROR_RESPONSE) { - if(!response.containsAttribute(Attribute.ERROR_CODE)) + if (!response.containsAttribute(Attribute.ERROR_CODE)) { logger.fine("Received a malformed error response."); return; //malformed error response @@ -394,7 +394,7 @@ class ConnectivityCheckClient processErrorResponse(ev); } //handle success responses. - else if(messageType == Response.BINDING_SUCCESS_RESPONSE) + else if (messageType == Response.BINDING_SUCCESS_RESPONSE) { processSuccessResponse(ev); } @@ -419,12 +419,12 @@ class ConnectivityCheckClient = checkedPair.getParentComponent().getParentStream(); final CheckList checkList = stream.getCheckList(); - if(stream.getParentAgent().getState().isEstablished()) + if (stream.getParentAgent().getState().isEstablished()) return; //If all of the pairs in the check list are now either in the Failed or //Succeeded state: - if(checkList.allChecksCompleted()) + if (checkList.allChecksCompleted()) { //If there is not a pair in the valid list for each component of the //media stream, the state of the check list is set to Failed. @@ -433,7 +433,7 @@ class ConnectivityCheckClient final String streamName = stream.getName(); Timer timer = timers.get(streamName); - if(timer == null) + if (timer == null) { logger.info("CheckList will failed in a few seconds if no" + "succeeded checks come"); @@ -443,7 +443,7 @@ class ConnectivityCheckClient @Override public void run() { - if(checkList.getState() != CheckListState.COMPLETED) + if (checkList.getState() != CheckListState.COMPLETED) { logger.info("CheckList for stream " + streamName + " FAILED"); @@ -471,7 +471,7 @@ class ConnectivityCheckClient { CheckList anotherCheckList = anotherStream.getCheckList(); - if(anotherCheckList.isFrozen()) + if (anotherCheckList.isFrozen()) { anotherCheckList.computeInitialCheckListPairStates(); startChecks(anotherCheckList); @@ -609,8 +609,11 @@ class ConnectivityCheckClient //Succeeded. Note that, the pair which *generated* the check may be //different than the valid pair constructed above if (checkedPair.getParentComponent().getSelectedPair() == null) + { logger.info("Pair succeeded: " + checkedPair.toShortString() - + ". Local ufrag " + parentAgent.getLocalUfrag()); + + ". Local ufrag " + + parentAgent.getLocalUfrag()); + } checkedPair.setStateSucceeded(); } @@ -627,12 +630,12 @@ class ConnectivityCheckClient IceMediaStream parentStream = checkedPair.getParentComponent().getParentStream(); - synchronized(this) + synchronized (this) { Vector parentCheckList = new Vector<>(parentStream.getCheckList()); - for(CandidatePair pair : parentCheckList) + for (CandidatePair pair : parentCheckList) { if (pair.getState() == CandidatePairState.FROZEN && checkedPair.getFoundation().equals( @@ -699,7 +702,7 @@ class ConnectivityCheckClient if (parentAgent.isControlling() && request.containsAttribute(Attribute.USE_CANDIDATE)) { - if(validPair.getParentComponent().getSelectedPair() == null) + if (validPair.getParentComponent().getSelectedPair() == null) { logger.info("Nomination confirmed for pair: " + validPair.toShortString() @@ -721,7 +724,7 @@ class ConnectivityCheckClient && checkedPair.useCandidateReceived() && !checkedPair.isNominated()) { - if(checkedPair.getParentComponent().getSelectedPair() == null) + if (checkedPair.getParentComponent().getSelectedPair() == null) { logger.info( "Nomination confirmed for pair: " @@ -800,12 +803,12 @@ class ConnectivityCheckClient logger.finer("Received error code " + ((int) errorCode)); //RESOLVE ROLE_CONFLICTS - if(errorCode == ErrorCodeAttribute.ROLE_CONFLICT) + if (errorCode == ErrorCodeAttribute.ROLE_CONFLICT) { boolean wasControlling = originalRequest.containsAttribute(Attribute.ICE_CONTROLLING); - logger.finer("Swithing to isControlling=" + !wasControlling); + logger.finer("Switching to isControlling=" + !wasControlling); parentAgent.setControlling(!wasControlling); pair.getParentComponent().getParentStream().getCheckList() @@ -916,7 +919,7 @@ class ConnectivityCheckClient { long waitFor = getNextWaitInterval(); - if(waitFor > 0) + if (waitFor > 0) { /* * waitFor will be 0 for the first check since we won't @@ -939,10 +942,10 @@ class ConnectivityCheckClient CandidatePair pairToCheck = checkList.popTriggeredCheck(); //if there are no triggered checks, go for an ordinary one. - if(pairToCheck == null) + if (pairToCheck == null) pairToCheck = checkList.getNextOrdinaryPairToCheck(); - if(pairToCheck != null) + if (pairToCheck != null) { /* * Since we suspect that it is possible to @@ -956,7 +959,7 @@ class ConnectivityCheckClient TransactionID transactionID = startCheckForPair(pairToCheck); - if(transactionID == null) + if (transactionID == null) { logger.info( "Pair failed: " @@ -983,7 +986,7 @@ class ConnectivityCheckClient { synchronized (paceMakers) { - synchronized(this) + synchronized (this) { paceMakers.remove(this); } @@ -1005,7 +1008,7 @@ class ConnectivityCheckClient { PaceMaker paceMaker = paceMakersIter.next(); - synchronized(paceMaker) + synchronized (paceMaker) { paceMaker.running = false; paceMaker.notify(); diff --git a/src/main/java/org/ice4j/ice/DefaultNominator.java b/src/main/java/org/ice4j/ice/DefaultNominator.java index 0229d21..21e113c 100644 --- a/src/main/java/org/ice4j/ice/DefaultNominator.java +++ b/src/main/java/org/ice4j/ice/DefaultNominator.java @@ -52,7 +52,7 @@ public class DefaultNominator /** * Map that will remember association between validated relayed candidate - * and a timer. It is use with the NOMINATE_FIRST_HIGHEST_VALID strategy. + * and a timer. It is used with the NOMINATE_FIRST_HIGHEST_VALID strategy. */ private final Map validatedCandidates = new HashMap<>(); @@ -86,12 +86,12 @@ public class DefaultNominator { String propertyName = ev.getPropertyName(); - if(Agent.PROPERTY_ICE_PROCESSING_STATE.equals(propertyName)) + if (Agent.PROPERTY_ICE_PROCESSING_STATE.equals(propertyName)) { - if(ev.getNewValue() != IceProcessingState.RUNNING) + if (ev.getNewValue() != IceProcessingState.RUNNING) return; - for(IceMediaStream stream : parentAgent.getStreams()) + for (IceMediaStream stream : parentAgent.getStreams()) { stream.addPairChangeListener(this); stream.getCheckList().addStateChangeListener(this); @@ -104,7 +104,7 @@ public class DefaultNominator return; } - if(ev.getSource() instanceof CandidatePair) + if (ev.getSource() instanceof CandidatePair) { // STUN Usage for Consent Freshness is of no concern here. if (IceMediaStream.PROPERTY_PAIR_CONSENT_FRESHNESS_CHANGED.equals( @@ -115,7 +115,7 @@ public class DefaultNominator // do not nominate pair if there is currently a selected pair for // the component - if(validPair.getParentComponent().getSelectedPair() != null) + if (validPair.getParentComponent().getSelectedPair() != null) { logger.fine( "Keep-alive for pair: " + validPair.toShortString()); @@ -141,7 +141,8 @@ public class DefaultNominator */ private void strategyNominateFirstValid(PropertyChangeEvent evt) { - if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName())) + if (IceMediaStream.PROPERTY_PAIR_VALIDATED + .equals(evt.getPropertyName())) { CandidatePair validPair = (CandidatePair)evt.getSource(); @@ -163,7 +164,7 @@ public class DefaultNominator { String pname = ev.getPropertyName(); - if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(pname) + if (IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(pname) || (IceMediaStream.PROPERTY_PAIR_STATE_CHANGED.equals(pname) && (ev.getNewValue() == CandidatePairState.FAILED))) { @@ -172,14 +173,14 @@ public class DefaultNominator IceMediaStream parentStream = parentComponent.getParentStream(); CheckList parentCheckList = parentStream.getCheckList(); - if(!parentCheckList.allChecksCompleted()) + if (!parentCheckList.allChecksCompleted()) return; - for(Component component : parentStream.getComponents()) + for (Component component : parentStream.getComponents()) { CandidatePair pair = parentStream.getValidPair(component); - if(pair != null) + if (pair != null) { logger.info( "Nominate (highest priority): " @@ -215,7 +216,7 @@ public class DefaultNominator private void strategyNominateFirstHostOrReflexiveValid( PropertyChangeEvent evt) { - if(IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName())) + if (IceMediaStream.PROPERTY_PAIR_VALIDATED.equals(evt.getPropertyName())) { CandidatePair validPair = (CandidatePair) evt.getSource(); @@ -229,12 +230,12 @@ public class DefaultNominator CandidateType.RELAYED_CANDIDATE); boolean nominate = false; - synchronized(validatedCandidates) + synchronized (validatedCandidates) { TimerTask task = validatedCandidates.get(component.toShortString()); - if(isRelayed && task == null) + if (isRelayed && task == null) { /* armed a timer and see if a host or server reflexive pair * gets nominated. Otherwise nominate the relayed candidate @@ -247,10 +248,10 @@ public class DefaultNominator timer.schedule(task, 0); validatedCandidates.put(component.toShortString(), task); } - else if(!isRelayed) + else if (!isRelayed) { // host or server reflexive candidate pair - if(task != null) + if (task != null) { task.cancel(); logger.info( @@ -265,7 +266,7 @@ public class DefaultNominator } } - if(nominate) + if (nominate) parentAgent.nominate(validPair); } } @@ -314,18 +315,17 @@ public class DefaultNominator */ public void propertyChange(PropertyChangeEvent evt) { - /* check list has running out of ordinary checks, see if all other - * candidates are FAILED, in which case we nominate immediately - * the relayed candidate - */ + // check list has running out of ordinary checks, see if all other + // candidates are FAILED, in which case we nominate immediately + // the relayed candidate CheckList checkList = (CheckList)evt.getSource(); boolean allFailed = true; - synchronized(checkList) + synchronized (checkList) { - for(CandidatePair c : checkList) + for (CandidatePair c : checkList) { - if(c != pair && c.getState() != CandidatePairState.FAILED) + if (c != pair && c.getState() != CandidatePairState.FAILED) { allFailed = false; break; @@ -365,7 +365,7 @@ public class DefaultNominator { Thread.sleep(WAIT_TIME); } - catch(InterruptedException e) + catch (InterruptedException e) { cancelled = true; } @@ -376,7 +376,7 @@ public class DefaultNominator this); validatedCandidates.remove(component.toShortString()); - if(cancelled) + if (cancelled) return; logger.info( diff --git a/src/main/java/org/ice4j/ice/IceMediaStream.java b/src/main/java/org/ice4j/ice/IceMediaStream.java index bf7826b..894293c 100644 --- a/src/main/java/org/ice4j/ice/IceMediaStream.java +++ b/src/main/java/org/ice4j/ice/IceMediaStream.java @@ -68,6 +68,19 @@ public class IceMediaStream */ public static final String PROPERTY_PAIR_VALIDATED = "PairValidated"; + /** + * Use builder pattern to provide an immutable IceMediaStream instance. + * + * @param name the name of the media stream + * @param parentAgent the agent that is handling the session that this + * media stream is a part of + * @return IceMediaStream + */ + public static IceMediaStream build(Agent parentAgent, String name) + { + return new IceMediaStream(parentAgent, name); + } + /** * The name of this media stream. The name is equal to the value specified * in the SDP description. @@ -557,12 +570,12 @@ public class IceMediaStream { synchronized(checkList) { - for( CandidatePair pair : checkList) + for (CandidatePair pair : checkList) { - if( pair.getLocalCandidate().getTransportAddress() + if (pair.getLocalCandidate().getTransportAddress() .equals(localAddress) && pair.getRemoteCandidate().getTransportAddress() - .equals(remoteAddress) ) + .equals(remoteAddress)) { return pair; } @@ -587,12 +600,12 @@ public class IceMediaStream { synchronized(checkList) { - for( CandidatePair pair : checkList) + for (CandidatePair pair : checkList) { LocalCandidate local = pair.getLocalCandidate(); RemoteCandidate remote = pair.getRemoteCandidate(); - if(local.getUfrag().equals(remoteUFrag) + if (local.getUfrag().equals(remoteUFrag) && remote.getUfrag().equals(localUFrag)) { return pair; @@ -613,7 +626,7 @@ public class IceMediaStream synchronized (components) { - for(Component cmp : components.values()) + for (Component cmp : components.values()) num += cmp.countLocalHostCandidates(); } @@ -645,7 +658,7 @@ public class IceMediaStream { synchronized (validList) { - if(!validList.contains(pair)) + if (!validList.contains(pair)) validList.add(pair); } @@ -666,7 +679,7 @@ public class IceMediaStream { synchronized(validList) { - for(CandidatePair pair : validList) + for (CandidatePair pair : validList) { if (pair.getFoundation().equals(foundation)) return true; @@ -714,7 +727,7 @@ public class IceMediaStream */ protected boolean validListContainsAllComponents() { - for(Component cmp : getComponents()) + for (Component cmp : getComponents()) { if (getValidPair(cmp) == null) { @@ -762,9 +775,9 @@ public class IceMediaStream */ protected boolean allComponentsHaveSelected() { - for(Component component : getComponents()) + for (Component component : getComponents()) { - if(component.getSelectedPair() == null) + if (component.getSelectedPair() == null) return false; } return true; @@ -782,11 +795,11 @@ public class IceMediaStream */ protected CandidatePair getValidPair(Component component) { - synchronized(validList) + synchronized (validList) { - for(CandidatePair pair : validList) + for (CandidatePair pair : validList) { - if(pair.getParentComponent() == component) + if (pair.getParentComponent() == component) return pair; } } @@ -803,9 +816,9 @@ public class IceMediaStream */ public void addPairChangeListener(PropertyChangeListener l) { - synchronized(streamListeners) + synchronized (streamListeners) { - if(!streamListeners.contains(l)) + if (!streamListeners.contains(l)) streamListeners.add(l); } } @@ -818,7 +831,7 @@ public class IceMediaStream */ public void removePairStateChangeListener(PropertyChangeListener l) { - synchronized(streamListeners) + synchronized (streamListeners) { streamListeners.remove(l); } @@ -840,7 +853,7 @@ public class IceMediaStream { PropertyChangeListener[] ls; - synchronized(streamListeners) + synchronized (streamListeners) { ls = streamListeners.toArray( @@ -850,7 +863,7 @@ public class IceMediaStream PropertyChangeEvent ev = new PropertyChangeEvent(source, propertyName, oldValue, newValue); - for(PropertyChangeListener l : ls) + for (PropertyChangeListener l : ls) l.propertyChange(ev); } @@ -898,18 +911,4 @@ public class IceMediaStream { return remotePassword; } - - /** - * Use builder pattern to provide an immutable IceMediaStream instance. - * - * @param name the name of the media stream - * @param parentAgent the agent that is handling the session that this - * media stream is a part of - * @return IceMediaStream - */ - public static IceMediaStream build(Agent parentAgent, String name) - { - return new IceMediaStream(parentAgent, name); - } - }