From 19d734605016e346d89c1d36148b8899fa2fbee3 Mon Sep 17 00:00:00 2001 From: Boris Grozev Date: Tue, 18 Jun 2013 13:02:11 +0300 Subject: [PATCH] Prevents sending of more than one COIN every 200ms to a specific CallPeerJabberImpl. --- .../protocol/jabber/CallPeerJabberImpl.java | 27 ++++++++++++++ ...ionSetTelephonyConferencingJabberImpl.java | 37 ++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java index 2bd1610a1..c7fd0c0dc 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/CallPeerJabberImpl.java @@ -71,6 +71,17 @@ public class CallPeerJabberImpl */ private final Object sidSyncRoot = new Object(); + /** + * Whether a COIN has been scheduled to be sent to this + * CallPeerJabberImpl + */ + private boolean coinScheduled = false; + + /** + * Synchronization object for coinScheduled + */ + private final Object coinScheduledSyncRoot = new Object(); + /** * Creates a new call peer with address peerAddress. * @@ -1453,4 +1464,20 @@ else if (((IQ) result).getType() != IQ.Type.RESULT) new TransferredPacketExtension())); } } + + public boolean isCoinScheduled() + { + synchronized (coinScheduledSyncRoot) + { + return coinScheduled; + } + } + + public void setCoinScheduled(boolean coinScheduled) + { + synchronized (coinScheduledSyncRoot) + { + this.coinScheduled = coinScheduled; + } + } } diff --git a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java index d288ec629..5e556158b 100644 --- a/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetTelephonyConferencingJabberImpl.java @@ -49,6 +49,12 @@ public class OperationSetTelephonyConferencingJabberImpl private static final Logger logger = Logger.getLogger(OperationSetTelephonyConferencingJabberImpl.class); + /** + * The minimum interval in milliseconds between COINs sent to a single + * CallPeer. + */ + private static final int COIN_MIN_INTERVAL = 200; + /** * Synchronization object. */ @@ -107,7 +113,34 @@ private void notify(CallPeer callPeer) if(!(callPeer instanceof CallPeerJabberImpl)) return; - CallPeerJabberImpl callPeerJabber = (CallPeerJabberImpl)callPeer; + final CallPeerJabberImpl callPeerJabber = (CallPeerJabberImpl)callPeer; + + final long timeSinceLastCoin = System.currentTimeMillis() + - callPeerJabber.getLastConferenceInfoSentTimestamp(); + if (timeSinceLastCoin < COIN_MIN_INTERVAL) + { + if (callPeerJabber.isCoinScheduled()) + return; + + logger.info("Scheduling to send a COIN to " + callPeerJabber); + callPeerJabber.setCoinScheduled(true); + new Thread(new Runnable(){ + @Override + public void run() + { + try + { + Thread.sleep(1 + COIN_MIN_INTERVAL - timeSinceLastCoin); + } + catch (InterruptedException ie) {} + + OperationSetTelephonyConferencingJabberImpl.this + .notify(callPeerJabber); + } + }).start(); + + return; + } // check that callPeer supports COIN before sending him a // conference-info @@ -124,6 +157,7 @@ private void notify(CallPeer callPeer) ProtocolProviderServiceJabberImpl.URN_XMPP_JINGLE_COIN)) { logger.info(callPeer.getAddress() + " does not support COIN"); + callPeerJabber.setCoinScheduled(false); return; } } @@ -162,6 +196,7 @@ private void notify(CallPeer callPeer) System.currentTimeMillis()); } } + callPeerJabber.setCoinScheduled(false); } /**