From edd325a973a1dbe200a85e105a06bd2e06f863f2 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Tue, 22 Mar 2016 22:42:37 -0500 Subject: [PATCH] Manually formats (while reading the source code in the context of early DTLS support) for consistency. --- src/main/java/org/ice4j/ice/Agent.java | 17 +++--- src/main/java/org/ice4j/ice/Candidate.java | 36 +++++------ .../java/org/ice4j/ice/CandidatePair.java | 11 ++-- src/main/java/org/ice4j/ice/CheckList.java | 6 +- .../ice4j/ice/ConnectivityCheckClient.java | 60 ++++++++++--------- .../java/org/ice4j/ice/DefaultNominator.java | 2 +- .../java/org/ice4j/ice/IceMediaStream.java | 8 +-- 7 files changed, 73 insertions(+), 67 deletions(-) diff --git a/src/main/java/org/ice4j/ice/Agent.java b/src/main/java/org/ice4j/ice/Agent.java index c83acca..eb62b6b 100644 --- a/src/main/java/org/ice4j/ice/Agent.java +++ b/src/main/java/org/ice4j/ice/Agent.java @@ -707,7 +707,7 @@ public class Agent synchronized(stateListeners) { if(!stateListeners.contains(l)) - this.stateListeners.add(l); + stateListeners.add(l); } } @@ -721,7 +721,7 @@ public class Agent { synchronized(stateListeners) { - this.stateListeners.remove(l); + stateListeners.remove(l); } } @@ -1637,23 +1637,24 @@ public class Agent public synchronized void nominate(CandidatePair pair) throws IllegalStateException { - if(! isControlling() ) - throw new IllegalStateException("Only controlling agents can " - +"nominate pairs"); + if(!isControlling()) + { + throw new IllegalStateException( + "Only controlling agents can nominate pairs"); + } Component parentComponent = pair.getParentComponent(); IceMediaStream parentStream = parentComponent.getParentStream(); //If the pair is not already nominated and if its parent component //does not already contain a nominated pair - nominate it. - if(!pair.isNominated() + if (!pair.isNominated() && !parentStream.validListContainsNomineeForComponent( parentComponent)) { logger.info("verify if nominated pair answer again"); pair.nominate(); - pair.getParentComponent().getParentStream() - .getCheckList().scheduleTriggeredCheck(pair); + parentStream.getCheckList().scheduleTriggeredCheck(pair); } } diff --git a/src/main/java/org/ice4j/ice/Candidate.java b/src/main/java/org/ice4j/ice/Candidate.java index 91a14eb..9bca749 100644 --- a/src/main/java/org/ice4j/ice/Candidate.java +++ b/src/main/java/org/ice4j/ice/Candidate.java @@ -956,24 +956,24 @@ public abstract class Candidate> TransportAddress relatedAddress = null; switch (getType()) { - case SERVER_REFLEXIVE_CANDIDATE: - if(getBase() != null) - { - relatedAddress = getBase().getTransportAddress(); - } - break; - case PEER_REFLEXIVE_CANDIDATE: - if(getBase() != null) - { - relatedAddress = getBase().getTransportAddress(); - } - break; - case RELAYED_CANDIDATE: - relatedAddress = getMappedAddress(); - break; - default: - //host candidate - return null; + case SERVER_REFLEXIVE_CANDIDATE: + if(getBase() != null) + { + relatedAddress = getBase().getTransportAddress(); + } + break; + case PEER_REFLEXIVE_CANDIDATE: + if(getBase() != null) + { + relatedAddress = getBase().getTransportAddress(); + } + break; + case RELAYED_CANDIDATE: + relatedAddress = getMappedAddress(); + break; + default: + //host candidate + return null; } // Update the related candidate conforming to the related address. this.relatedCandidate = findRelatedCandidate(relatedAddress); diff --git a/src/main/java/org/ice4j/ice/CandidatePair.java b/src/main/java/org/ice4j/ice/CandidatePair.java index 81a141e..026f508 100644 --- a/src/main/java/org/ice4j/ice/CandidatePair.java +++ b/src/main/java/org/ice4j/ice/CandidatePair.java @@ -131,7 +131,6 @@ public class CandidatePair public CandidatePair(LocalCandidate localCandidate, RemoteCandidate remoteCandidate) { - this.localCandidate = localCandidate; this.remoteCandidate = remoteCandidate; @@ -449,9 +448,9 @@ public class CandidatePair CandidatePair candidatePair = (CandidatePair) obj; - //DO NOT change this method to also depend on other pair properties - //because the Conn Check Client counts on it only using the candidates - //for comparisons. + // XXX DO NOT change this method to also depend on other pair properties + // because ConnectivityCheckClient counts on it only using the + // candidates for comparisons. return localCandidate.equals(candidatePair.localCandidate) && remoteCandidate.equals(candidatePair.remoteCandidate); @@ -616,8 +615,8 @@ public class CandidatePair getParentComponent().getParentStream().firePairPropertyChange( this, IceMediaStream.PROPERTY_PAIR_NOMINATED, - false, - true); + /* oldValue */ false, + /* newValue */ true); } /** diff --git a/src/main/java/org/ice4j/ice/CheckList.java b/src/main/java/org/ice4j/ice/CheckList.java index e939324..8e23779 100644 --- a/src/main/java/org/ice4j/ice/CheckList.java +++ b/src/main/java/org/ice4j/ice/CheckList.java @@ -383,9 +383,9 @@ public class CheckList return; } - logger.info("Selected pair for stream " + - cmp.toShortString() + ": " + - nominatedPair.toShortString()); + logger.info( + "Selected pair for stream " + cmp.toShortString() + ": " + + nominatedPair.toShortString()); cmp.setSelectedPair(nominatedPair); diff --git a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java index e5895bb..5cefdbc 100644 --- a/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/main/java/org/ice4j/ice/ConnectivityCheckClient.java @@ -248,7 +248,7 @@ class ConnectivityCheckClient //if we are the controlling agent then we need to indicate our //nominated pairs. - if(candidatePair.isNominated()) + if (candidatePair.isNominated()) { logger.fine( "Add USE-CANDIDATE in check for: " @@ -485,7 +485,7 @@ class ConnectivityCheckClient TransportAddress mappedAddress = null; - if(! response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS)) + if (!response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS)) { logger.fine("Received a success response with no " + "XOR_MAPPED_ADDRESS attribute."); @@ -496,14 +496,14 @@ class ConnectivityCheckClient } XorMappedAddressAttribute mappedAddressAttr - = (XorMappedAddressAttribute)response - .getAttribute(Attribute.XOR_MAPPED_ADDRESS); + = (XorMappedAddressAttribute) + response.getAttribute(Attribute.XOR_MAPPED_ADDRESS); - mappedAddress = mappedAddressAttr - .getAddress(response.getTransactionID()); + mappedAddress + = mappedAddressAttr.getAddress(response.getTransactionID()); // XXX AddressAttribute always returns UDP based TransportAddress - if(checkedPair.getLocalCandidate().getTransport() == Transport.TCP) + if (checkedPair.getLocalCandidate().getTransport() == Transport.TCP) { mappedAddress = new TransportAddress( @@ -514,8 +514,7 @@ class ConnectivityCheckClient LocalCandidate validLocalCandidate = null; - validLocalCandidate = parentAgent - .findLocalCandidate(mappedAddress); + validLocalCandidate = parentAgent.findLocalCandidate(mappedAddress); RemoteCandidate validRemoteCandidate = checkedPair.getRemoteCandidate(); @@ -523,7 +522,7 @@ class ConnectivityCheckClient // response. If the transport address does not match any of the // local candidates that the agent knows about, the mapped address // represents a new candidate -- a peer reflexive candidate. - if ( validLocalCandidate == null) + if (validLocalCandidate == null) { //Like other candidates, PEER-REFLEXIVE candidates have a type, //base, priority, and foundation. They are computed as follows: @@ -557,9 +556,12 @@ class ConnectivityCheckClient //generated from it momentarily validLocalCandidate = peerReflexiveCandidate; - if(checkedPair.getParentComponent().getSelectedPair() == null) - logger.info("Receive a peer-reflexive candidate: " + - peerReflexiveCandidate.getTransportAddress()); + if (checkedPair.getParentComponent().getSelectedPair() == null) + { + logger.info( + "Receive a peer-reflexive candidate: " + + peerReflexiveCandidate.getTransportAddress()); + } } //check if the resulting valid pair was already in our check lists. @@ -588,27 +590,27 @@ class ConnectivityCheckClient // (for the same check) from other peer come at the very same time, that // we will trigger the nominationConfirmed (that will pass the pair as // as selected if it is the first time). - synchronized(checkedPair) + synchronized (checkedPair) { //The agent sets the state of the pair that *generated* the check to //Succeeded. Note that, the pair which *generated* the check may be //different than the valid pair constructed above - if(checkedPair.getParentComponent().getSelectedPair() == null) + if (checkedPair.getParentComponent().getSelectedPair() == null) logger.info("Pair succeeded: " + checkedPair.toShortString()); checkedPair.setStateSucceeded(); } - if(! validPair.isValid()) + if (!validPair.isValid()) { - if(validPair.getParentComponent().getSelectedPair() == null) + if (validPair.getParentComponent().getSelectedPair() == null) logger.info("Pair validated: " + validPair.toShortString()); parentAgent.validatePair(validPair); } //The agent changes the states for all other Frozen pairs for the //same media stream and same foundation to Waiting. - IceMediaStream parentStream = checkedPair.getParentComponent() - .getParentStream(); + IceMediaStream parentStream + = checkedPair.getParentComponent().getParentStream(); synchronized(this) { @@ -616,10 +618,14 @@ class ConnectivityCheckClient = new Vector<>(parentStream.getCheckList()); for(CandidatePair pair : parentCheckList) - if ((pair.getState() == CandidatePairState.FROZEN) + { + if (pair.getState() == CandidatePairState.FROZEN && checkedPair.getFoundation().equals( pair.getFoundation())) + { pair.setStateWaiting(); + } + } } // The agent examines the check list for all other streams in turn. If @@ -636,7 +642,7 @@ class ConnectivityCheckClient synchronized (checkList) { - for(CandidatePair pair : checkList) + for (CandidatePair pair : checkList) { if (parentStream.validListContainsFoundation( pair.getFoundation()) @@ -652,7 +658,7 @@ class ConnectivityCheckClient //foundation, and for each group, sets the state of the pair with //the lowest component ID to Waiting. If there is more than one //such pair, the one with the highest priority is used. - if(checkList.isFrozen()) + if (checkList.isFrozen()) checkList.computeInitialCheckListPairStates(); if (wasFrozen) @@ -663,7 +669,7 @@ class ConnectivityCheckClient } } - if(validPair.getParentComponent().getSelectedPair() == null) + if (validPair.getParentComponent().getSelectedPair() == null) { logger.info("IsControlling: " + parentAgent.isControlling() + " USE-CANDIDATE:" + @@ -674,8 +680,8 @@ class ConnectivityCheckClient //If the agent was a controlling agent, and it had included a USE- //CANDIDATE attribute in the Binding request, the valid pair generated //from that check has its nominated flag set to true. - if((parentAgent.isControlling() - && request.containsAttribute(Attribute.USE_CANDIDATE))) + if (parentAgent.isControlling() + && request.containsAttribute(Attribute.USE_CANDIDATE)) { if(validPair.getParentComponent().getSelectedPair() == null) { @@ -695,7 +701,7 @@ 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.isControlling() && checkedPair.useCandidateReceived() && !checkedPair.isNominated()) { @@ -704,7 +710,7 @@ class ConnectivityCheckClient logger.info( "Nomination confirmed for pair: " + validPair.toShortString()); - parentAgent.nominationConfirmed( checkedPair ); + parentAgent.nominationConfirmed(checkedPair); } else { diff --git a/src/main/java/org/ice4j/ice/DefaultNominator.java b/src/main/java/org/ice4j/ice/DefaultNominator.java index c3ee922..dea47f7 100644 --- a/src/main/java/org/ice4j/ice/DefaultNominator.java +++ b/src/main/java/org/ice4j/ice/DefaultNominator.java @@ -322,7 +322,7 @@ public class DefaultNominator } } - if(allFailed && !pair.isNominated()) + if (allFailed && !pair.isNominated()) { // all other pairs are failed to do not waste time, cancel // timer and nominate ourself (the relayed candidate). diff --git a/src/main/java/org/ice4j/ice/IceMediaStream.java b/src/main/java/org/ice4j/ice/IceMediaStream.java index 548601a..73f8658 100644 --- a/src/main/java/org/ice4j/ice/IceMediaStream.java +++ b/src/main/java/org/ice4j/ice/IceMediaStream.java @@ -690,9 +690,9 @@ public class IceMediaStream */ protected boolean validListContainsNomineeForComponent(Component component) { - synchronized(validList) + synchronized (validList) { - for(CandidatePair pair : validList) + for (CandidatePair pair : validList) { if (pair.isNominated() && pair.getParentComponent() == component) @@ -742,9 +742,9 @@ public class IceMediaStream synchronized (validList) { - for(CandidatePair pair : validList) + for (CandidatePair pair : validList) { - if(pair.isNominated()) + if (pair.isNominated()) components.remove(pair.getParentComponent()); } }