diff --git a/src/main/java/org/ice4j/ice/CandidatePair.java b/src/main/java/org/ice4j/ice/CandidatePair.java index 902e804..f0a165f 100644 --- a/src/main/java/org/ice4j/ice/CandidatePair.java +++ b/src/main/java/org/ice4j/ice/CandidatePair.java @@ -722,7 +722,9 @@ public class CandidatePair * CandidatePair. * @return the UDP DatagramSocket (if any) for this * CandidatePair. + * @deprecated use {@link Component#getSocket()} instead. */ + @Deprecated public DatagramSocket getDatagramSocket() { IceSocketWrapper wrapper = getIceSocketWrapper(); @@ -732,38 +734,22 @@ public class CandidatePair /** * Returns the TCP Socket (if any) for this CandidatePair. * @return the TCP Socket (if any) for this CandidatePair. + * @deprecated use {@link Component#getSocket()} instead. */ + @Deprecated public Socket getSocket() { - IceSocketWrapper wrapper = getIceSocketWrapper(); - return wrapper == null ? null : wrapper.getTCPSocket(); + return null; } /** * Returns the IceSocketWrapper for this CandidatePair. * @return the IceSocketWrapper for this CandidatePair. + * @deprecated use {@link Component#getSocket()} instead. */ + @Deprecated public IceSocketWrapper getIceSocketWrapper() { - LocalCandidate localCandidate = getLocalCandidate(); - if (localCandidate == null) - { - return null; - } - - LocalCandidate base = localCandidate.getBase(); - if (base != null) - localCandidate = base; - - RemoteCandidate remoteCandidate = getRemoteCandidate(); - if (remoteCandidate != null) - { - SocketAddress remoteAddress - = remoteCandidate.getTransportAddress(); - if (remoteAddress != null) - return localCandidate.getIceSocketWrapper(remoteAddress); - } - - return localCandidate.getIceSocketWrapper(); + return getParentComponent().getSocketWrapper(); } } diff --git a/src/main/java/org/ice4j/ice/GoogleRelayedCandidate.java b/src/main/java/org/ice4j/ice/GoogleRelayedCandidate.java index 5c6b81d..9a97198 100644 --- a/src/main/java/org/ice4j/ice/GoogleRelayedCandidate.java +++ b/src/main/java/org/ice4j/ice/GoogleRelayedCandidate.java @@ -191,9 +191,10 @@ public class GoogleRelayedCandidate * * @return the DatagramSocket associated with this * Candidate - * @see LocalCandidate#getIceSocketWrapper() + * @see LocalCandidate#getCandidateIceSocketWrapper() */ - public synchronized IceSocketWrapper getIceSocketWrapper() + @Override + protected synchronized IceSocketWrapper getCandidateIceSocketWrapper() { if (socket == null) { diff --git a/src/main/java/org/ice4j/ice/HostCandidate.java b/src/main/java/org/ice4j/ice/HostCandidate.java index d9cc77c..236c4d2 100644 --- a/src/main/java/org/ice4j/ice/HostCandidate.java +++ b/src/main/java/org/ice4j/ice/HostCandidate.java @@ -131,13 +131,12 @@ public class HostCandidate extends LocalCandidate } /** - * Gets the DatagramSocket associated with this Candidate. - * - * @return the DatagramSocket associated with this - * Candidate - * @see LocalCandidate#getIceSocketWrapper() + * {@inheritDoc} + * SHOULD NOT be used outside ice4j. Only exposed for use in the + * org.ice4j.socket package. */ - public IceSocketWrapper getIceSocketWrapper() + @Override + public IceSocketWrapper getCandidateIceSocketWrapper() { return socket; } diff --git a/src/main/java/org/ice4j/ice/LocalCandidate.java b/src/main/java/org/ice4j/ice/LocalCandidate.java index 8e05090..560938c 100644 --- a/src/main/java/org/ice4j/ice/LocalCandidate.java +++ b/src/main/java/org/ice4j/ice/LocalCandidate.java @@ -108,8 +108,7 @@ public abstract class LocalCandidate * Candidate * * @deprecated This should be used by the library only. Users of ice4j - * should use {@link org.ice4j.ice.CandidatePair#getDatagramSocket()} - * on the appropriate CandidatePair instead. + * should use {@link org.ice4j.ice.Component#getSocket()} instead. */ @Deprecated public DatagramSocket getDatagramSocket() @@ -126,39 +125,34 @@ public abstract class LocalCandidate * Candidate * * @deprecated This should be used by the library only. Users of ice4j - * should use {@link org.ice4j.ice.CandidatePair#getSocket()} on the - * appropriate CandidatePair instead. + * should use {@link org.ice4j.ice.Component#getSocket()} instead. */ @Deprecated public Socket getSocket() { - IceSocketWrapper wrapper = getIceSocketWrapper(); - return wrapper == null ? null : wrapper.getTCPSocket(); + return null; } /** - * Gets the IceSocketWrapper associated with this - * Candidate. - * - * @return the IceSocketWrapper associated with this - * Candidate + * @return the {@link IceSocketWrapper} instance of the {@link Component} + * which owns this {@link LocalCandidate}. Note that this IS NOT an + * instance specific to this {@link LocalCandidate}. See + * {@link #getCandidateIceSocketWrapper()}. */ - protected abstract IceSocketWrapper getIceSocketWrapper(); - - /** - * Gets the IceSocketWrapper associated with this - * Candidate which is to be used for a specific remote address. - * This default implementation ignores the remote address. - * - * @param remoteAddress the remote address for which to get a socket. - * @return the IceSocketWrapper associated with this - * Candidate which is to be used for a specific remote address. - */ - protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress) + protected IceSocketWrapper getIceSocketWrapper() { - return getIceSocketWrapper(); + return getParentComponent().getSocketWrapper(); } + /** + * @return the {@link IceSocketWrapper} instance, if any, associated with + * this candidate. Note that this IS NOT the instance which should be used + * for reading and writing by the application, and SHOULD NOT be used from + * outside ice4j (even if a subclass exposes it as public). Also see + * {@link #getIceSocketWrapper()}. + */ + protected abstract IceSocketWrapper getCandidateIceSocketWrapper(); + /** * Creates if necessary and returns a DatagramSocket that would * capture all STUN packets arriving on this candidate's socket. If the @@ -174,7 +168,7 @@ public abstract class LocalCandidate */ public IceSocketWrapper getStunSocket(TransportAddress serverAddress) { - IceSocketWrapper hostSocket = getIceSocketWrapper(); + IceSocketWrapper hostSocket = getCandidateIceSocketWrapper(); if (hostSocket != null && hostSocket.getTCPSocket() != null) @@ -323,7 +317,7 @@ public abstract class LocalCandidate protected void free() { // Close the socket associated with this LocalCandidate. - IceSocketWrapper socket = getIceSocketWrapper(); + IceSocketWrapper socket = getCandidateIceSocketWrapper(); if (socket != null) { @@ -331,7 +325,7 @@ public abstract class LocalCandidate if ((base == null) || (base == this) - || (base.getIceSocketWrapper() != socket)) + || (base.getCandidateIceSocketWrapper() != socket)) { //remove our socket from the stack. getStunStack().removeSocket(getTransportAddress()); diff --git a/src/main/java/org/ice4j/ice/PeerReflexiveCandidate.java b/src/main/java/org/ice4j/ice/PeerReflexiveCandidate.java index 02ea7ab..9ad34f5 100644 --- a/src/main/java/org/ice4j/ice/PeerReflexiveCandidate.java +++ b/src/main/java/org/ice4j/ice/PeerReflexiveCandidate.java @@ -64,15 +64,11 @@ public class PeerReflexiveCandidate } /** - * Returns the DatagramSocket associated with this - * Candidate. - * - * @return the DatagramSocket associated with this - * Candidate - * @see LocalCandidate#getIceSocketWrapper() + * {@inheritDoc} */ - public IceSocketWrapper getIceSocketWrapper() + @Override + public IceSocketWrapper getCandidateIceSocketWrapper() { - return getBase().getIceSocketWrapper(); + return getBase().getCandidateIceSocketWrapper(); } } diff --git a/src/main/java/org/ice4j/ice/RelayedCandidate.java b/src/main/java/org/ice4j/ice/RelayedCandidate.java index 08a89c5..9adf723 100644 --- a/src/main/java/org/ice4j/ice/RelayedCandidate.java +++ b/src/main/java/org/ice4j/ice/RelayedCandidate.java @@ -101,7 +101,7 @@ public class RelayedCandidate * @return the RelayedCandidateDatagramSocket of this * RelayedCandidate */ - public synchronized RelayedCandidateDatagramSocket + private synchronized RelayedCandidateDatagramSocket getRelayedCandidateDatagramSocket() { if (relayedCandidateDatagramSocket == null) @@ -127,9 +127,9 @@ public class RelayedCandidate * * @return the DatagramSocket associated with this * Candidate - * @see LocalCandidate#getIceSocketWrapper() */ - public synchronized IceSocketWrapper getIceSocketWrapper() + @Override + protected synchronized IceSocketWrapper getCandidateIceSocketWrapper() { if (socket == null) { diff --git a/src/main/java/org/ice4j/ice/ServerReflexiveCandidate.java b/src/main/java/org/ice4j/ice/ServerReflexiveCandidate.java index d0105f2..6dc21d5 100644 --- a/src/main/java/org/ice4j/ice/ServerReflexiveCandidate.java +++ b/src/main/java/org/ice4j/ice/ServerReflexiveCandidate.java @@ -104,16 +104,12 @@ public class ServerReflexiveCandidate } /** - * Gets the DatagramSocket associated with this Candidate. - * - * @return the DatagramSocket associated with this - * Candidate - * @see LocalCandidate#getIceSocketWrapper() + * {@inheritDoc} */ @Override - public IceSocketWrapper getIceSocketWrapper() + public IceSocketWrapper getCandidateIceSocketWrapper() { - return getBase().getIceSocketWrapper(); + return getBase().getCandidateIceSocketWrapper(); } /** diff --git a/src/main/java/org/ice4j/ice/TcpHostCandidate.java b/src/main/java/org/ice4j/ice/TcpHostCandidate.java index 8cd96d4..2b70642 100644 --- a/src/main/java/org/ice4j/ice/TcpHostCandidate.java +++ b/src/main/java/org/ice4j/ice/TcpHostCandidate.java @@ -83,16 +83,4 @@ public class TcpHostCandidate super.free(); } - @Override - protected IceSocketWrapper getIceSocketWrapper(SocketAddress remoteAddress) - { - for (IceSocketWrapper socket : sockets) - { - if (socket.getTCPSocket().getRemoteSocketAddress() - .equals(remoteAddress)) - return socket; - } - - return null; - } } diff --git a/src/main/java/org/ice4j/ice/UPNPCandidate.java b/src/main/java/org/ice4j/ice/UPNPCandidate.java index 74646b3..95589e2 100644 --- a/src/main/java/org/ice4j/ice/UPNPCandidate.java +++ b/src/main/java/org/ice4j/ice/UPNPCandidate.java @@ -79,7 +79,7 @@ public class UPNPCandidate { } - IceSocketWrapper socket = getIceSocketWrapper(); + IceSocketWrapper socket = getCandidateIceSocketWrapper(); if(socket != null) { socket.close(); @@ -89,13 +89,19 @@ public class UPNPCandidate } /** - * Gets the DatagramSocket associated with this Candidate. - * - * @return the DatagramSocket associated with this - * Candidate + * {@inheritDoc} */ @Override - public IceSocketWrapper getIceSocketWrapper() + protected IceSocketWrapper getCandidateIceSocketWrapper() + { + return getBase().getCandidateIceSocketWrapper(); + } + + /** + * {@inheritDoc} + */ + @Override + protected IceSocketWrapper getIceSocketWrapper() { return getBase().getIceSocketWrapper(); } diff --git a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java index be9e25c..9ffb0bc 100644 --- a/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java +++ b/src/main/java/org/ice4j/ice/harvest/SinglePortUdpHarvester.java @@ -230,26 +230,27 @@ public class SinglePortUdpHarvester * The collection of IceSocketWrappers that can potentially * be used by the ice4j user to read/write from/to this candidate. * The keys are the remote addresses for each socket. - * + *
* There are wrappers over MultiplexedDatagramSockets over
* a corresponding socket in {@link #sockets}.
*/
private final Map
* These are the "raw" sockets, before any wrappers are added for
* the STUN stack or the user of ice4j.
*/
private final Map
* Closes all sockets in use by this LocalCandidate.
*/
@Override
@@ -283,20 +284,21 @@ public class SinglePortUdpHarvester
StunStack stunStack = getStunStack();
for (Map.Entry