Merge pull request #56 from jitsi/early-dtls

Fix early DTLS
This commit is contained in:
bgrozev 2016-03-28 14:52:04 -05:00
commit 2014cb9fef
58 changed files with 338 additions and 313 deletions

View File

@ -245,7 +245,7 @@ public class StackProperties
String[] parts = str.split(regex);
// Remove mal-formatted entries.
List<String> res = new ArrayList<String>();
List<String> res = new ArrayList<>();
for (String s : parts)
if (s != null && s.trim().length() != 0)
res.add(s);

View File

@ -74,14 +74,14 @@ public abstract class IceControlAttribute
// the attributeValue array
// Reading in the network byte order (Big-Endian)
tieBreaker = ((attributeValue[offset++] & 0xffl) << 56)
| ((attributeValue[offset++] & 0xffl) << 48)
| ((attributeValue[offset++] & 0xffl) << 40)
| ((attributeValue[offset++] & 0xffl) << 32)
| ((attributeValue[offset++] & 0xffl) << 24)
| ((attributeValue[offset++] & 0xffl) << 16)
| ((attributeValue[offset++] & 0xffl) << 8)
| (attributeValue[offset++] & 0xffl);
tieBreaker = ((attributeValue[offset++] & 0xffL) << 56)
| ((attributeValue[offset++] & 0xffL) << 48)
| ((attributeValue[offset++] & 0xffL) << 40)
| ((attributeValue[offset++] & 0xffL) << 32)
| ((attributeValue[offset++] & 0xffL) << 24)
| ((attributeValue[offset++] & 0xffL) << 16)
| ((attributeValue[offset++] & 0xffL) << 8)
| (attributeValue[offset] & 0xffL);
}
/**

View File

@ -144,7 +144,7 @@ public class LifetimeAttribute
throw new StunException("length invalid");
}
lifetime = ((attributeValue[offset + 0] << 24) & 0xff000000) +
lifetime = ((attributeValue[offset] << 24) & 0xff000000) +
((attributeValue[offset + 1] << 16) & 0x00ff0000) +
((attributeValue[offset + 2] << 8) & 0x0000ff00) +
(attributeValue[offset + 3] & 0x000000ff);

View File

@ -131,7 +131,7 @@ public class ReservationTokenAttribute
byte[] copy = new byte[reservationToken.length];
System.arraycopy(reservationToken, 0, copy, 0, reservationToken.length);
return reservationToken;
return copy;
}
/**
@ -196,8 +196,8 @@ public class ReservationTokenAttribute
for(int i = 0; i < b; i++)
{
token.reservationToken[i] = (byte)((left >> (i * 8)) & 0xFFl);
token.reservationToken[i + b] = (byte)((right >> (i * 8)) & 0xFFl);
token.reservationToken[i] = (byte)((left >> (i * 8)) & 0xFFL);
token.reservationToken[i + b] = (byte)((right >> (i * 8)) & 0xFFL);
}
//calculate hashcode for Hashtable storage.

View File

@ -121,7 +121,7 @@ public class SoftwareAttribute
byte[] copy = new byte[software.length];
System.arraycopy(software, 0, copy, 0, software.length);
return software;
return copy;
}
/**

View File

@ -52,7 +52,7 @@ public class UnknownAttributesAttribute extends Attribute
/**
* A list of attribute types that were not understood by the server.
*/
private ArrayList<Character> unknownAttributes = new ArrayList<Character>();
private ArrayList<Character> unknownAttributes = new ArrayList<>();
/**
* Constructor.
@ -100,7 +100,7 @@ public class UnknownAttributesAttribute extends Attribute
//some attributes may be repeated for padding
//(packet length should be divisable by 4)
if(!contains(attributeID))
unknownAttributes.add(new Character(attributeID));
unknownAttributes.add(attributeID);
}
/**
@ -110,7 +110,7 @@ public class UnknownAttributesAttribute extends Attribute
*/
public boolean contains(char attributeID)
{
return unknownAttributes.contains(new Character(attributeID));
return unknownAttributes.contains(attributeID);
}
/**
@ -140,7 +140,7 @@ public class UnknownAttributesAttribute extends Attribute
*/
public char getAttribute(int index )
{
return (unknownAttributes.get(index)).charValue();
return unknownAttributes.get(index);
}
/**
@ -164,7 +164,7 @@ public class UnknownAttributesAttribute extends Attribute
Iterator<Character> attributes = getAttributes();
while (attributes.hasNext())
{
char att = attributes.next().charValue();
char att = attributes.next();
binValue[offset++] = (byte)(att >> 8);
binValue[offset++] = (byte)(att & 0x00FF);
}

View File

@ -27,7 +27,6 @@ import java.util.logging.*;
import org.ice4j.*;
import org.ice4j.ice.harvest.*;
import org.ice4j.ice.harvest.TrickleCallback;
import org.ice4j.stack.*;
/**
@ -108,7 +107,7 @@ public class Agent
* This map preserves the insertion order of the media streams.
*/
private final Map<String, IceMediaStream> mediaStreams
= new LinkedHashMap<String, IceMediaStream>();
= new LinkedHashMap<>();
/**
* The candidate harvester that we use to gather candidate on the local
@ -122,8 +121,7 @@ public class Agent
* harvest candidates synchronously, and previously to harvesting by
* {@link #harvesters}.
*/
private final List<CandidateHarvester> hostHarvesters
= new LinkedList<CandidateHarvester>();
private final List<CandidateHarvester> hostHarvesters = new LinkedList<>();
/**
* The set of harvesters (i.e. STUN, TURN, and others) that the agent should
@ -166,7 +164,7 @@ public class Agent
* the necessary triggered checks.
*/
private final List<CandidatePair> preDiscoveredPairsQueue
= new LinkedList<CandidatePair>();
= new LinkedList<>();
/**
* The lock that we use while starting connectivity establishment.
@ -228,7 +226,7 @@ public class Agent
* Agent} and following its changes of state.
*/
private final List<PropertyChangeListener> stateListeners
= new LinkedList<PropertyChangeListener>();
= new LinkedList<>();
/**
* The <tt>StunStack</tt> used by this <tt>Agent</tt>.
@ -424,6 +422,28 @@ public class Agent
return component;
}
/**
* Initializes a new {@link CandidatePair} instance from a
* {@link LocalCandidate} and a {@link RemoteCandidate}. The method
* represents a {@code CandidatePair} factory and is preferable to
* explicitly calling the {@code CandidatePair} constructor because it
* allows this {@code Agent} to easily track the initialization of its
* {@code CandidatePair}s.
*
* @param local the {@code LocalCandidate} to initialize the new instance
* with
* @param remote the {@code RemoteCandidate} to initialize the new instance
* with
* @return a new {@code CandidatePair} instance initializes with
* {@code local} and {@code remote}
*/
protected CandidatePair createCandidatePair(
LocalCandidate local,
RemoteCandidate remote)
{
return new CandidatePair(local, remote);
}
/**
* Uses all <tt>CandidateHarvester</tt>s currently registered with this
* <tt>Agent</tt> to obtain whatever addresses they can discover.
@ -525,7 +545,7 @@ public class Agent
}
//create a list of components and start harvesting
List<Component> components = new LinkedList<Component>();
List<Component> components = new LinkedList<>();
for (IceMediaStream stream : getStreams())
{
@ -571,14 +591,12 @@ public class Agent
"Trigger checks for pairs that were received before "
+ "running state");
Iterator<CandidatePair> it = preDiscoveredPairsQueue.iterator();
while(it.hasNext())
for (CandidatePair cp : preDiscoveredPairsQueue)
{
triggerCheck(it.next());
triggerCheck(cp);
}
this.preDiscoveredPairsQueue.clear();
preDiscoveredPairsQueue.clear();
}
connCheckClient.startChecks();
@ -663,9 +681,9 @@ public class Agent
*/
public boolean isOver()
{
return state == IceProcessingState.COMPLETED
|| state == IceProcessingState.TERMINATED
|| state == IceProcessingState.FAILED;
IceProcessingState state = getState();
return (state != null) && state.isOver();
}
/**
@ -689,7 +707,7 @@ public class Agent
synchronized(stateListeners)
{
if(!stateListeners.contains(l))
this.stateListeners.add(l);
stateListeners.add(l);
}
}
@ -703,7 +721,7 @@ public class Agent
{
synchronized(stateListeners)
{
this.stateListeners.remove(l);
stateListeners.remove(l);
}
}
@ -1042,7 +1060,7 @@ public class Agent
{
synchronized(mediaStreams)
{
return new LinkedList<String>(mediaStreams.keySet());
return new LinkedList<>(mediaStreams.keySet());
}
}
@ -1057,7 +1075,7 @@ public class Agent
{
synchronized(mediaStreams)
{
return new LinkedList<IceMediaStream>(mediaStreams.values());
return new LinkedList<>(mediaStreams.values());
}
}
@ -1449,7 +1467,7 @@ public class Agent
ufrag);
CandidatePair triggeredPair
= new CandidatePair(localCandidate, remoteCandidate);
= createCandidatePair(localCandidate, remoteCandidate);
logger.fine("set use-candidate " + useCandidate + " for pair " +
triggeredPair.toShortString());
@ -1619,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);
}
}

View File

@ -62,7 +62,7 @@ public abstract class Candidate<T extends Candidate<?>>
/**
* The transport address represented by this candidate.
*/
private TransportAddress transportAddress = null;
private final TransportAddress transportAddress;
/**
* The type of this candidate. At this point the ICE specification (and
@ -70,7 +70,7 @@ public abstract class Candidate<T extends Candidate<?>>
* server reflexive, peer reflexive and relayed candidates. Others may be
* added in the future.
*/
private CandidateType candidateType = null;
private CandidateType candidateType;
/**
* An arbitrary string that is the same for two candidates
@ -341,6 +341,20 @@ public abstract class Candidate<T extends Candidate<?>>
&& getFoundation().equals(candidate.getFoundation());
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
// Even if the following hashCode algorithm has drawbacks because of it
// simplicity, it is better than nothing because at least it allows
// Candidate and, respectively, CandidatePair to be used as HashMap
// keys.
return
getParentComponent().hashCode() + getTransportAddress().hashCode();
}
/**
* Returns a reference to the <tt>Component</tt> that this candidate belongs
* to.
@ -956,24 +970,24 @@ public abstract class Candidate<T extends 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);

View File

@ -131,7 +131,6 @@ public class CandidatePair
public CandidatePair(LocalCandidate localCandidate,
RemoteCandidate remoteCandidate)
{
this.localCandidate = localCandidate;
this.remoteCandidate = remoteCandidate;
@ -449,14 +448,28 @@ 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);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
// Even if the following hashCode algorithm has drawbacks because of it
// simplicity, it is better than nothing because at least it allows
// CandidatePair to be used as a HashMap key.
// XXX While localCandidate is not final, the parentComponent is
// supposedly effectively final.
return getLocalCandidate().getParentComponent().hashCode();
}
/**
* Returns a String representation of this <tt>CandidatePair</tt>.
*
@ -616,8 +629,8 @@ public class CandidatePair
getParentComponent().getParentStream().firePairPropertyChange(
this,
IceMediaStream.PROPERTY_PAIR_NOMINATED,
false,
true);
/* oldValue */ false,
/* newValue */ true);
}
/**

View File

@ -56,8 +56,7 @@ public class CheckList
* A pair would get into a triggered check queue as soon as we receive
* a check on its local candidate.
*/
private final List<CandidatePair> triggeredCheckQueue
= new LinkedList<CandidatePair>();
private final List<CandidatePair> triggeredCheckQueue = new LinkedList<>();
/**
* A reference to the {@link IceMediaStream} that we belong to.
@ -69,14 +68,14 @@ public class CheckList
* Agent} and following its changes of state.
*/
private final List<PropertyChangeListener> stateListeners
= new LinkedList<PropertyChangeListener>();
= new LinkedList<>();
/**
* Contains {@link PropertyChangeListener}s registered with this {@link
* Agent} and following its changes of state.
*/
private final List<PropertyChangeListener> checkListeners
= new LinkedList<PropertyChangeListener>();
= new LinkedList<>();
/**
* The name of the {@link PropertyChangeEvent} that we use to deliver
@ -297,8 +296,7 @@ public class CheckList
*/
protected synchronized void computeInitialCheckListPairStates()
{
Map<String, CandidatePair> pairsToWait
= new Hashtable<String, CandidatePair>();
Map<String, CandidatePair> pairsToWait = new Hashtable<>();
//first, determine the pairs that we'd need to put in the waiting state.
for(CandidatePair pair : this)
@ -385,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);
@ -508,8 +506,7 @@ public class CheckList
synchronized(stateListeners)
{
listenersCopy
= new LinkedList<PropertyChangeListener>(stateListeners);
listenersCopy = new LinkedList<>(stateListeners);
}
PropertyChangeEvent evt = new PropertyChangeEvent(
@ -564,8 +561,7 @@ public class CheckList
synchronized(checkListeners)
{
listenersCopy
= new LinkedList<PropertyChangeListener>(checkListeners);
listenersCopy = new LinkedList<>(checkListeners);
}
PropertyChangeEvent evt = new PropertyChangeEvent(

View File

@ -73,21 +73,19 @@ public class Component
/**
* The list locally gathered candidates for this media stream.
*/
private final List<LocalCandidate> localCandidates
= new LinkedList<LocalCandidate>();
private final List<LocalCandidate> localCandidates = new LinkedList<>();
/**
* The list of candidates that the peer agent sent for this stream.
*/
private final List<RemoteCandidate> remoteCandidates
= new LinkedList<RemoteCandidate>();
private final List<RemoteCandidate> remoteCandidates = new LinkedList<>();
/**
* The list of candidates that the peer agent sent for this stream after
* connectivity establishment.
*/
private final List<RemoteCandidate> remoteUpdateCandidates =
new LinkedList<RemoteCandidate>();
private final List<RemoteCandidate> remoteUpdateCandidates
= new LinkedList<>();
/**
* A <tt>Comparator</tt> that we use for sorting <tt>Candidate</tt>s by
@ -185,7 +183,7 @@ public class Component
{
synchronized(localCandidates)
{
return new ArrayList<LocalCandidate>(localCandidates);
return new ArrayList<>(localCandidates);
}
}
@ -257,8 +255,7 @@ public class Component
logger.info("Update remote candidate for " + toShortString() + ": " +
candidate.getTransportAddress());
List<RemoteCandidate> existingCandidates
= new LinkedList<RemoteCandidate>();
List<RemoteCandidate> existingCandidates = new LinkedList<>();
synchronized (remoteCandidates)
{
existingCandidates.addAll(remoteCandidates);
@ -292,7 +289,7 @@ public class Component
*/
public void updateRemoteCandidates()
{
List<CandidatePair> checkList = null;
List<CandidatePair> checkList;
List<RemoteCandidate> newRemoteCandidates;
synchronized(remoteUpdateCandidates)
@ -300,8 +297,7 @@ public class Component
if(remoteUpdateCandidates.size() == 0)
return;
newRemoteCandidates
= new LinkedList<RemoteCandidate>(remoteUpdateCandidates);
newRemoteCandidates = new LinkedList<>(remoteUpdateCandidates);
List<LocalCandidate> localCnds = getLocalCandidates();
@ -315,7 +311,7 @@ public class Component
}
}
checkList = new Vector<CandidatePair>();
checkList = new Vector<>();
for(LocalCandidate localCnd : localCnds)
{
@ -346,7 +342,9 @@ public class Component
*/
CandidatePair pair
= new CandidatePair(localCnd, remoteCnd);
= getParentStream()
.getParentAgent()
.createCandidatePair(localCnd, remoteCnd);
logger.info("new Pair added: " + pair.toShortString());
checkList.add(pair);
}
@ -391,7 +389,7 @@ public class Component
{
synchronized(remoteCandidates)
{
return new ArrayList<RemoteCandidate>(remoteCandidates);
return new ArrayList<>(remoteCandidates);
}
}
@ -459,15 +457,17 @@ public class Component
StringBuffer buff
= new StringBuffer("Component id=").append(getComponentID());
buff.append(" parent stream=" + getParentStream().getName());
buff.append(" parent stream=").append(getParentStream().getName());
//local candidates
int localCandidatesCount = getLocalCandidateCount();
if(localCandidatesCount > 0)
{
buff.append("\n" + localCandidatesCount + " Local candidates:");
buff.append("\ndefault candidate: " + getDefaultCandidate());
buff.append("\n")
.append(localCandidatesCount)
.append(" Local candidates:");
buff.append("\ndefault candidate: ").append(getDefaultCandidate());
synchronized(localCandidates)
{
@ -487,14 +487,16 @@ public class Component
if(remoteCandidatesCount > 0)
{
buff.append("\n" + remoteCandidatesCount + " Remote candidates:");
buff.append("\ndefault remote candidate: "
+ getDefaultRemoteCandidate());
buff.append("\n")
.append(remoteCandidatesCount)
.append(" Remote candidates:");
buff.append("\ndefault remote candidate: ")
.append(getDefaultRemoteCandidate());
synchronized(remoteCandidates)
{
for (RemoteCandidate cand : remoteCandidates)
{
buff.append("\n" + cand.toString());
buff.append("\n").append(cand);
}
}
}
@ -701,12 +703,8 @@ public class Component
{
synchronized(localCandidates)
{
Iterator<LocalCandidate> localCandsIter = localCandidates.iterator();
while (localCandsIter.hasNext())
for (LocalCandidate cand : localCandidates)
{
LocalCandidate cand = localCandsIter.next();
if ((defaultCandidate == null)
|| (defaultCandidate.getDefaultPreference()
< cand.getDefaultPreference()))

View File

@ -57,13 +57,13 @@ class ConnectivityCheckClient
/**
* The {@link PaceMaker}s that are currently running checks in this client.
*/
private final List<PaceMaker> paceMakers = new LinkedList<PaceMaker>();
private final List<PaceMaker> paceMakers = new LinkedList<>();
/**
* Timer that is used to let some seconds before a CheckList is considered
* as FAILED.
*/
private Map<String, Timer> timers = new HashMap<String, Timer>();
private Map<String, Timer> timers = new HashMap<>();
/**
* A flag that determines whether we have received a STUN response or not.
@ -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.
@ -575,7 +577,9 @@ class ConnectivityCheckClient
// by a STUN connectivity check.
CandidatePair validPair
= (existingPair == null)
? new CandidatePair(validLocalCandidate, validRemoteCandidate)
? parentAgent.createCandidatePair(
validLocalCandidate,
validRemoteCandidate)
: existingPair;
// we synchronize here because the same pair object can be processed (in
@ -586,38 +590,42 @@ 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)
{
Vector<CandidatePair> parentCheckList
= new Vector<CandidatePair>(parentStream.getCheckList());
= 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
@ -634,7 +642,7 @@ class ConnectivityCheckClient
synchronized (checkList)
{
for(CandidatePair pair : checkList)
for (CandidatePair pair : checkList)
{
if (parentStream.validListContainsFoundation(
pair.getFoundation())
@ -650,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)
@ -661,7 +669,7 @@ class ConnectivityCheckClient
}
}
if(validPair.getParentComponent().getSelectedPair() == null)
if (validPair.getParentComponent().getSelectedPair() == null)
{
logger.info("IsControlling: " + parentAgent.isControlling() +
" USE-CANDIDATE:" +
@ -672,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)
{
@ -693,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())
{
@ -702,7 +710,7 @@ class ConnectivityCheckClient
logger.info(
"Nomination confirmed for pair: "
+ validPair.toShortString());
parentAgent.nominationConfirmed( checkedPair );
parentAgent.nominationConfirmed(checkedPair);
}
else
{

View File

@ -50,8 +50,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.
*/
private final Map<String, TimerTask> validatedCandidates
= new HashMap<String, TimerTask>();
private final Map<String, TimerTask> validatedCandidates = new HashMap<>();
/**
* Creates a new instance of this nominator using <tt>parentAgent</tt> as
@ -323,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).

View File

@ -44,7 +44,7 @@ public class FoundationsRegistry
* Contains mappings between a type+baseIP+server+transport
* <tt>String</tt>s and the foundation that has been assigned to them.
*/
private Map<String, String> foundations = new Hashtable<String, String>();
private Map<String, String> foundations = new Hashtable<>();
/**
* Assigns to <tt>candidate</tt> the foundation that corresponds to its

View File

@ -75,8 +75,7 @@ public class IceMediaStream
* address; a media stream may require multiple components, each of which
* has to work for the media stream as a whole to work.
*/
private final Map<Integer, Component> components
= new LinkedHashMap<Integer, Component>();
private final Map<Integer, Component> components = new LinkedHashMap<>();
/**
* An ordered set of candidate pairs for a media stream that have been
@ -84,8 +83,7 @@ public class IceMediaStream
* start of ICE processing, and fills as checks are performed, resulting in
* valid candidate pairs.
*/
private final TreeSet<CandidatePair> validList
= new TreeSet<CandidatePair>();
private final TreeSet<CandidatePair> validList = new TreeSet<>();
/**
* The id that was last assigned to a component. The next id that we give
@ -110,7 +108,7 @@ public class IceMediaStream
* Agent} and following the various events it may be generating.
*/
private final List<PropertyChangeListener> streamListeners
= new LinkedList<PropertyChangeListener>();
= new LinkedList<>();
/**
* The maximum number of candidate pairs that we should have in our check
@ -163,9 +161,7 @@ public class IceMediaStream
synchronized (components)
{
component = new Component(++lastComponentID, this);
components.put(
Integer.valueOf(component.getComponentID()),
component);
components.put(component.getComponentID(), component);
}
return component;
@ -231,7 +227,7 @@ public class IceMediaStream
{
synchronized(components)
{
return new ArrayList<Component>(components.values());
return new ArrayList<>(components.values());
}
}
@ -261,7 +257,7 @@ public class IceMediaStream
{
synchronized(components)
{
return new ArrayList<Integer>(components.keySet());
return new ArrayList<>(components.keySet());
}
}
@ -398,8 +394,9 @@ public class IceMediaStream
if(localCnd.canReach(remoteCnd)
&& remoteCnd.getTransportAddress().getPort() != 0)
{
CandidatePair pair = new CandidatePair(localCnd,
remoteCnd);
CandidatePair pair
= getParentAgent()
.createCandidatePair(localCnd, remoteCnd);
checkList.add(pair);
}
}
@ -436,8 +433,7 @@ public class IceMediaStream
{
//a list that we only use for storing pairs that we've already gone
//through. The list is destroyed at the end of this method.
List<CandidatePair> tmpCheckList
= new ArrayList<CandidatePair>(checkList.size());
List<CandidatePair> tmpCheckList = new ArrayList<>(checkList.size());
Iterator<CandidatePair> ckListIter = checkList.iterator();
@ -694,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)
@ -746,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());
}
}

View File

@ -35,6 +35,7 @@ package org.ice4j.ice;
* refer to with "Terminated".
*
* @author Emil Ivov
* @author Lyubomir Marinov
*/
public enum IceProcessingState
{
@ -99,6 +100,21 @@ public enum IceProcessingState
return stateName;
}
/**
* Determines whether an {@link Agent} in this state has finished its ICE
* processing.
*
* @return {@code true} if an {@code Agent} in this state has finished its
* ICE processing; otherwise, {@code false}
*/
public boolean isOver()
{
return
COMPLETED.equals(this)
|| FAILED.equals(this)
|| TERMINATED.equals(this);
}
/**
* Returns <tt>true</tt> iff the state is one in which a connection
* has been established, that is either <tt>COMPLETED</tt> or

View File

@ -707,8 +707,7 @@ public class NetworkUtils
{
Method method = iface.getClass().getMethod("isLoopback");
return ((Boolean)method.invoke(iface, new Object[]{}))
.booleanValue();
return (Boolean) method.invoke(iface);
}
catch(Throwable t)
{
@ -739,7 +738,7 @@ public class NetworkUtils
{
Method method = iface.getClass().getMethod("isUp");
return ((Boolean)method.invoke(iface)).booleanValue();
return (Boolean) method.invoke(iface);
}
catch(Throwable t)
{
@ -769,7 +768,7 @@ public class NetworkUtils
{
Method method = iface.getClass().getMethod("isVirtual");
return ((Boolean)method.invoke(iface)).booleanValue();
return (Boolean) method.invoke(iface);
}
catch(Throwable t)
{

View File

@ -38,8 +38,7 @@ public class TcpHostCandidate
/**
* List of <tt>accept</tt>ed sockets for this <tt>TcpHostCandidate</tt>.
*/
private final List<IceSocketWrapper> sockets
= new LinkedList<IceSocketWrapper>();
private final List<IceSocketWrapper> sockets = new LinkedList<>();
/**
* Initializes a new <tt>TcpHostCandidate</tt>.

View File

@ -44,7 +44,7 @@ public class CandidateHarvesterSet
* <tt>Set</tt>.
*/
private final Collection<CandidateHarvesterSetElement> elements
= new LinkedList<CandidateHarvesterSetElement>();
= new LinkedList<>();
/**
* A pool of thread used for gathering process.
@ -95,7 +95,7 @@ public class CandidateHarvesterSet
*/
public void harvest(Component component)
{
harvest(Arrays.asList(new Component[]{component}), null);
harvest(Arrays.asList(component), null);
}
@ -145,8 +145,7 @@ public class CandidateHarvesterSet
* Start asynchronously executing the
* CandidateHarvester#harvest(Component) method of the harvesters.
*/
Map<CandidateHarvesterSetTask, Future<?>> tasks
= new HashMap<CandidateHarvesterSetTask, Future<?>>();
Map<CandidateHarvesterSetTask, Future<?>> tasks = new HashMap<>();
while (true)
{
@ -171,7 +170,7 @@ public class CandidateHarvesterSet
synchronized (components)
{
componentsCopy = new ArrayList<Component>(components);
componentsCopy = new ArrayList<>(components);
}
// Asynchronously start gathering candidates using the harvester.
@ -194,7 +193,7 @@ public class CandidateHarvesterSet
= taskIter.next();
Future<?> future = task.getValue();
while (true)
do
{
try
{
@ -232,9 +231,9 @@ public class CandidateHarvesterSet
}
catch (InterruptedException ie)
{
continue;
}
}
while (true);
taskIter.remove();
}
}

View File

@ -194,7 +194,7 @@ public class HostCandidateHarvester
}
if (allowedAddresses == null)
allowedAddresses = new ArrayList<InetAddress>();
allowedAddresses = new ArrayList<>();
allowedAddresses.add(address);
}
@ -220,7 +220,7 @@ public class HostCandidateHarvester
}
if (blockedAddresses == null)
blockedAddresses = new ArrayList<InetAddress>();
blockedAddresses = new ArrayList<>();
blockedAddresses.add(address);
}

View File

@ -84,7 +84,7 @@ public class MappingCandidateHarvester
* Report the LocalCandidates gathered by this CandidateHarvester so
* that the harvest is sure to be considered successful.
*/
Collection<LocalCandidate> candidates = new HashSet<LocalCandidate>();
Collection<LocalCandidate> candidates = new HashSet<>();
for (Candidate<?> cand : component.getLocalCandidates())
{

View File

@ -85,10 +85,9 @@ public class SinglePortUdpHarvester
public static List<SinglePortUdpHarvester>
createHarvesters(int port)
{
List<SinglePortUdpHarvester> harvesters
= new LinkedList<SinglePortUdpHarvester>();
List<SinglePortUdpHarvester> harvesters = new LinkedList<>();
List<TransportAddress> addresses = new LinkedList<TransportAddress>();
List<TransportAddress> addresses = new LinkedList<>();
boolean isIPv6Disabled = StackProperties.getBoolean(
StackProperties.DISABLE_IPv6,
false);
@ -158,7 +157,7 @@ public class SinglePortUdpHarvester
* other threads remove entries when candidates are freed.
*/
private final Map<SocketAddress, MySocket> sockets
= new ConcurrentHashMap<SocketAddress, MySocket>();
= new ConcurrentHashMap<>();
/**
* The map which keeps all currently active <tt>Candidate</tt>s created by
@ -166,14 +165,14 @@ public class SinglePortUdpHarvester
* the components for which the candidates are harvested.
*/
private final Map<String, MyCandidate> candidates
= new ConcurrentHashMap<String, MyCandidate>();
= new ConcurrentHashMap<>();
/**
* A pool of <tt>Buffer</tt> instances used to avoid creating of new java
* objects.
*/
private final ArrayBlockingQueue<Buffer> pool
= new ArrayBlockingQueue<Buffer>(POOL_SIZE);
= new ArrayBlockingQueue<>(POOL_SIZE);
/**
* The local address that this harvester is bound to.
@ -235,7 +234,7 @@ public class SinglePortUdpHarvester
MySocket destinationSocket;
InetSocketAddress remoteAddress;
while (true)
do
{
// TODO: implement stopping the thread with a switch?
@ -303,21 +302,19 @@ public class SinglePortUdpHarvester
catch (SocketException se)
{
logger.info("Could not create a socket: " + se);
continue;
}
catch (IOException ioe)
{
logger.info("Failed to handle new socket: " + ioe);
continue;
}
}
else
{
// A STUN Binding Request with an unknown USERNAME. Drop it.
continue;
}
}
}
while (true);
// TODO we are all done, clean up.
}
@ -431,7 +428,7 @@ public class SinglePortUdpHarvester
*/
logger.info(
"More than one Component for an Agent, cannot harvest.");
return new LinkedList<LocalCandidate>();
return new LinkedList<>();
}
MyCandidate candidate = new MyCandidate(component, ufrag);
@ -470,7 +467,7 @@ public class SinglePortUdpHarvester
* The FIFO which acts as a buffer for this socket.
*/
private final ArrayBlockingQueue<Buffer> queue
= new ArrayBlockingQueue<Buffer>(QUEUE_SIZE);
= new ArrayBlockingQueue<>(QUEUE_SIZE);
/**
* The {@link QueueStatistics} instance optionally used to collect and
@ -721,7 +718,7 @@ public class SinglePortUdpHarvester
* a corresponding socket in {@link #sockets}.
*/
private final Map<SocketAddress, IceSocketWrapper> candidateSockets
= new HashMap<SocketAddress, IceSocketWrapper>();
= new HashMap<>();
/**
* The collection of <tt>DatagramSocket</tt>s added to this candidate.
@ -731,7 +728,7 @@ public class SinglePortUdpHarvester
* the STUN stack or the user of ice4j.
*/
private final Map<SocketAddress, DatagramSocket> sockets
= new HashMap<SocketAddress, DatagramSocket>();
= new HashMap<>();
/**
* Initializes a new <tt>MyCandidate</tt> instance with the given

View File

@ -68,8 +68,7 @@ public class StunCandidateHarvest
* The list of <tt>Candidate</tt>s harvested for {@link #hostCandidate} by
* this harvest.
*/
private final List<LocalCandidate> candidates
= new LinkedList<LocalCandidate>();
private final List<LocalCandidate> candidates = new LinkedList<>();
/**
* The indicator which determines whether this <tt>StunCandidateHarvest</tt>
@ -104,8 +103,7 @@ public class StunCandidateHarvest
* to which a STUN <tt>Response</tt> responds available though it is known
* in <tt>StunClientTransaction</tt>.
*/
private final Map<TransactionID, Request> requests
= new HashMap<TransactionID, Request>();
private final Map<TransactionID, Request> requests = new HashMap<>();
/**
* The interval in milliseconds at which a new STUN keep-alive message is to
@ -1448,7 +1446,7 @@ public class StunCandidateHarvest
*/
public SendKeepAliveMessageThread(StunCandidateHarvest harvest)
{
this.harvest = new WeakReference<StunCandidateHarvest>(harvest);
this.harvest = new WeakReference<>(harvest);
}
@Override

View File

@ -51,7 +51,7 @@ public class StunCandidateHarvester
* completed i.e. have harvested <tt>Candidate</tt>s.
*/
private final List<StunCandidateHarvest> completedHarvests
= new LinkedList<StunCandidateHarvest>();
= new LinkedList<>();
/**
* The username used by this <tt>StunCandidateHarvester</tt> for the
@ -65,7 +65,7 @@ public class StunCandidateHarvester
* not completed yet so {@link #harvest(Component)} has to wait for them.
*/
private final List<StunCandidateHarvest> startedHarvests
= new LinkedList<StunCandidateHarvest>();
= new LinkedList<>();
/**
* The address of the STUN server that we will be sending our requests to.
@ -255,7 +255,7 @@ public class StunCandidateHarvester
* Report the LocalCandidates gathered by this CandidateHarvester so
* that the harvest is sure to be considered successful.
*/
Collection<LocalCandidate> candidates = new HashSet<LocalCandidate>();
Collection<LocalCandidate> candidates = new HashSet<>();
synchronized (completedHarvests)
{

View File

@ -83,7 +83,7 @@ public class TcpHarvester
List<NetworkInterface> interfaces)
throws IOException
{
List<TransportAddress> addresses = new LinkedList<TransportAddress>();
List<TransportAddress> addresses = new LinkedList<>();
for (NetworkInterface iface : interfaces)
{
@ -126,34 +126,32 @@ public class TcpHarvester
* <tt>Component</tt>s from being freed.
*/
private final Map<String, WeakReference<Component>> components
= new HashMap<String, WeakReference<Component>>();
= new HashMap<>();
/**
* The list of transport addresses which we have found to be listening on,
* and which we will advertise as candidates in
* {@link #harvest(org.ice4j.ice.Component)}
*/
private final List<TransportAddress> localAddresses
= new LinkedList<TransportAddress>();
private final List<TransportAddress> localAddresses = new LinkedList<>();
/**
* Maps a public address to a local address.
*/
private final Map<InetAddress, InetAddress> mappedAddresses
= new HashMap<InetAddress, InetAddress>();
= new HashMap<>();
/**
* Sets of additional ports, for which server reflexive candidates will be
* added.
*/
private final Set<Integer> mappedPorts = new HashSet<Integer>();
private final Set<Integer> mappedPorts = new HashSet<>();
/**
* Channels pending to be added to the list that {@link #readThread} reads
* from.
*/
private final List<SocketChannel> newChannels
= new LinkedList<SocketChannel>();
private final List<SocketChannel> newChannels = new LinkedList<>();
/**
* A counter used to decide when to purge {@link #components}.
@ -175,7 +173,7 @@ public class TcpHarvester
* on.
*/
private final List<ServerSocketChannel> serverSocketChannels
= new LinkedList<ServerSocketChannel>();
= new LinkedList<>();
/**
* Whether or not to use ssltcp.
@ -421,8 +419,7 @@ public class TcpHarvester
*/
private List<LocalCandidate> createLocalCandidates(Component component)
{
List<TcpHostCandidate> hostCandidates
= new LinkedList<TcpHostCandidate>();
List<TcpHostCandidate> hostCandidates = new LinkedList<>();
// Add the host candidates for the addresses we really listen on
for (TransportAddress transportAddress : localAddresses)
@ -438,8 +435,7 @@ public class TcpHarvester
}
// Add srflx candidates for any mapped addresses
List<LocalCandidate> mappedCandidates
= new LinkedList<LocalCandidate>();
List<LocalCandidate> mappedCandidates = new LinkedList<>();
for (Map.Entry<InetAddress, InetAddress> mapping
: mappedAddresses.entrySet())
@ -473,8 +469,7 @@ public class TcpHarvester
}
// Add srflx candidates for mapped ports
List<LocalCandidate> portMappedCandidates
= new LinkedList<LocalCandidate>();
List<LocalCandidate> portMappedCandidates = new LinkedList<>();
for (TcpHostCandidate base : hostCandidates)
{
@ -524,8 +519,7 @@ public class TcpHarvester
}
}
LinkedList<LocalCandidate> allCandidates
= new LinkedList<LocalCandidate>();
LinkedList<LocalCandidate> allCandidates = new LinkedList<>();
allCandidates.addAll(hostCandidates);
allCandidates.addAll(mappedCandidates);
@ -589,7 +583,7 @@ public class TcpHarvester
*/
logger.info(
"More than one Component for an Agent, cannot harvest.");
return new LinkedList<LocalCandidate>();
return new LinkedList<>();
}
List<LocalCandidate> candidates = createLocalCandidates(component);
@ -599,8 +593,9 @@ public class TcpHarvester
synchronized (components)
{
components.put(agent.getLocalUfrag(),
new WeakReference<Component>(component));
components.put(
agent.getLocalUfrag(),
new WeakReference<>(component));
purgeComponents();
}
@ -807,8 +802,7 @@ public class TcpHarvester
}
IOException exception = null;
List<SocketChannel> channelsToAdd
= new LinkedList<SocketChannel>();
List<SocketChannel> channelsToAdd = new LinkedList<>();
// Allow to go on, so we can quit if closed.
long selectTimeout = 3000;

