communication: use ChronoSync Logic instead of Socket
refs: #4623
Change-Id: I6950af9d92a254b4fe05f7570ab6bc8b8a9599c8
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 308a15d..1e8f90b 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -53,10 +53,10 @@
}
void
-SyncLogicHandler::createSyncSocket(const ndn::Name& syncPrefix, const ndn::time::milliseconds& syncInterestLifetime)
+SyncLogicHandler::createSyncLogic(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");
+ if (m_syncLogic != nullptr) {
+ NLSR_LOG_WARN("Trying to create Sync Logic object, but Sync Logic object already exists");
return;
}
@@ -65,27 +65,34 @@
// Build LSA sync update prefix
buildUpdatePrefix();
- NLSR_LOG_DEBUG("Creating Sync socket. Sync Prefix: " << m_syncPrefix);
+ NLSR_LOG_DEBUG("Creating Sync Logic object. Sync Prefix: " << m_syncPrefix);
- // The face's lifetime is managed in main.cpp; SyncSocket should not manage the memory
+ // The face's lifetime is managed in main.cpp; Logic should not manage the memory
// of the object
std::shared_ptr<ndn::Face> facePtr(&m_syncFace, NullDeleter<ndn::Face>());
const auto fixedSession = ndn::name::Component::fromNumber(0);
- m_syncSocket = std::make_shared<chronosync::Socket>(m_syncPrefix, m_nameLsaUserPrefix, *facePtr,
- std::bind(&SyncLogicHandler::onChronoSyncUpdate, this, _1),
- chronosync::Socket::DEFAULT_NAME, chronosync::Socket::DEFAULT_VALIDATOR,
- syncInterestLifetime, fixedSession);
+ m_syncLogic = std::make_shared<chronosync::Logic>(*facePtr, m_syncPrefix, m_nameLsaUserPrefix,
+ std::bind(&SyncLogicHandler::onChronoSyncUpdate, this, _1),
+ chronosync::Logic::DEFAULT_NAME,
+ chronosync::Logic::DEFAULT_VALIDATOR,
+ chronosync::Logic::DEFAULT_RESET_TIMER,
+ chronosync::Logic::DEFAULT_CANCEL_RESET_TIMER,
+ chronosync::Logic::DEFAULT_RESET_INTEREST_LIFETIME,
+ syncInterestLifetime,
+ chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS,
+ chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME,
+ fixedSession);
if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
- m_syncSocket->addSyncNode(m_adjLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
+ m_syncLogic->addUserNode(m_adjLsaUserPrefix, chronosync::Logic::DEFAULT_NAME, fixedSession);
}
else if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
- m_syncSocket->addSyncNode(m_coorLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
+ m_syncLogic->addUserNode(m_coorLsaUserPrefix, chronosync::Logic::DEFAULT_NAME, fixedSession);
}
else {
- m_syncSocket->addSyncNode(m_adjLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
- m_syncSocket->addSyncNode(m_coorLsaUserPrefix, chronosync::Socket::DEFAULT_NAME, fixedSession);
+ m_syncLogic->addUserNode(m_adjLsaUserPrefix, chronosync::Logic::DEFAULT_NAME, fixedSession);
+ m_syncLogic->addUserNode(m_coorLsaUserPrefix, chronosync::Logic::DEFAULT_NAME, fixedSession);
}
}
@@ -154,21 +161,21 @@
void
SyncLogicHandler::publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo)
{
- if (m_syncSocket == nullptr) {
- NLSR_LOG_FATAL("Cannot publish routing update; SyncSocket does not exist");
+ if (m_syncLogic == nullptr) {
+ NLSR_LOG_FATAL("Cannot publish routing update; SyncLogic does not exist");
- BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncSocket does not exist"));
+ BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncLogic does not exist"));
}
switch (type) {
case Lsa::Type::ADJACENCY:
- publishSyncUpdate(m_adjLsaUserPrefix, seqNo);
+ m_syncLogic->updateSeqNo(seqNo, m_adjLsaUserPrefix);
break;
case Lsa::Type::COORDINATE:
- publishSyncUpdate(m_coorLsaUserPrefix, seqNo);
+ m_syncLogic->updateSeqNo(seqNo, m_coorLsaUserPrefix);
break;
case Lsa::Type::NAME:
- publishSyncUpdate(m_nameLsaUserPrefix, seqNo);
+ m_syncLogic->updateSeqNo(seqNo, m_nameLsaUserPrefix);
break;
default:
break;
@@ -192,16 +199,4 @@
m_coorLsaUserPrefix.append(std::to_string(Lsa::Type::COORDINATE));
}
-void
-SyncLogicHandler::publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo)
-{
- NLSR_LOG_DEBUG("Publishing Sync Update. Prefix: " << updatePrefix << " Seq No: " << seqNo);
-
- ndn::Name updateName(updatePrefix);
- std::string data("NoData");
-
- m_syncSocket->publishData(reinterpret_cast<const uint8_t*>(data.c_str()), data.size(),
- ndn::time::milliseconds(1000), seqNo, updateName);
-}
-
} // namespace nlsr
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index f4bd31a..8be327c 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -29,7 +29,7 @@
#include <ndn-cxx/face.hpp>
#include <ndn-cxx/util/signal.hpp>
-#include <ChronoSync/socket.hpp>
+#include <ChronoSync/logic.hpp>
#include <boost/throw_exception.hpp>
class InterestManager;
@@ -87,7 +87,7 @@
void
publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
- /*! \brief Create and configure a socket to enable ChronoSync for this NLSR.
+ /*! \brief Create and configure a Logic object to enable ChronoSync for this NLSR.
*
* 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
@@ -95,9 +95,9 @@
* \sa Nlsr::initialize
*/
void
- createSyncSocket(const ndn::Name& syncPrefix,
- const ndn::time::milliseconds& syncInterestLifetime =
- ndn::time::milliseconds(SYNC_INTEREST_LIFETIME_DEFAULT));
+ createSyncLogic(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
@@ -118,21 +118,12 @@
processUpdateFromSync(const ndn::Name& originRouter,
const ndn::Name& updateName, const uint64_t& seqNo);
- /*! \brief Instruct ChronoSync, via the sync socket, to publish an update.
- *
- * Each ChronoSync instance maintains its own PIT for sync
- * updates. This function creates a data that satisfies that update,
- * so that the interested routers will know new data is available.
- */
- void
- publishSyncUpdate(const ndn::Name& updatePrefix, uint64_t seqNo);
-
public:
std::unique_ptr<OnNewLsa> onNewLsa;
private:
ndn::Face& m_syncFace;
- std::shared_ptr<chronosync::Socket> m_syncSocket;
+ std::shared_ptr<chronosync::Logic> m_syncLogic;
ndn::Name m_syncPrefix;
IsLsaNew m_isLsaNew;
const ConfParameter& m_confParam;
diff --git a/src/nlsr.cpp b/src/nlsr.cpp
index 58d4441..2823a74 100644
--- a/src/nlsr.cpp
+++ b/src/nlsr.cpp
@@ -260,8 +260,8 @@
m_nlsrLsdb.getSequencingManager().setSeqFileDirectory(m_confParam.getSeqFileDir());
m_nlsrLsdb.getSequencingManager().initiateSeqNoFromFile(m_confParam.getHyperbolicState());
- m_nlsrLsdb.getSyncLogicHandler().createSyncSocket(m_confParam.getChronosyncPrefix(),
- m_confParam.getSyncInterestLifetime());
+ m_nlsrLsdb.getSyncLogicHandler().createSyncLogic(m_confParam.getChronosyncPrefix(),
+ m_confParam.getSyncInterestLifetime());
// Logging start
m_confParam.writeLog();
diff --git a/tests/test-sync-logic-handler.cpp b/tests/test-sync-logic-handler.cpp
index 9f8192e..ab9732d 100644
--- a/tests/test-sync-logic-handler.cpp
+++ b/tests/test-sync-logic-handler.cpp
@@ -99,7 +99,7 @@
BOOST_AUTO_TEST_CASE(UpdateForOtherLS)
{
SyncLogicHandler sync{face, testIsLsaNew, conf};
- sync.createSyncSocket(conf.getChronosyncPrefix());
+ sync.createSyncLogic(conf.getChronosyncPrefix());
std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::ADJACENCY};
@@ -129,7 +129,7 @@
conf.setHyperbolicState(HYPERBOLIC_STATE_ON);
SyncLogicHandler sync{face, testIsLsaNew, conf};
- sync.createSyncSocket(conf.getChronosyncPrefix());
+ sync.createSyncLogic(conf.getChronosyncPrefix());
uint64_t syncSeqNo = 1;
std::vector<Lsa::Type> lsaTypes = {Lsa::Type::NAME, Lsa::Type::COORDINATE};
@@ -157,7 +157,7 @@
conf.setHyperbolicState(HYPERBOLIC_STATE_DRY_RUN);
SyncLogicHandler sync{face, testIsLsaNew, conf};
- sync.createSyncSocket(conf.getChronosyncPrefix());
+ sync.createSyncLogic(conf.getChronosyncPrefix());
for (const Lsa::Type& lsaType : lsaTypes) {
uint64_t syncSeqNo = 1;
@@ -184,7 +184,7 @@
const uint64_t sequenceNumber = 1;
SyncLogicHandler sync{face, testIsLsaNew, conf};
- sync.createSyncSocket(conf.getChronosyncPrefix());
+ sync.createSyncLogic(conf.getChronosyncPrefix());
for (const Lsa::Type& lsaType : lsaTypes) {
// To ensure that we get correctly-separated components, create
@@ -210,7 +210,7 @@
const uint64_t sequenceNumber = 1;
SyncLogicHandler sync{face, testIsLsaNew, conf};
- sync.createSyncSocket(conf.getChronosyncPrefix());
+ sync.createSyncLogic(conf.getChronosyncPrefix());
for (const Lsa::Type& lsaType : lsaTypes) {
ndn::Name updateName{CONFIG_SITE};
@@ -238,7 +238,7 @@
const uint64_t sequenceNumber = 1;
SyncLogicHandler sync{face, testLsaAlwaysFalse, conf};
- sync.createSyncSocket(conf.getChronosyncPrefix());
+ sync.createSyncLogic(conf.getChronosyncPrefix());
ndn::util::signal::ScopedConnection connection = sync.onNewLsa->connect(
[&] (const ndn::Name& routerName, const uint64_t& sequenceNumber) {
BOOST_FAIL("An update for an LSA with non-new sequence number should not emit!");
@@ -281,7 +281,7 @@
NB: This test is as much an Nlsr class test as a
SyncLogicHandler class test, but it rides the line and ends up here.
*/
-BOOST_AUTO_TEST_CASE(CreateSyncSocketOnInitialization) // Bug #2649
+BOOST_AUTO_TEST_CASE(createSyncLogicOnInitialization) // Bug #2649
{
nlsr.initialize();