style: Whitespace and braces.

This commit is contained in:
Boris Grozev 2016-12-15 10:45:43 -06:00
parent abec6b79e5
commit a1796c9bfb
2 changed files with 92 additions and 64 deletions

View File

@ -554,7 +554,7 @@ public class Agent
logger.warning("Failed to gather any host candidates!"); logger.warning("Failed to gather any host candidates!");
//in case we are not trickling, apply other harvesters here //in case we are not trickling, apply other harvesters here
if(!isTrickling()) if (!isTrickling())
{ {
harvestingStarted = true; //raise a flag to warn on a second call. harvestingStarted = true; //raise a flag to warn on a second call.
harvesters.harvest(component); harvesters.harvest(component);
@ -588,13 +588,13 @@ public class Agent
public void startCandidateTrickle(TrickleCallback trickleCallback) public void startCandidateTrickle(TrickleCallback trickleCallback)
throws IllegalStateException throws IllegalStateException
{ {
if(!isTrickling()) if (!isTrickling())
{ {
throw new IllegalStateException( throw new IllegalStateException(
"Trying to start trickling without enabling it on the agent!"); "Trying to start trickling without enabling it on the agent!");
} }
if(harvestingStarted) if (harvestingStarted)
{ {
logger.warning( logger.warning(
"Hmmm ... why are you harvesting twice? You shouldn't be!"); "Hmmm ... why are you harvesting twice? You shouldn't be!");
@ -642,7 +642,7 @@ public class Agent
//if we have received connectivity checks before RUNNING state, //if we have received connectivity checks before RUNNING state,
//trigger a check for those candidate pairs. //trigger a check for those candidate pairs.
if(this.preDiscoveredPairsQueue.size() > 0) if (this.preDiscoveredPairsQueue.size() > 0)
{ {
logger.info( logger.info(
"Trigger checks for pairs that were received before " "Trigger checks for pairs that were received before "
@ -863,7 +863,7 @@ public class Agent
? 0 ? 0
: maxCheckListSize / streamCount; : maxCheckListSize / streamCount;
for(IceMediaStream stream : streams) for (IceMediaStream stream : streams)
{ {
logger.info("Init checklist for stream " + stream.getName()); logger.info("Init checklist for stream " + stream.getName());
stream.setMaxCheckListSize(maxPerStreamSize); stream.setMaxCheckListSize(maxPerStreamSize);
@ -1252,8 +1252,10 @@ public class Agent
buff.append(" tie-breaker:").append(getTieBreaker()); buff.append(" tie-breaker:").append(getTieBreaker());
buff.append("):\n"); buff.append("):\n");
for(IceMediaStream stream : getStreams()) for (IceMediaStream stream : getStreams())
{
buff.append(stream).append("\n"); buff.append(stream).append("\n");
}
return buff.toString(); return buff.toString();
} }
@ -1282,12 +1284,14 @@ public class Agent
//in case we have already initialized our check lists we'd need to //in case we have already initialized our check lists we'd need to
//recompute pair priorities. //recompute pair priorities.
for(IceMediaStream stream : getStreams()) for (IceMediaStream stream : getStreams())
{ {
CheckList list = stream.getCheckList(); CheckList list = stream.getCheckList();
if (list != null) if (list != null)
{
list.recomputePairPriorities(); list.recomputePairPriorities();
}
} }
} }
@ -1338,12 +1342,14 @@ public class Agent
*/ */
public LocalCandidate findLocalCandidate(TransportAddress localAddress) public LocalCandidate findLocalCandidate(TransportAddress localAddress)
{ {
for(IceMediaStream stream : mediaStreams.values()) for (IceMediaStream stream : mediaStreams.values())
{ {
LocalCandidate cnd = stream.findLocalCandidate(localAddress); LocalCandidate cnd = stream.findLocalCandidate(localAddress);
if(cnd != null) if (cnd != null)
{
return cnd; return cnd;
}
} }
return null; return null;
} }
@ -1363,13 +1369,13 @@ public class Agent
TransportAddress localAddress, TransportAddress localAddress,
String ufrag) String ufrag)
{ {
for(IceMediaStream stream : mediaStreams.values()) for (IceMediaStream stream : mediaStreams.values())
{ {
for(Component c : stream.getComponents()) for (Component c : stream.getComponents())
{ {
for(LocalCandidate cnd : c.getLocalCandidates()) for (LocalCandidate cnd : c.getLocalCandidates())
{ {
if(cnd != null if (cnd != null
&& cnd.getUfrag() != null && cnd.getUfrag() != null
&& cnd.getUfrag().equals(ufrag)) && cnd.getUfrag().equals(ufrag))
{ {
@ -1394,12 +1400,14 @@ public class Agent
*/ */
public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress) public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress)
{ {
for(IceMediaStream stream : mediaStreams.values()) for (IceMediaStream stream : mediaStreams.values())
{ {
RemoteCandidate cnd = stream.findRemoteCandidate(remoteAddress); RemoteCandidate cnd = stream.findRemoteCandidate(remoteAddress);
if(cnd != null) if (cnd != null)
{
return cnd; return cnd;
}
} }
return null; return null;
} }
@ -1503,7 +1511,7 @@ public class Agent
localCandidate = findLocalCandidate(localAddress); localCandidate = findLocalCandidate(localAddress);
if(localCandidate == null) if (localCandidate == null)
{ {
logger.info("No localAddress for this incoming checks: " + logger.info("No localAddress for this incoming checks: " +
localAddress); localAddress);
@ -1529,18 +1537,18 @@ public class Agent
logger.fine("set use-candidate " + useCandidate + " for pair " + logger.fine("set use-candidate " + useCandidate + " for pair " +
triggeredPair.toShortString()); triggeredPair.toShortString());
if(useCandidate) if (useCandidate)
{ {
triggeredPair.setUseCandidateReceived(); triggeredPair.setUseCandidateReceived();
} }
synchronized(startLock) synchronized(startLock)
{ {
if(isStarted()) if (isStarted())
{ {
//we are started, which means we have the remote candidates //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. //so it's now safe to go and see whether this is a new PR cand.
if(triggeredPair.getParentComponent().getSelectedPair() == null) if (triggeredPair.getParentComponent().getSelectedPair() == null)
{ {
logger.info("Received check from " logger.info("Received check from "
+ triggeredPair.toShortString() + " triggered a check. " + triggeredPair.toShortString() + " triggered a check. "
@ -1637,7 +1645,7 @@ public class Agent
// Its state is set to Waiting [and it] is enqueued into the // Its state is set to Waiting [and it] is enqueued into the
// triggered check queue. // triggered check queue.
// //
if(triggerPair.getParentComponent().getSelectedPair() == null) if (triggerPair.getParentComponent().getSelectedPair() == null)
logger.info("Add peer CandidatePair with new reflexive " + logger.info("Add peer CandidatePair with new reflexive " +
"address to checkList: " + triggerPair); "address to checkList: " + triggerPair);
parentStream.addToCheckList(triggerPair); parentStream.addToCheckList(triggerPair);
@ -1696,7 +1704,7 @@ public class Agent
public synchronized void nominate(CandidatePair pair) public synchronized void nominate(CandidatePair pair)
throws IllegalStateException throws IllegalStateException
{ {
if(!isControlling()) if (!isControlling())
{ {
throw new IllegalStateException( throw new IllegalStateException(
"Only controlling agents can nominate pairs"); "Only controlling agents can nominate pairs");
@ -1745,13 +1753,15 @@ public class Agent
IceMediaStream parentStream = parentComponent.getParentStream(); IceMediaStream parentStream = parentComponent.getParentStream();
CheckList checkList = parentStream.getCheckList(); CheckList checkList = parentStream.getCheckList();
if( checkList.getState() == CheckListState.RUNNING ) if ( checkList.getState() == CheckListState.RUNNING )
{
checkList.handleNominationConfirmed(nominatedPair); checkList.handleNominationConfirmed(nominatedPair);
}
//Once there is at least one nominated pair in the valid list for //Once there is at least one nominated pair in the valid list for
//every component of the media stream and the state of the //every component of the media stream and the state of the
//check list is Running //check list is Running
if(parentStream.allComponentsHaveSelected() if (parentStream.allComponentsHaveSelected()
&& checkList.getState() == CheckListState.RUNNING) && checkList.getState() == CheckListState.RUNNING)
{ {
//The agent MUST change the state of processing for its check //The agent MUST change the state of processing for its check
@ -1770,21 +1780,23 @@ public class Agent
boolean allListsEnded = true; boolean allListsEnded = true;
boolean atLeastOneListSucceeded = false; boolean atLeastOneListSucceeded = false;
if(getState().isEstablished()) if (getState().isEstablished())
{
return; return;
}
List<IceMediaStream> streams = getStreams(); List<IceMediaStream> streams = getStreams();
for(IceMediaStream stream : streams) for (IceMediaStream stream : streams)
{ {
CheckListState checkListState = stream.getCheckList().getState(); CheckListState checkListState = stream.getCheckList().getState();
if(checkListState == CheckListState.RUNNING) if (checkListState == CheckListState.RUNNING)
{ {
allListsEnded = false; allListsEnded = false;
break; break;
} }
else if(checkListState == CheckListState.COMPLETED) else if (checkListState == CheckListState.COMPLETED)
{ {
logger.info("CheckList of stream " + stream.getName() + logger.info("CheckList of stream " + stream.getName() +
" is COMPLETED"); " is COMPLETED");
@ -1793,10 +1805,12 @@ public class Agent
} }
if(!allListsEnded) if (!allListsEnded)
{
return; return;
}
if(!atLeastOneListSucceeded) if (!atLeastOneListSucceeded)
{ {
//all lists ended but none succeeded. No love today ;( //all lists ended but none succeeded. No love today ;(
if (logger.isLoggable(Level.INFO)) if (logger.isLoggable(Level.INFO))
@ -1817,7 +1831,7 @@ public class Agent
//Once the state of each check list is Completed: //Once the state of each check list is Completed:
//The agent sets the state of ICE processing overall to Completed. //The agent sets the state of ICE processing overall to Completed.
if(getState() != IceProcessingState.RUNNING) if (getState() != IceProcessingState.RUNNING)
{ {
//Oh, seems like we already did this. //Oh, seems like we already did this.
return; return;
@ -1827,7 +1841,9 @@ public class Agent
// under our nose here has been observed (and not in a single instance) // under our nose here has been observed (and not in a single instance)
// So check that we did indeed just trigger the change. // So check that we did indeed just trigger the change.
if (!setState(IceProcessingState.COMPLETED)) if (!setState(IceProcessingState.COMPLETED))
{
return; return;
}
// keep ICE running (answer STUN Binding requests, send STUN Binding // keep ICE running (answer STUN Binding requests, send STUN Binding
// indications or requests) // indications or requests)
@ -1855,9 +1871,9 @@ public class Agent
{ {
List<IceMediaStream> strms = getStreams(); List<IceMediaStream> strms = getStreams();
for(IceMediaStream stream : strms) for (IceMediaStream stream : strms)
{ {
for(Component component : stream.getComponents()) for (Component component : stream.getComponents())
{ {
CandidatePair selectedPair = component.getSelectedPair(); CandidatePair selectedPair = component.getSelectedPair();
@ -1867,7 +1883,7 @@ public class Agent
buf.append(" (local ufrag ").append(getLocalUfrag()); buf.append(" (local ufrag ").append(getLocalUfrag());
buf.append("): "); buf.append("): ");
if(selectedPair == null) if (selectedPair == null)
{ {
buf.append("none (conn checks failed)"); buf.append("none (conn checks failed)");
logger.info(buf.toString()); logger.info(buf.toString());
@ -1880,7 +1896,7 @@ public class Agent
buf.append(localCnd.getType()); buf.append(localCnd.getType());
if(serverAddr != null) if (serverAddr != null)
{ {
buf.append(" (STUN server = "); buf.append(" (STUN server = ");
buf.append(serverAddr); buf.append(serverAddr);
@ -1891,7 +1907,7 @@ public class Agent
TransportAddress relayAddr TransportAddress relayAddr
= localCnd.getRelayServerAddress(); = localCnd.getRelayServerAddress();
if(relayAddr != null) if (relayAddr != null)
{ {
buf.append(" (relay = "); buf.append(" (relay = ");
buf.append(relayAddr); buf.append(relayAddr);
@ -1916,8 +1932,10 @@ public class Agent
{ {
Collection<IceMediaStream> streamsCol = mediaStreams.values(); Collection<IceMediaStream> streamsCol = mediaStreams.values();
for( IceMediaStream stream : streamsCol) for (IceMediaStream stream : streamsCol)
{
num += stream.countHostCandidates(); num += stream.countHostCandidates();
}
} }
return num; return num;
@ -2276,9 +2294,9 @@ public class Agent
while (runInStunKeepAliveThreadCondition()) while (runInStunKeepAliveThreadCondition())
{ {
for(IceMediaStream stream : getStreams()) for (IceMediaStream stream : getStreams())
{ {
for(Component component : stream.getComponents()) for (Component component : stream.getComponents())
{ {
for (CandidatePair pair : component.getKeepAlivePairs()) for (CandidatePair pair : component.getKeepAlivePairs())
{ {
@ -2304,7 +2322,9 @@ public class Agent
} }
if (!runInStunKeepAliveThreadCondition()) if (!runInStunKeepAliveThreadCondition())
{
break; break;
}
try try
{ {
@ -2430,15 +2450,15 @@ public class Agent
{ {
long harvestingTime = 0; long harvestingTime = 0;
for(CandidateHarvester harvester : harvesters) for (CandidateHarvester harvester : harvesters)
{ {
if(harvester.getClass().getName().endsWith(harvesterName)) if (harvester.getClass().getName().endsWith(harvesterName))
{ {
harvestingTime harvestingTime
= harvester.getHarvestStatistics().getHarvestDuration(); = harvester.getHarvestStatistics().getHarvestDuration();
// There may be several harvester with the same class name. // There may be several harvester with the same class name.
// Thus, returns only an active one (if any). // Thus, returns only an active one (if any).
if(harvestingTime != 0) if (harvestingTime != 0)
{ {
return harvestingTime; return harvestingTime;
} }
@ -2462,15 +2482,15 @@ public class Agent
{ {
int harvestCount; int harvestCount;
for(CandidateHarvester harvester : harvesters) for (CandidateHarvester harvester : harvesters)
{ {
if(harvester.getClass().getName().endsWith(harvesterName)) if (harvester.getClass().getName().endsWith(harvesterName))
{ {
harvestCount harvestCount
= harvester.getHarvestStatistics().getHarvestCount(); = harvester.getHarvestStatistics().getHarvestCount();
// There may be several harvester with the same class name. // There may be several harvester with the same class name.
// Thus, returns only an active one (if any). // Thus, returns only an active one (if any).
if(harvestCount != 0) if (harvestCount != 0)
{ {
return harvestCount; return harvestCount;
} }
@ -2489,7 +2509,7 @@ public class Agent
{ {
long harvestDuration = 0; long harvestDuration = 0;
for(CandidateHarvester harvester : harvesters) for (CandidateHarvester harvester : harvesters)
{ {
harvestDuration harvestDuration
+= harvester.getHarvestStatistics().getHarvestDuration(); += harvester.getHarvestStatistics().getHarvestDuration();
@ -2510,7 +2530,7 @@ public class Agent
{ {
int harvestCount = 0; int harvestCount = 0;
for(CandidateHarvester harvester : harvesters) for (CandidateHarvester harvester : harvesters)
{ {
harvestCount += harvester.getHarvestStatistics().getHarvestCount(); harvestCount += harvester.getHarvestStatistics().getHarvestCount();
} }

View File

@ -266,7 +266,7 @@ public class Component
synchronized(localCandidates) synchronized(localCandidates)
{ {
int count = 0; int count = 0;
for(Candidate<?> cand : localCandidates) for (Candidate<?> cand : localCandidates)
{ {
if ((cand.getType() == CandidateType.HOST_CANDIDATE) if ((cand.getType() == CandidateType.HOST_CANDIDATE)
&& !cand.isVirtual()) && !cand.isVirtual())
@ -361,7 +361,7 @@ public class Component
synchronized(remoteUpdateCandidates) synchronized(remoteUpdateCandidates)
{ {
if(remoteUpdateCandidates.size() == 0) if (remoteUpdateCandidates.size() == 0)
return; return;
newRemoteCandidates = new LinkedList<>(remoteUpdateCandidates); newRemoteCandidates = new LinkedList<>(remoteUpdateCandidates);
@ -370,9 +370,9 @@ public class Component
// remove UPnP base from local candidate // remove UPnP base from local candidate
LocalCandidate upnpBase = null; LocalCandidate upnpBase = null;
for(LocalCandidate lc : localCnds) for (LocalCandidate lc : localCnds)
{ {
if(lc instanceof UPNPCandidate) if (lc instanceof UPNPCandidate)
{ {
upnpBase = lc.getBase(); upnpBase = lc.getBase();
} }
@ -380,26 +380,26 @@ public class Component
checkList = new Vector<>(); checkList = new Vector<>();
for(LocalCandidate localCnd : localCnds) for (LocalCandidate localCnd : localCnds)
{ {
if(localCnd == upnpBase) if (localCnd == upnpBase)
continue; continue;
//pair each of the new remote candidates with each of our locals //pair each of the new remote candidates with each of our locals
for(RemoteCandidate remoteCnd : remoteUpdateCandidates) for (RemoteCandidate remoteCnd : remoteUpdateCandidates)
{ {
if(localCnd.canReach(remoteCnd) if (localCnd.canReach(remoteCnd)
&& remoteCnd.getTransportAddress().getPort() != 0) && remoteCnd.getTransportAddress().getPort() != 0)
{ {
// A single LocalCandidate might be/become connected // A single LocalCandidate might be/become connected
// to more more than one remote address, and that's ok // to more more than one remote address, and that's ok
// (that is, we need to form pairs with them all). // (that is, we need to form pairs with them all).
/* /*
if(localCnd.getTransport() == Transport.TCP && if (localCnd.getTransport() == Transport.TCP &&
localCnd.getIceSocketWrapper().getTCPSocket(). localCnd.getIceSocketWrapper().getTCPSocket().
isConnected()) isConnected())
{ {
if(!localCnd.getIceSocketWrapper().getTCPSocket(). if (!localCnd.getIceSocketWrapper().getTCPSocket().
getRemoteSocketAddress().equals( getRemoteSocketAddress().equals(
remoteCnd.getTransportAddress())) remoteCnd.getTransportAddress()))
{ {
@ -431,7 +431,7 @@ public class Component
Collections.sort(checkList, CandidatePair.comparator); Collections.sort(checkList, CandidatePair.comparator);
parentStream.pruneCheckList(checkList); parentStream.pruneCheckList(checkList);
if(parentStream.getCheckList().getState().equals( if (parentStream.getCheckList().getState().equals(
CheckListState.RUNNING)) CheckListState.RUNNING))
{ {
//add the updated CandidatePair list to the currently running //add the updated CandidatePair list to the currently running
@ -439,7 +439,7 @@ public class Component
CheckList streamCheckList = parentStream.getCheckList(); CheckList streamCheckList = parentStream.getCheckList();
synchronized(streamCheckList) synchronized(streamCheckList)
{ {
for(CandidatePair pair : checkList) for (CandidatePair pair : checkList)
{ {
streamCheckList.add(pair); streamCheckList.add(pair);
} }
@ -531,7 +531,7 @@ public class Component
//local candidates //local candidates
int localCandidatesCount = getLocalCandidateCount(); int localCandidatesCount = getLocalCandidateCount();
if(localCandidatesCount > 0) if (localCandidatesCount > 0)
{ {
buff.append("\n") buff.append("\n")
.append(localCandidatesCount) .append(localCandidatesCount)
@ -554,7 +554,7 @@ public class Component
//remote candidates //remote candidates
int remoteCandidatesCount = getRemoteCandidateCount(); int remoteCandidatesCount = getRemoteCandidateCount();
if(remoteCandidatesCount > 0) if (remoteCandidatesCount > 0)
{ {
buff.append("\n") buff.append("\n")
.append(remoteCandidatesCount) .append(remoteCandidatesCount)
@ -663,7 +663,7 @@ public class Component
&& (cand.getPriority() >= cand2.getPriority())) && (cand.getPriority() >= cand2.getPriority()))
{ {
localCandidates.remove(j); localCandidates.remove(j);
if(logger.isLoggable(Level.FINEST)) if (logger.isLoggable(Level.FINEST))
{ {
logger.finest( logger.finest(
"eliminating redundant cand: "+ cand2); "eliminating redundant cand: "+ cand2);
@ -905,10 +905,12 @@ public class Component
*/ */
public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress) public RemoteCandidate findRemoteCandidate(TransportAddress remoteAddress)
{ {
for(RemoteCandidate remoteCnd : remoteCandidates) for (RemoteCandidate remoteCnd : remoteCandidates)
{ {
if(remoteCnd.getTransportAddress().equals(remoteAddress)) if (remoteCnd.getTransportAddress().equals(remoteAddress))
{
return remoteCnd; return remoteCnd;
}
} }
return null; return null;
@ -955,11 +957,17 @@ public class Component
public String getName() public String getName()
{ {
if (componentID == RTP) if (componentID == RTP)
{
return "RTP"; return "RTP";
else if(componentID == RTCP) }
else if (componentID == RTCP)
{
return "RTCP"; return "RTCP";
}
else else
{
return Integer.toString(componentID); return Integer.toString(componentID);
}
} }
/** /**