conf: make ChronoSync's sync interest lifetime configurable
refs: #4490
Change-Id: Id3eabeed1049d1208ba49c47206f73f798f37a35
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 6b392af..6257be5 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -53,7 +53,7 @@
}
void
-SyncLogicHandler::createSyncSocket(const ndn::Name& syncPrefix)
+SyncLogicHandler::createSyncSocket(const ndn::Name& syncPrefix, const ndn::time::milliseconds& syncInterestLifetime)
{
if (m_syncSocket != nullptr) {
NLSR_LOG_WARN("Trying to create Sync socket, but Sync socket already exists");
@@ -72,7 +72,9 @@
std::shared_ptr<ndn::Face> facePtr(&m_syncFace, NullDeleter<ndn::Face>());
m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
- std::bind(&SyncLogicHandler::onChronoSyncUpdate, this, _1));
+ std::bind(&SyncLogicHandler::onChronoSyncUpdate, this, _1),
+ chronosync::Socket::DEFAULT_NAME, chronosync::Socket::DEFAULT_VALIDATOR,
+ syncInterestLifetime);
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
m_syncSocket->addSyncNode(m_adjLsaUserPrefix);
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 46bb18f..f4bd31a 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -22,6 +22,7 @@
#ifndef NLSR_SYNC_LOGIC_HANDLER_HPP
#define NLSR_SYNC_LOGIC_HANDLER_HPP
+#include "conf-parameter.hpp"
#include "test-access-control.hpp"
#include "signals.hpp"
#include "lsa.hpp"
@@ -90,10 +91,13 @@
*
* In a typical situation this only needs to be called once, when NLSR starts.
* \param syncPrefix The sync prefix you want this ChronoSync to use
+ * \param syncInterestLifetime ChronoSync sends a periodic sync interest every \p syncInterestLifetime / 2 ms
* \sa Nlsr::initialize
*/
void
- createSyncSocket(const ndn::Name& syncPrefix);
+ createSyncSocket(const ndn::Name& syncPrefix,
+ const ndn::time::milliseconds& syncInterestLifetime =
+ ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT));
PUBLIC_WITH_TESTS_ELSE_PRIVATE:
/*! \brief Simple function to glue Name components together
diff --git a/src/conf-file-processor.cpp b/src/conf-file-processor.cpp
index e93ef35..d388221 100644
--- a/src/conf-file-processor.cpp
+++ b/src/conf-file-processor.cpp
@@ -287,6 +287,19 @@
return false;
}
+ uint32_t syncInterestLifetime = section.get<uint32_t>("sync-interest-lifetime", SYNC_INTEREST_LIFETIME_DEFAULT);
+ if (syncInterestLifetime >= SYNC_INTEREST_LIFETIME_MIN &&
+ syncInterestLifetime <= SYNC_INTEREST_LIFETIME_MAX) {
+ m_nlsr.getConfParameter().setSyncInterestLifetime(syncInterestLifetime);
+ }
+ else {
+ std::cerr << "Wrong value for sync-interest-lifetime. "
+ << "Allowed value:" << SYNC_INTEREST_LIFETIME_MIN << "-"
+ << SYNC_INTEREST_LIFETIME_MAX << std::endl;
+
+ return false;
+ }
+
try {
std::string seqDir = section.get<std::string>("seq-dir");
if (boost::filesystem::exists(seqDir)) {
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index ee22764..ac32e04 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -106,6 +106,12 @@
HYPERBOLIC_STATE_DEFAULT = 0
};
+enum {
+ SYNC_INTEREST_LIFETIME_MIN = 1000,
+ SYNC_INTEREST_LIFETIME_DEFAULT = 60000,
+ SYNC_INTEREST_LIFETIME_MAX = 120000,
+};
+
/*! \brief A class to house all the configuration parameters for NLSR.
*
* This class is conceptually a singleton (but not mechanically) which
@@ -421,6 +427,18 @@
}
void
+ setSyncInterestLifetime(uint32_t syncInterestLifetime)
+ {
+ m_syncInterestLifetime = ndn::time::milliseconds(syncInterestLifetime);
+ }
+
+ const ndn::time::milliseconds&
+ getSyncInterestLifetime() const
+ {
+ return m_syncInterestLifetime;
+ }
+
+ void
writeLog();
private:
@@ -459,7 +477,7 @@
uint32_t m_maxFacesPerPrefix;
std::string m_seqFileDir;
-
+ ndn::time::milliseconds m_syncInterestLifetime;
};
} // namespace nlsr
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 120092b..ebc469d 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -260,7 +260,8 @@
m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
m_nlsrLsdb.getSequencingManager().initiateSeqNoFromFile(m_confParam.getHyperbolicState());
- m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix());
+ m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix(),
+ m_confParam.getSyncInterestLifetime());
// Logging start
m_confParam.writeLog();