Make "consent freshness" intervals configurable

This commit is contained in:
paweldomas 2016-07-21 15:01:30 -05:00
parent 26aa42cc37
commit 58c319981c
2 changed files with 75 additions and 13 deletions

View File

@ -48,6 +48,43 @@ public class StackProperties
*/ */
public static final int BIND_RETRIES_DEFAULT_VALUE = 50; public static final int BIND_RETRIES_DEFAULT_VALUE = 50;
/**
* How often a STUN Binding request used for consent freshness check will be
* sent(value in milliseconds).
*/
public static final String CONSENT_FRESHNESS_INTERVAL
= "org.ice4j.ice.CONSENT_FRESHNESS_INTERVAL";
/**
* The maximum number of retransmissions of a STUN Binding request without
* a valid STUN Binding response after which consent freshness is to be
* considered unconfirmed according to "STUN Usage for Consent
* Freshness".
*/
public static final String CONSENT_FRESHNESS_MAX_RETRANSMISSIONS
= "org.ice4j.ice.CONSENT_FRESHNESS_MAX_RETRANSMISSIONS";
/**
* The number of milliseconds without a valid STUN Binding response after
* which a STUN Binding request is to be retransmitted according to
* "STUN Usage for Consent Freshness". This is the final value
* for the back-off strategy.
* {@link #CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL} defines the initial
* interval for the first request sent. Value in milliseconds.
*/
public static final String CONSENT_FRESHNESS_MAX_WAIT_INTERVAL
= "org.ice4j.ice.CONSENT_FRESHNESS_MAX_WAIT_INTERVAL";
/**
* The number of milliseconds without a valid STUN Binding response after
* which a STUN Binding request is to be retransmitted according to
* "STUN Usage for Consent Freshness". This is the original value
* for back-off strategy. {@link #CONSENT_FRESHNESS_MAX_WAIT_INTERVAL} sets
* the upper limit. Value in milliseconds.
*/
public static final String CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL
= "org.ice4j.ice.CONSENT_FRESHNESS_WAIT_INTERVAL";
/** /**
* The number of milliseconds a client transaction should wait before * The number of milliseconds a client transaction should wait before
* retransmitting, after it has sent a request for the first time. * retransmitting, after it has sent a request for the first time.

View File

@ -54,19 +54,28 @@ import org.ice4j.util.Logger; // Disambiguation.
public class Agent public class Agent
{ {
/** /**
* The maximum number of retransmissions of a STUN Binding request without * Default value for {@link StackProperties#CONSENT_FRESHNESS_INTERVAL}.
* a valid STUN Binding response after which consent freshness is to be
* considered unconfirmed according to "STUN Usage for Consent
* Freshness".
*/ */
private static final int CONSENT_FRESHNESS_MAX_RETRANSMISSIONS = 30; private static final int DEFAULT_CONSENT_FRESHNESS_INTERVAL = 15000;
/** /**
* The number of milliseconds without a valid STUN Binding response after * Default value for
* which a STUN Binding request is to be retransmitted according to * {@link StackProperties#CONSENT_FRESHNESS_MAX_RETRANSMISSIONS}.
* "STUN Usage for Consent Freshness".
*/ */
private static final int CONSENT_FRESHNESS_WAIT_INTERVAL = 500; private static final int DEFAULT_CONSENT_FRESHNESS_MAX_RETRANSMISSIONS = 30;
/**
* Default value for
* {@link StackProperties#CONSENT_FRESHNESS_MAX_WAIT_INTERVAL}.
*/
private static final int DEFAULT_CONSENT_FRESHNESS_MAX_WAIT_INTERVAL = 500;
/**
* Default value for
* {@link StackProperties#CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL}.
*/
private static final int DEFAULT_CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL
= 500;
/** /**
* The default maximum size for check lists. * The default maximum size for check lists.
@ -2216,6 +2225,22 @@ public class Agent
*/ */
private void runInStunKeepAliveThread() private void runInStunKeepAliveThread()
{ {
long consentFreshnessInterval = Long.getLong(
StackProperties.CONSENT_FRESHNESS_INTERVAL,
DEFAULT_CONSENT_FRESHNESS_INTERVAL);
int originalConsentFreshnessWaitInterval = Integer.getInteger(
StackProperties.CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL,
DEFAULT_CONSENT_FRESHNESS_ORIGINAL_WAIT_INTERVAL);
int maxConsentFreshnessWaitInterval = Integer.getInteger(
StackProperties.CONSENT_FRESHNESS_MAX_WAIT_INTERVAL,
DEFAULT_CONSENT_FRESHNESS_MAX_WAIT_INTERVAL);
int consentFreshnessMaxRetransmissions = Integer.getInteger(
StackProperties.CONSENT_FRESHNESS_MAX_RETRANSMISSIONS,
DEFAULT_CONSENT_FRESHNESS_MAX_RETRANSMISSIONS);
while (runInStunKeepAliveThreadCondition()) while (runInStunKeepAliveThreadCondition())
{ {
for(IceMediaStream stream : getStreams()) for(IceMediaStream stream : getStreams())
@ -2230,9 +2255,9 @@ public class Agent
{ {
connCheckClient.startCheckForPair( connCheckClient.startCheckForPair(
pair, pair,
CONSENT_FRESHNESS_WAIT_INTERVAL, originalConsentFreshnessWaitInterval,
CONSENT_FRESHNESS_WAIT_INTERVAL, maxConsentFreshnessWaitInterval,
CONSENT_FRESHNESS_MAX_RETRANSMISSIONS); consentFreshnessMaxRetransmissions);
} }
else else
{ {
@ -2247,7 +2272,7 @@ public class Agent
try try
{ {
Thread.sleep(15000); Thread.sleep(consentFreshnessInterval);
Thread.yield(); Thread.yield();
} }
catch(InterruptedException e) catch(InterruptedException e)