diff --git a/src/org/ice4j/ice/CandidatePair.java b/src/org/ice4j/ice/CandidatePair.java new file mode 100644 index 0000000..f099603 --- /dev/null +++ b/src/org/ice4j/ice/CandidatePair.java @@ -0,0 +1,104 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package org.ice4j.ice; + +import java.util.logging.*; + +/** + * CandidatePairs map local to remote Candidates so that they + * could be added to check lists. Connectivity in ICE is always verified by + * pairs: i.e. STUN packets are sent from the local candidate of a pair to the + * remote candidate of a pair. To see which pairs work, an agent schedules a + * series of ConnectivityChecks. Each check is a STUN request/response + * transaction that the client will perform on a particular candidate pair by + * sending a STUN request from the local candidate to the remote candidate. + * + * @author Emil Ivov + */ +public class CandidatePair +{ + /** + * The Logger used by the CandidatePair + * class and its instances for logging output. + */ + private static final Logger logger = Logger + .getLogger(CandidatePair.class.getName()); + + /** + * The local candidate of this pair. + */ + private final LocalCandidate localCandidate; + + /** + * The remote candidate of this pair. + */ + private final RemoteCandidate remoteCandidate; + + /** + * Priority of the candidate-pair + */ + private long priority = 0; + + public static enum CandidatePairState{ + /** + * Indicates that the candidate pair is in a Waiting state which means that + * a check has not been performed for this pair, and can be performed as + * soon as it is the highest priority Waiting pair on the check list. + */ + STATE_WAITING("Waiting"), + + /** + * Indicates that the candidate pair is in a "In-Progress" state which means that + * a check has been sent for this pair, but the transaction is in progress. + */ + public static final String STATE_IN_PROGRESS = "In-Progress"; + + /** + * Indicates that the candidate pair is in a "Succeeded" state which means + * that a check for this pair was already done and produced a successful + * result. + */ + public static final String STATE_SUCCEEDED = "Succeeded"; + + /** + * Indicates that the candidate pair is in a "Failed" state which means that + * a check for this pair was already done and failed, either never producing + * any response or producing an unrecoverable failure response. + */ + public static final String STATE_FAILED = "Failed"; + + /** + * Indicates that the candidate pair is in a "Frozen" state which means that + * a check for this pair hasn't been performed, and it can't yet be + * performed until some other check succeeds, allowing this pair to unfreeze + * and move into the Waiting state. + */ + public static final String STATE_FROZEN = "Frozen"; + } + /** + * Each candidate pair has a a state that is assigned once the check list + * for each media stream has been computed. The ICE RFC defines five + * potential values that the state can have. They are represented here with + * the STATE_XXX class fields. + */ + private CandidatePairState state = CandidatePairState.STATE_FROZEN; + + /** + * Creates a CandidatePair instance mapping localCandidate + * to remoteCandidate. + * + * @param localCandidate the local candidate of the pair. + * @param remoteCandidate the remote candidate of the pair. + */ + public CandidatePair(LocalCandidate localCandidate, + RemoteCandidate remoteCandidate) + { + + this.localCandidate = localCandidate; + this.remoteCandidate = remoteCandidate; + } +} diff --git a/src/org/ice4j/ice/CandidatePairState.java b/src/org/ice4j/ice/CandidatePairState.java new file mode 100644 index 0000000..1f9ffac --- /dev/null +++ b/src/org/ice4j/ice/CandidatePairState.java @@ -0,0 +1,84 @@ +/* + * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal. + * Maintained by the SIP Communicator community (http://sip-communicator.org). + * + * Distributable under LGPL license. See terms of license at gnu.org. + */ +package org.ice4j.ice; + +/** + * Each candidate pair in the a list has a CandidatePairState. It is + * assigned once the check list for each media stream has been computed. There + * are five potential values that the state can have and they are all + * represented by this enumeration. + * + * @author Emil Ivov + */ +public enum CandidatePairState +{ + /** + * Indicates that the candidate pair is in a Waiting state which means that + * a check has not been performed for this pair, and can be performed as + * soon as it is the highest priority Waiting pair on the check list. + */ + STATE_WAITING("Waiting"), + + /** + * Indicates that the candidate pair is in a "In-Progress" state which + * means that a check has been sent for this pair, but the transaction is + * in progress. + */ + STATE_IN_PROGRESS("In-Progress"), + + /** + * Indicates that the candidate pair is in a "Succeeded" state which means + * that a check for this pair was already done and produced a successful + * result. + */ + STATE_SUCCEEDED("Succeeded"), + + /** + * Indicates that the candidate pair is in a "Failed" state which means that + * a check for this pair was already done and failed, either never producing + * any response or producing an unrecoverable failure response. + */ + STATE_FAILED("Failed"), + + /** + * Indicates that the candidate pair is in a "Frozen" state which means that + * a check for this pair hasn't been performed, and it can't yet be + * performed until some other check succeeds, allowing this pair to unfreeze + * and move into the Waiting state. + */ + STATE_FROZEN("Frozen"); + + /** + * The name of this CandidatePairState instance. + */ + private final String stateName; + + /** + * Creates a CandidatePairState instance with the specified name. + * + * @param stateName the name of the CandidatePairState instance + * we'd like to create. + */ + private CandidatePairState(String stateName) + { + this.stateName = stateName; + } + + /** + * Returns the name of this CandidatePairStae (e.g. "In-Progress", + * "Waiting", "Succeeded", or "Failed"). + * + * @return the name of this Transport (e.g. "Waiting" or + * "Frozen"). + */ + @Override + public String toString() + { + return stateName; + } + +}