diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 8c98a35..cd0cde9 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -1539,13 +1539,13 @@ public class Agent setState(IceProcessingState.COMPLETED); // keep ICE running (answer binding request) - if(compatibilityMode == CompatibilityMode.GTALK - && stunKeepAliveThread == null) + if(stunKeepAliveThread == null) { // schedule STUN checks for selected candidates scheduleSTUNKeepAlive(); } - else if(compatibilityMode == CompatibilityMode.RFC5245) + + if(compatibilityMode == CompatibilityMode.RFC5245) { scheduleTermination(); } @@ -1951,7 +1951,8 @@ public class Agent */ public void runInStunKeepAliveThread() { - while(state == IceProcessingState.COMPLETED) + while(state == IceProcessingState.COMPLETED || state == + IceProcessingState.TERMINATED) { List streams = getStreams(); @@ -1964,7 +1965,14 @@ public class Agent if(pair != null) { - connCheckClient.startCheckForPair(pair); + if(compatibilityMode == CompatibilityMode.GTALK) + { + connCheckClient.startCheckForPair(pair); + } + else if(compatibilityMode == CompatibilityMode.RFC5245) + { + connCheckClient.sendBindingIndicationForPair(pair); + } pair = null; } } diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index a028ed6..6d953e3 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -103,6 +103,53 @@ class ConnectivityCheckClient paceMaker.start(); } + /** + * Creates a STUN Binding {@link Indication} to a candidate pair. It is used + * as a keep-alive. + * + * @param candidatePair that {@link CandidatePair} that we'd like to send + * an indication + */ + protected void sendBindingIndicationForPair( + CandidatePair candidatePair) + { + LocalCandidate localCandidate = candidatePair.getLocalCandidate(); + + Indication indication = MessageFactory.createBindingIndication(); + + TransactionID tran = TransactionID.createNewTransactionID(); + tran.setApplicationData(candidatePair); + + try + { + TransportAddress localAddr = localCandidate.getBase(). + getTransportAddress(); + + stunStack.sendIndication( + indication, + candidatePair + .getRemoteCandidate().getTransportAddress(), + localAddr); + if(logger.isLoggable(Level.FINEST)) + { + logger.finest( + "sending binding indication to pair " + candidatePair); + } + } + catch (Exception ex) + { + IceSocketWrapper stunSocket = localCandidate.getStunSocket(null); + if(stunSocket != null) + logger.log( + Level.INFO, + "Failed to send " + indication + + " through " + stunSocket.getLocalSocketAddress(), + ex); + stunSocket = null; + tran = null; + } + } + /** * Creates a STUN {@link Request} containing the necessary PRIORITY and * CONTROLLING/CONTROLLED attributes. Also stores a reference to diff --git a/src/org/ice4j/message/Message.java b/src/org/ice4j/message/Message.java index 3e434aa..d2bd8a1 100644 --- a/src/org/ice4j/message/Message.java +++ b/src/org/ice4j/message/Message.java @@ -79,6 +79,12 @@ public abstract class Message public static final char BINDING_ERROR_RESPONSE = (STUN_METHOD_BINDING | STUN_ERROR_RESP); + /** + * STUN binding request code. + */ + public static final char BINDING_INDICATION = + (STUN_METHOD_BINDING | STUN_INDICATION); + /** * STUN shared secret request. */ diff --git a/src/org/ice4j/message/MessageFactory.java b/src/org/ice4j/message/MessageFactory.java index 0d700a7..0f0f900 100644 --- a/src/org/ice4j/message/MessageFactory.java +++ b/src/org/ice4j/message/MessageFactory.java @@ -319,6 +319,19 @@ public class MessageFactory return createBindingErrorResponse(errorCode, null, null); } + /** + * Creates a default binding indication. + * + * @return a default binding indication. + */ + public static Indication createBindingIndication() + { + Indication bindingIndication = new Indication(); + + bindingIndication.setMessageType(Message.BINDING_INDICATION); + return bindingIndication; + } + /** * Create an allocate request without attribute. *