View File

@ -323,9 +323,7 @@ public class TurnCandidateHarvest
EvenPortAttribute evenPortAttribute
= (EvenPortAttribute) request.getAttribute(Attribute.EVEN_PORT);
boolean rFlag
= (evenPortAttribute == null)
? false
: evenPortAttribute.isRFlag();
= (evenPortAttribute != null) && evenPortAttribute.isRFlag();
return
MessageFactory.createAllocateRequest(

View File

@ -87,7 +87,7 @@ public class UPNPHarvester
*/
public synchronized Collection<LocalCandidate> harvest(Component component)
{
Collection<LocalCandidate> candidates = new HashSet<LocalCandidate>();
Collection<LocalCandidate> candidates = new HashSet<>();
int retries = 0;
logger.fine("Begin UPnP harvesting");
@ -213,9 +213,9 @@ public class UPNPHarvester
String externalIP, int port, Component cmp, GatewayDevice device)
throws Exception
{
List<LocalCandidate> ret = new ArrayList<LocalCandidate>();
TransportAddress addr = new TransportAddress(externalIP, port,
Transport.UDP);
List<LocalCandidate> ret = new ArrayList<>();
TransportAddress addr
= new TransportAddress(externalIP, port, Transport.UDP);
HostCandidate base = new HostCandidate(socket, cmp);

View File

@ -273,8 +273,8 @@ public class IceSdpUtils
//m lines
List<IceMediaStream> streams = agent.getStreams();
Vector<MediaDescription> mDescs = new Vector<MediaDescription>(
agent.getStreamCount());
Vector<MediaDescription> mDescs
= new Vector<>(agent.getStreamCount());
for(IceMediaStream stream : streams)
{
MediaDescription mLine = sdpFactory.createMediaDescription(
@ -320,15 +320,14 @@ public class IceSdpUtils
if(localCandidates == null || localCandidates.size() == 0)
{
trickleUpdate = new ArrayList<Attribute>(1);
trickleUpdate = new ArrayList<>(1);
trickleUpdate.add(
sdpFactory.createAttribute(END_OF_CANDIDATES, null));
return trickleUpdate;
}
trickleUpdate
= new ArrayList<Attribute>(localCandidates.size() + 1);
trickleUpdate = new ArrayList<>(localCandidates.size() + 1);
String streamName = null;

View File

@ -342,7 +342,7 @@ public abstract class Message
*/
//not sure this is the best solution but I'm trying to keep entry order
protected LinkedHashMap<Character, Attribute> attributes
= new LinkedHashMap<Character, Attribute>();
= new LinkedHashMap<>();
/**
* Attribute presentity is a thing of RFC 3489 and no longer exists in
@ -619,7 +619,7 @@ public abstract class Message
{
synchronized(attributes)
{
return new LinkedList<Attribute>(attributes.values());
return new LinkedList<>(attributes.values());
}
}
@ -941,8 +941,7 @@ public abstract class Message
offset += RFC3489_TRANSACTION_ID_LENGTH;
}
Vector<Map.Entry<Character, Attribute>> v =
new Vector<Map.Entry<Character, Attribute>>();
Vector<Map.Entry<Character, Attribute>> v = new Vector<>();
Iterator<Map.Entry<Character, Attribute>> iter = null;
char dataLengthForContentDependentAttribute = 0;

View File

@ -36,4 +36,4 @@ enum EnShutdown
* There was a forceful shutdown
*/
SD_FORCEFUL
};
}

View File

@ -48,4 +48,4 @@ public enum Option
* Timeout in ms for write operations(0 - no timeout)
*/
OPT_WRITE_TIMEOUT
};
}

