diff --git a/src/org/ice4j/ice/Candidate.java b/src/org/ice4j/ice/Candidate.java index 349d37b..be2ad13 100644 --- a/src/org/ice4j/ice/Candidate.java +++ b/src/org/ice4j/ice/Candidate.java @@ -29,6 +29,26 @@ import org.ice4j.*; public abstract class Candidate> implements Comparable { + /** + * The maximum value for a candidate's type preference. + */ + public static final int MAX_TYPE_PREFERENCE = 126; + + /** + * The minimum value for a candidate's type preference. + */ + public static final int MIN_TYPE_PREFERENCE = 0; + + /** + * The maximum value for a candidate's local preference. + */ + public static final int MAX_LOCAL_PREFERENCE = 65535; + + /** + * The minimum value for a candidate's local preference. + */ + public static final int MIN_LOCAL_PREFERENCE = 0; + /** * The transport address represented by this candidate. */ @@ -116,24 +136,9 @@ public abstract class Candidate> private T relatedCandidate = null; /** - * The maximum value for a candidate's type preference. + * The CandidateTcpType for this Candidate. */ - public static final int MAX_TYPE_PREFERENCE = 126; - - /** - * The minimum value for a candidate's type preference. - */ - public static final int MIN_TYPE_PREFERENCE = 0; - - /** - * The maximum value for a candidate's local preference. - */ - public static final int MAX_LOCAL_PREFERENCE = 65535; - - /** - * The minimum value for a candidate's local preference. - */ - public static final int MIN_LOCAL_PREFERENCE = 0; + private CandidateTcpType tcpType = null; /** * Creates a candidate for the specified transport address and properties. @@ -966,4 +971,22 @@ public abstract class Candidate> { return CandidatePrioritizer.compareCandidates(this, candidate); } + + /** + * Gets the CandidateTcpType for this Candidate. + * @return the CandidateTcpType for this Candidate. + */ + public CandidateTcpType getTcpType() + { + return tcpType; + } + + /** + * Sets the CandidateTcpType for this Candidate. + * @param tcpType the CandidateTcpType to set. + */ + public void setTcpType(CandidateTcpType tcpType) + { + this.tcpType = tcpType; + } } \ No newline at end of file diff --git a/src/org/ice4j/ice/CandidateTcpType.java b/src/org/ice4j/ice/CandidateTcpType.java new file mode 100644 index 0000000..08bdb55 --- /dev/null +++ b/src/org/ice4j/ice/CandidateTcpType.java @@ -0,0 +1,80 @@ +/* + * 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; + +/** + * Represents the TCP types for ICE TCP candidates. + * See http://tools.ietf.org/html/rfc6544 + * + * @author Boris Grozev + */ +public enum CandidateTcpType +{ + /** + * The "active" TCP candidate type. + */ + ACTIVE("active"), + + /** + * The "passive" TCP candidate type. + */ + PASSIVE("passive"), + + /** + * The "so" (simultaneous-open) TCP candidate type. + */ + SO("so"); + + /** + * The name of this CandidateTcpType instance. + */ + private final String name; + + /** + * Creates a CandidateTcpType instance with the specified name. + * + * @param name the name of the CandidateTcpType instance we'd + * like to create. + */ + private CandidateTcpType(String name) + { + this.name = name; + } + + /** + * Returns the name of this CandidateTcpType (e.g. "active", + * "passive", or "so"). + * + * @return the name of this CandidateTcpType (e.g. "active", + * "passive", or "so"). + */ + @Override + public String toString() + { + return name; + } + + /** + * + * Parses the string candidateTcpTypeName and return the + * corresponding CandidateTcpType instance. + * + * @throws IllegalArgumentException in case candidateTcpTypeName is + * not a valid or currently supported candidate TCP type. + */ + public static CandidateTcpType parse(String candidateTcpTypeName) + throws IllegalArgumentException + { + for (CandidateTcpType type : values()) + if (type.toString().equals(candidateTcpTypeName)) + return type; + + throw new IllegalArgumentException(candidateTcpTypeName + + " is not a currently supported CandidateTcpType"); + } +} + diff --git a/src/org/ice4j/ice/CandidateType.java b/src/org/ice4j/ice/CandidateType.java index e8d5b7a..108492b 100644 --- a/src/org/ice4j/ice/CandidateType.java +++ b/src/org/ice4j/ice/CandidateType.java @@ -89,8 +89,8 @@ public enum CandidateType * Returns the name of this CandidateType (e.g. "host", "prflx", * "srflx", or "relay"). * - * @return the name of this Transport (e.g. "udp" or - * "tcp"). + * @return the name of this CandidateType (e.g. "host", "prflx", + * "srflx", or "relay"). */ @Override public String toString() diff --git a/src/org/ice4j/ice/TcpHostCandidate.java b/src/org/ice4j/ice/TcpHostCandidate.java index 653f4f7..6e554a6 100644 --- a/src/org/ice4j/ice/TcpHostCandidate.java +++ b/src/org/ice4j/ice/TcpHostCandidate.java @@ -8,6 +8,7 @@ package org.ice4j.ice; import org.ice4j.*; import org.ice4j.socket.*; +import org.ice4j.stack.*; import java.util.*; @@ -55,11 +56,21 @@ public class TcpHostCandidate @Override protected void free() { - super.free(); + StunStack stunStack = getStunStack(); + TransportAddress localAddr = getTransportAddress(); for (IceSocketWrapper socket : sockets) { - socket.close(); + //remove our sockets from the stack. + stunStack.removeSocket( + localAddr, + new TransportAddress( + socket.getTCPSocket().getInetAddress(), + socket.getTCPSocket().getPort(), + Transport.TCP)); + + socket.close(); } + super.free(); } }