make sync interest interval configurable
default is 20.0 for dispatcher's SyncCore
diff --git a/src/dispatcher.cc b/src/dispatcher.cc
index de52384..02ae150 100644
--- a/src/dispatcher.cc
+++ b/src/dispatcher.cc
@@ -33,6 +33,7 @@
INIT_LOGGER ("Dispatcher");
static const string BROADCAST_DOMAIN = "/ndn/broadcast/chronoshare";
+const static double DEFAULT_SYNC_INTEREST_INTERVAL = 20.0;
Dispatcher::Dispatcher(const std::string &localUserName
, const std::string &sharedFolder
@@ -62,7 +63,7 @@
m_server->registerPrefix(Name(BROADCAST_DOMAIN));
m_core = new SyncCore (m_syncLog, localUserName, Name ("/"), syncPrefix,
- bind(&Dispatcher::Did_SyncLog_StateChange, this, _1), ccnx);
+ bind(&Dispatcher::Did_SyncLog_StateChange, this, _1), ccnx, DEFAULT_SYNC_INTEREST_INTERVAL);
m_actionFetcher = make_shared<FetchManager> (m_ccnx, bind (&SyncLog::LookupLocator, &*m_syncLog, _1), 3);
m_fileFetcher = make_shared<FetchManager> (m_ccnx, bind (&SyncLog::LookupLocator, &*m_syncLog, _1), 3);
diff --git a/src/sync-core.cc b/src/sync-core.cc
index 29f8664..e113b24 100644
--- a/src/sync-core.cc
+++ b/src/sync-core.cc
@@ -38,13 +38,14 @@
using namespace Ccnx;
SyncCore::SyncCore(SyncLogPtr syncLog, const Name &userName, const Name &localPrefix, const Name &syncPrefix,
- const StateMsgCallback &callback, CcnxWrapperPtr ccnx)
+ const StateMsgCallback &callback, CcnxWrapperPtr ccnx, double syncInterestInterval/*= -1.0*/)
: m_ccnx (ccnx)
, m_log(syncLog)
, m_scheduler(new Scheduler ())
, m_stateMsgCallback(callback)
, m_syncPrefix(syncPrefix)
, m_recoverWaitGenerator(new RandomIntervalGenerator(WAIT, RANDOM_PERCENT, RandomIntervalGenerator::UP))
+ , m_syncInterestInterval(syncInterestInterval)
{
m_rootHash = m_log->RememberStateInStateLog();
@@ -54,7 +55,8 @@
m_scheduler->start();
string tag = userName.toString() + "send-sync-interest";
- m_sendSyncInterestTask = make_shared<OneTimeTask>(bind(&SyncCore::sendSyncInterest, this), tag, m_scheduler, 4.0);
+ double interval = (m_syncInterestInterval > 0 && m_syncInterestInterval < 30.0) ? m_syncInterestInterval : 4.0;
+ m_sendSyncInterestTask = make_shared<OneTimeTask>(bind(&SyncCore::sendSyncInterest, this), tag, m_scheduler, interval);
sendSyncInterest();
}
@@ -283,15 +285,19 @@
_LOG_DEBUG ("[" << m_log->GetLocalName () << "] >>> SYNC Interest for " << m_rootHash->shortHash () << ": " << syncInterest);
+ Selectors selectors;
+ if (m_syncInterestInterval > 0 && m_syncInterestInterval < 30.0)
+ {
+ selectors.interestLifetime(m_syncInterestInterval);
+ }
m_ccnx->sendInterest(syncInterest,
Closure (boost::bind(&SyncCore::handleSyncData, this, _1, _2),
- boost::bind(&SyncCore::handleSyncInterestTimeout, this, _1)));
+ boost::bind(&SyncCore::handleSyncInterestTimeout, this, _1)),
+ selectors);
- // if there is a pending syncSyncInterest task, reschedule it to be 4 seconds from now
+ // if there is a pending syncSyncInterest task, reschedule it to be m_syncInterestInterval seconds from now
// if no such task exists, it will be added
- _LOG_DEBUG("[" << m_log->GetLocalName () << "] >>> Attempt to schedule sendSyncInterest ");
m_scheduler->rescheduleTask(m_sendSyncInterestTask);
- _LOG_DEBUG("[" << m_log->GetLocalName () << "] >>> Scheduled sendSyncInterest ");
}
void
diff --git a/src/sync-core.h b/src/sync-core.h
index b0d8af0..a0eb547 100644
--- a/src/sync-core.h
+++ b/src/sync-core.h
@@ -45,7 +45,8 @@
, const Ccnx::Name &localPrefix // routable name used by the local user
, const Ccnx::Name &syncPrefix // the prefix for the sync collection
, const StateMsgCallback &callback // callback when state change is detected
- , Ccnx::CcnxWrapperPtr ccnx);
+ , Ccnx::CcnxWrapperPtr ccnx
+ , double syncInterestInterval = -1.0);
~SyncCore();
void
@@ -113,6 +114,8 @@
IntervalGeneratorPtr m_recoverWaitGenerator;
TaskPtr m_sendSyncInterestTask;
+
+ double m_syncInterestInterval;
};
#endif // SYNC_CORE_H