View File

@ -174,7 +174,7 @@ public class PseudoTCPBase
* control flags. If segment contains any data it is stored in the receive
* buffer.
*/
List<RSegment> m_rlist = new ArrayList<RSegment>();
List<RSegment> m_rlist = new ArrayList<>();
/**
* Last receive timestamp
*/
@ -203,7 +203,7 @@ public class PseudoTCPBase
/**
* Outgoing segments list
*/
List<SSegment> m_slist = new ArrayList<SSegment>();
List<SSegment> m_slist = new ArrayList<>();
/**
* Last send timestamp
*/
@ -429,7 +429,7 @@ public class PseudoTCPBase
// Check if it's time to retransmit a segment
if (m_rto_base > 0 && (timeDiff(m_rto_base + m_rx_rto, now) <= 0))
{
assert m_slist.isEmpty() == false;
assert !m_slist.isEmpty();
// retransmit segments
if (logger.isLoggable(Level.FINER))
{
@ -1399,7 +1399,7 @@ public class PseudoTCPBase
Iterator<RSegment> iter = m_rlist.iterator();
List<RSegment> toBeRemoved = new ArrayList<RSegment>();
List<RSegment> toBeRemoved = new ArrayList<>();
while (iter.hasNext())
{
RSegment it = iter.next();
@ -1903,7 +1903,7 @@ public class PseudoTCPBase
*/
boolean parseOptions(byte[] data, int offset, int len)
{
List<Short> options_specified = new ArrayList<Short>();
List<Short> options_specified = new ArrayList<>();
// See http://www.freesoft.org/CIE/Course/Section4/8.htm for
// parsing the options list.

View File

@ -270,7 +270,7 @@ class PseudoTcpSocketImpl
throw new UnsupportedOperationException("Not supported yet.");
}
private Map<Integer, Object> options = new HashMap<Integer,Object>();
private Map<Integer, Object> options = new HashMap<>();
public void setOption(int optID, Object value)
throws SocketException
{
@ -353,7 +353,7 @@ class PseudoTcpSocketImpl
synchronized (state_notify)
{
while (pseudoTcp.getState() != PseudoTcpState.TCP_ESTABLISHED
&& (noTimeout ? true : (elapsed < timeout)) )
&& (noTimeout || (elapsed < timeout)) )
{
long start = System.currentTimeMillis();
state_notify.wait(timeout);

View File

@ -45,4 +45,4 @@ public enum PseudoTcpState
* TODO: closing procedure
*/
TCP_CLOSED// = 4;
};
}

View File

@ -24,5 +24,5 @@ package org.ice4j.pseudotcp;
*/
enum SendFlags
{
sfNone, sfImmediateAck, sfDelayedAck;
sfNone, sfImmediateAck, sfDelayedAck
}

View File

@ -35,4 +35,4 @@ public enum WriteResult
* Write failed
*/
WR_FAIL
};
}

View File

@ -41,8 +41,7 @@ public class CredentialsManager
* The list of <tt>CredentialsAuthority</tt>s registered with this manager
* as being able to provide credentials.
*/
private final List<CredentialsAuthority> authorities =
new LinkedList<CredentialsAuthority>();
private final List<CredentialsAuthority> authorities = new LinkedList<>();
/**
* The list of <tt>CredentialsAuthority</tt>s registered with this manager

View File

@ -58,8 +58,7 @@ public class GoogleRelayedCandidateDelegate
* {@link #receive(DatagramPacket)} method. They have been received from the
* TURN server in the form of Data indications.
*/
private final List<DatagramPacket> packetsToReceive =
new LinkedList<DatagramPacket>();
private final List<DatagramPacket> packetsToReceive = new LinkedList<>();
/**
* The <tt>DatagramSocket</tt>s which have been sent through this
@ -67,8 +66,7 @@ public class GoogleRelayedCandidateDelegate
* and which are to be relayed through its associated TURN server in the
* form of Send indications.
*/
private final List<DatagramPacket> packetsToSend =
new LinkedList<DatagramPacket>();
private final List<DatagramPacket> packetsToSend = new LinkedList<>();
/**
* The <tt>Thread</tt> which is to send the {@link #packetsToSend} to the
@ -315,7 +313,7 @@ public class GoogleRelayedCandidateDelegate
{
synchronized (packetsToReceive)
{
while (true)
do
{
/*
* According to the javadoc of DatagramSocket#close(), any
@ -337,7 +335,6 @@ public class GoogleRelayedCandidateDelegate
catch (InterruptedException iex)
{
}
continue;
}
else
{
@ -348,6 +345,7 @@ public class GoogleRelayedCandidateDelegate
break;
}
}
while (true);
}
}

View File

@ -62,7 +62,7 @@ public class IceTcpServerSocketWrapper
/**
* List of TCP client sockets.
*/
private final List<Socket> sockets = new ArrayList<Socket>();
private final List<Socket> sockets = new ArrayList<>();
/**
* Initializes a new <tt>IceTcpServerSocketWrapper</tt>.

View File

@ -570,7 +570,7 @@ abstract class MultiplexingXXXSocketSupport
if (socketFilter.accept(p))
{
if (toMove == null)
toMove = new LinkedList<DatagramPacket>();
toMove = new LinkedList<>();
toMove.add(p);
// XXX In the method receive, we allow multiple filters

View File

@ -112,7 +112,7 @@ public class RelayedCandidateDatagramSocket
* <tt>RelayedCandidateDatagramSocket</tt>s relays data send to it to
* peer <tt>TransportAddress</tt>es.
*/
private final List<Channel> channels = new LinkedList<Channel>();
private final List<Channel> channels = new LinkedList<>();
/**
* The indicator which determines whether this instance has started
@ -143,8 +143,7 @@ public class RelayedCandidateDatagramSocket
* {@link #receive(DatagramPacket)} method. They have been received from the
* TURN server in the form of Data indications.
*/
private final List<DatagramPacket> packetsToReceive
= new LinkedList<DatagramPacket>();
private final List<DatagramPacket> packetsToReceive = new LinkedList<>();
/**
* The <tt>DatagramSocket</tt>s which have been sent through this
@ -152,8 +151,7 @@ public class RelayedCandidateDatagramSocket
* and which are to be relayed through its associated TURN server in the
* form of Send indications.
*/
private final List<DatagramPacket> packetsToSend
= new LinkedList<DatagramPacket>();
private final List<DatagramPacket> packetsToSend = new LinkedList<>();
/**
* The <tt>Thread</tt> which receives <tt>DatagramPacket</tt>s from
@ -704,7 +702,7 @@ public class RelayedCandidateDatagramSocket
{
synchronized (packetsToReceive)
{
while (true)
do
{
/*
* According to the javadoc of DatagramSocket#close(), any
@ -728,7 +726,6 @@ public class RelayedCandidateDatagramSocket
catch (InterruptedException iex)
{
}
continue;
}
else
{
@ -739,6 +736,7 @@ public class RelayedCandidateDatagramSocket
break;
}
}
while (true);
}
}

View File

@ -65,7 +65,7 @@ public class RtcpDemuxPacketFilter
byte[] data = p.getData();
int off = p.getOffset();
if (((data[off + 0] & 0xc0) >> 6) == 2) //RTP/RTCP version field
if (((data[off] & 0xc0) >> 6) == 2) //RTP/RTCP version field
{
int pt = data[off + 1] & 0xff;

View File

@ -39,7 +39,7 @@ public class EventDispatcher
* <tt>EventDispatcher</tt>.
*/
private final List<MessageTypeEventHandler<?>> messageListeners
= new Vector<MessageTypeEventHandler<?>>();
= new Vector<>();
/**
* The <tt>Map</tt> of <tt>EventDispatcher</tt>s which keep the
@ -48,7 +48,7 @@ public class EventDispatcher
* <tt>TransportAddress<tt>es.
*/
private final Map<TransportAddress, EventDispatcher> children
= new Hashtable<TransportAddress, EventDispatcher>();
= new Hashtable<>();
/**
* Initializes a new <tt>EventDispatcher</tt> instance.

View File

@ -38,7 +38,7 @@ class MessageQueue
// not sure whether Vector is the best choice here since we explicitly
//sync all methods ... review later
private Vector<RawMessage> queue = new Vector<RawMessage>();
private final Vector<RawMessage> queue = new Vector<>();
//keep a copy of the fifo size and make it accessible for concurrent
// queries.

View File

@ -59,7 +59,7 @@ class NetAccessManager
*/
private final Map<TransportAddress, Map<TransportAddress, Connector>>
udpConnectors
= new HashMap<TransportAddress, Map<TransportAddress, Connector>>();
= new HashMap<>();
/**
* All <tt>Connectors</tt> currently in use with TCP. The table maps a local
@ -74,7 +74,7 @@ class NetAccessManager
*/
private final Map<TransportAddress, Map<TransportAddress, Connector>>
tcpConnectors
= new HashMap<TransportAddress, Map<TransportAddress, Connector>>();
= new HashMap<>();
/**
* A synchronized FIFO where incoming messages are stocked for processing.
@ -84,8 +84,7 @@ class NetAccessManager
/**
* A thread pool of message processors.
*/
private Vector<MessageProcessor> messageProcessors
= new Vector<MessageProcessor>();
private final Vector<MessageProcessor> messageProcessors = new Vector<>();
/**
* The instance that should be notified when an incoming message has been
@ -332,8 +331,7 @@ class NetAccessManager
if (connectorsForLocalAddress == null)
{
connectorsForLocalAddress
= new HashMap<TransportAddress, Connector>();
connectorsForLocalAddress = new HashMap<>();
connectorsMap.put(localAddress, connectorsForLocalAddress);
}

View File

@ -81,7 +81,7 @@ public class StunStack
*/
private final Hashtable<TransactionID, StunClientTransaction>
clientTransactions
= new Hashtable<TransactionID, StunClientTransaction>();
= new Hashtable<>();
/**
* The <tt>Thread</tt> which expires the <tt>StunServerTransaction</tt>s of
@ -96,7 +96,7 @@ public class StunStack
*/
private final Hashtable<TransactionID, StunServerTransaction>
serverTransactions
= new Hashtable<TransactionID, StunServerTransaction>();
= new Hashtable<>();
/**
* A dispatcher for incoming requests event;
@ -310,8 +310,7 @@ public class StunStack
*/
if (clientTransactionsToCancel == null)
{
clientTransactionsToCancel
= new LinkedList<StunClientTransaction>();
clientTransactionsToCancel = new LinkedList<>();
}
clientTransactionsToCancel.add(tran);
}
@ -352,8 +351,7 @@ public class StunStack
if (serverTransactionsToExpire == null)
{
serverTransactionsToExpire
= new LinkedList<StunServerTransaction>();
serverTransactionsToExpire = new LinkedList<>();
}
serverTransactionsToExpire.add(tran);
}
@ -1079,8 +1077,7 @@ public class StunStack
synchronized (clientTransactions)
{
clientTransactionsToCancel
= new ArrayList<StunClientTransaction>(
clientTransactions.values());
= new ArrayList<>(clientTransactions.values());
clientTransactions.clear();
}
/*
@ -1097,8 +1094,7 @@ public class StunStack
synchronized (serverTransactions)
{
serverTransactionsToExpire
= new ArrayList<StunServerTransaction>(
serverTransactions.values());
= new ArrayList<>(serverTransactions.values());
serverTransactions.clear();
}
for (StunServerTransaction tran : serverTransactionsToExpire)

View File

@ -131,8 +131,8 @@ public class TransactionID
for(int i = 0; i < b; i++)
{
tid.transactionID[i] = (byte)((left >> (i * 8)) & 0xFFl);
tid.transactionID[i + b] = (byte)((right >> (i * 8)) & 0xFFl);
tid.transactionID[i] = (byte)((left >> (i * 8)) & 0xFFL);
tid.transactionID[i + b] = (byte)((right >> (i * 8)) & 0xFFL);
}
//calculate hashcode for Hashtable storage.

View File

@ -260,8 +260,7 @@ public class MessageEventDispatchingTest extends TestCase
private class PlainRequestCollector implements RequestListener
{
/** all requests we've received so far. */
public Vector<StunMessageEvent> receivedRequests
= new Vector<StunMessageEvent>();
public final Vector<StunMessageEvent> receivedRequests = new Vector<>();
/**
* Stores incoming requests.
@ -299,7 +298,7 @@ public class MessageEventDispatchingTest extends TestCase
private static class PlainResponseCollector
extends AbstractResponseCollector
{
public final Vector<Object> receivedResponses = new Vector<Object>();
public final Vector<Object> receivedResponses = new Vector<>();
/**
* Notifies this <tt>ResponseCollector</tt> that a transaction described by

View File

@ -515,7 +515,7 @@ public class TransactionSupportTests extends TestCase
*
*/
private Vector<StunMessageEvent> receivedRequestsVector
= new Vector<StunMessageEvent>();
= new Vector<>();
/**
* Logs the newly received request.
@ -543,7 +543,7 @@ public class TransactionSupportTests extends TestCase
*/
public Vector<StunMessageEvent> getRequestsForTransaction(byte[] tranid)
{
Vector<StunMessageEvent> newVec = new Vector<StunMessageEvent>();
Vector<StunMessageEvent> newVec = new Vector<>();
for (StunMessageEvent evt : receivedRequestsVector)
{
@ -581,7 +581,7 @@ public class TransactionSupportTests extends TestCase
/**
* The responses we've collected so far.
*/
public final Vector<Object> receivedResponses = new Vector<Object>();
public final Vector<Object> receivedResponses = new Vector<>();
/**
* Notifies this <tt>ResponseCollector</tt> that a transaction described by

View File

@ -109,7 +109,7 @@ public class OptionalAttributeAttributeTest extends TestCase
assertEquals("failed null comparison", expectedReturn, actualReturn);
//wrong type comparison
obj = new String("hehe :)");
obj = "hehe :)";
actualReturn = optionalAttribute.equals(obj);
assertEquals("failed wrong type comparison", expectedReturn,
actualReturn);

View File

@ -253,8 +253,8 @@ public class UnknownAttributesAttributeTest extends TestCase
Iterator<Character> iterator = unknownAttributesAttribute.getAttributes();
actualId1 = iterator.next().charValue();
actualId2 = iterator.next().charValue();;
actualId1 = iterator.next();
actualId2 = iterator.next();
assertEquals("getAttributes() return value mismatch", expectedId1, actualId1);
assertEquals("getAttributes() return value mismatch", expectedId2, actualId2);

View File

@ -67,8 +67,8 @@ public class PseudoTcpTestRecvWindow extends PseudoTcpTestBase
Thread.setDefaultUncaughtExceptionHandler(this);
testDataSize = size;
long start, elapsed;
send_position = new ArrayList<Integer>();
recv_position = new ArrayList<Integer>();
send_position = new ArrayList<>();
recv_position = new ArrayList<>();
// Create some dummy data
byte[] dummy = createDummyData(size);
send_stream = new ByteFifoBuffer(size);

View File

@ -46,7 +46,7 @@ public class ResponseSequenceServer
/**
* The sequence of responses to send.
*/
private Vector<Object> messageSequence = new Vector<Object>();
private Vector<Object> messageSequence = new Vector<>();
/**
* The <tt>StunStack</tt> used by this instance for the purposes of STUN
@ -110,7 +110,7 @@ public class ResponseSequenceServer
if (response == null)
{
//leave a mark to skip a message
messageSequence.add(new Boolean(false));
messageSequence.add(false);
}
else
messageSequence.add(response);

View File

@ -60,8 +60,7 @@ public class AwsTest
}
AwsCandidateHarvester mch = new AwsCandidateHarvester();
List<CandidateHarvester> harvesters
= new ArrayList<CandidateHarvester>();
List<CandidateHarvester> harvesters = new ArrayList<>();
harvesters.add(mch);
Agent localAgent = createAgent(2020, false, harvesters);

View File

@ -97,7 +97,7 @@ public class IceDistributed
= new BufferedReader(new InputStreamReader(System.in));
StringBuffer buff = new StringBuffer();
String line = new String();
String line;
while ( (line = reader.readLine()) != null)
{

View File

@ -78,8 +78,7 @@ public class MappingTest
MappingCandidateHarvester natHarvester
= new MappingCandidateHarvester(publicAddress, localAddress);
List<CandidateHarvester> harvesters
= new ArrayList<CandidateHarvester>();
List<CandidateHarvester> harvesters = new ArrayList<>();
harvesters.add(natHarvester);
Agent localAgent = createAgent(2020, false, harvesters);

View File

@ -18,13 +18,11 @@
package test;
import java.util.*;
import java.util.StringTokenizer;
import javax.sdp.*;
import org.ice4j.*;
import org.ice4j.ice.*;
import org.ice4j.ice.Agent;
import org.ice4j.ice.sdp.*;
/**

View File

@ -80,7 +80,7 @@ public class TrickleIce
localAgent.startCandidateTrickle(printer);
List<Component> allComponents = new LinkedList<Component>();
List<Component> allComponents = new LinkedList<>();
int allCandidates = 0;
for (IceMediaStream stream : localAgent.getStreams())
{
@ -139,7 +139,7 @@ public class TrickleIce
if(iceCandidates == null)
{
try{Thread.sleep(1000);}catch(Exception e){};
try{Thread.sleep(1000);}catch(Exception e){}
logger.info("ICE stats: time="
+ agent.getTotalHarvestingTime() + "ms");