diff --git a/ndn-svs/core.cpp b/ndn-svs/core.cpp index 31e5463..080cff7 100644 --- a/ndn-svs/core.cpp +++ b/ndn-svs/core.cpp @@ -40,9 +40,12 @@ SVSyncCore::SVSyncCore(ndn::Face& face, , m_securityOptions(securityOptions) , m_id(nid) , m_onUpdate(onUpdate) + , m_maxSuppressionTime(100) + , m_periodicSyncTime(30000) + , m_periodicSyncJitter(0.1) , m_rng(ndn::random::getRandomNumberEngine()) - , m_retxDist(30000 * 0.9, 30000 * 1.1) - , m_intrReplyDist(0, 75) + , m_retxDist(m_periodicSyncTime * (1.0 - m_periodicSyncJitter), m_periodicSyncTime * (1.0 + m_periodicSyncJitter)) + , m_intrReplyDist(0, m_maxSuppressionTime) , m_keyChainMem("pib-memory:", "tpm-memory:") , m_scheduler(m_face.getIoService()) { @@ -56,6 +59,24 @@ SVSyncCore::SVSyncCore(ndn::Face& face, }); } +inline int +suppressionCurve(int constFactor, int value) +{ + /** + * This curve increases the probability that only one or a few + * nodes pick lower values for timers compared to other nodes. + * This leads to better suppression results. + * Increasing the curve factor makes the curve steeper => + * better for more nodes, but worse for fewer nodes. + */ + + double c = constFactor; + double v = value; + double f = 10.0; // curve factor + + return (int) (c * (1.0 - std::exp((v - c) / (c / f)))); +} + void SVSyncCore::sendInitialInterest() { @@ -161,6 +182,11 @@ SVSyncCore::onSyncInterestValidated(const Interest &interest) // Check how much time is left on the timer, // reset to ~m_intrReplyDist if more than that. int delay = m_intrReplyDist(m_rng); + + // Curve the delay for better suppression in large groups + // TODO: efficient curve depends on number of active nodes + delay = suppressionCurve(m_maxSuppressionTime, delay); + if (getCurrentTime() + delay * 1000 < m_nextSyncInterest) { retxSyncInterest(false, delay); diff --git a/ndn-svs/core.hpp b/ndn-svs/core.hpp index 4bbabd7..4755dc2 100644 --- a/ndn-svs/core.hpp +++ b/ndn-svs/core.hpp @@ -257,6 +257,16 @@ class SVSyncCore : noncopyable GetExtraBlockCallback m_getExtraBlock; RecvExtraBlockCallback m_recvExtraBlock; + // Max suppression time; this value is roughly + // correlated to the network diameter + int m_maxSuppressionTime; + // Periodic timer value; can be set to lower + // for highly lossy networks. + int m_periodicSyncTime; + // Fraction of jitter in the periodic timer value. + // Correlated to network diameter. + double m_periodicSyncJitter; + // Random Engine ndn::random::RandomNumberEngine& m_rng; // Milliseconds between sending two sync interests