communication: refactor SyncLogicHandler to not need a ConfParameter reference

refs #4208

Change-Id: I5194c0a775dc1581af3a6ebd2db3699892671fb4
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index cd9e17a..8193a60 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  The University of Memphis,
+ * Copyright (c) 2014-2024,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -24,8 +24,6 @@
 #include "logger.hpp"
 #include "utility/name-helper.hpp"
 
-#include <boost/lexical_cast.hpp>
-
 namespace nlsr {
 
 INIT_LOGGER(SyncLogicHandler);
@@ -33,24 +31,22 @@
 const std::string LSA_COMPONENT{"LSA"};
 
 SyncLogicHandler::SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
-                                   IsLsaNew isLsaNew, const ConfParameter& conf)
+                                   IsLsaNew isLsaNew, const SyncLogicOptions& opts)
   : m_isLsaNew(std::move(isLsaNew))
-  , m_confParam(conf)
-  , m_nameLsaUserPrefix(ndn::Name(m_confParam.getSyncUserPrefix()).append(boost::lexical_cast<std::string>(Lsa::Type::NAME)))
-  , m_syncLogic(face, keyChain, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(),
-                m_nameLsaUserPrefix, m_confParam.getSyncInterestLifetime(),
+  , m_routerPrefix(opts.routerPrefix)
+  , m_hyperbolicState(opts.hyperbolicState)
+  , m_nameLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::NAME))
+  , m_adjLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::ADJACENCY))
+  , m_coorLsaUserPrefix(makeLsaUserPrefix(opts.userPrefix, Lsa::Type::COORDINATE))
+  , m_syncLogic(face, keyChain, opts.syncProtocol, opts.syncPrefix,
+                m_nameLsaUserPrefix, opts.syncInterestLifetime,
                 std::bind(&SyncLogicHandler::processUpdate, this, _1, _2, _3))
 {
-  m_adjLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
-                         .append(boost::lexical_cast<std::string>(Lsa::Type::ADJACENCY));
-  m_coorLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
-                         .append(boost::lexical_cast<std::string>(Lsa::Type::COORDINATE));
-
-  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_ON) {
+  if (m_hyperbolicState != HYPERBOLIC_STATE_ON) {
     m_syncLogic.addUserNode(m_adjLsaUserPrefix);
   }
 
-  if (m_confParam.getHyperbolicState() != HYPERBOLIC_STATE_OFF) {
+  if (m_hyperbolicState != HYPERBOLIC_STATE_OFF) {
     m_syncLogic.addUserNode(m_coorLsaUserPrefix);
   }
 }
@@ -83,37 +79,36 @@
 {
   NLSR_LOG_DEBUG("Origin Router of update: " << originRouter);
 
-  // A router should not try to fetch its own LSA
-  if (originRouter != m_confParam.getRouterPrefix()) {
+  if (originRouter == m_routerPrefix) {
+    // A router should not try to fetch its own LSA
+    return;
+  }
 
-    Lsa::Type lsaType;
-    std::istringstream(updateName.get(updateName.size()-1).toUri()) >> lsaType;
+  auto lsaType = boost::lexical_cast<Lsa::Type>(updateName.get(-1).toUri());
+  NLSR_LOG_DEBUG("Received sync update with higher " << lsaType <<
+                  " sequence number than entry in LSDB");
 
-    NLSR_LOG_DEBUG("Received sync update with higher " << lsaType <<
-                   " sequence number than entry in LSDB");
-
-    if (m_isLsaNew(originRouter, lsaType, seqNo, incomingFaceId)) {
-      if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
-          m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
-        NLSR_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing " <<
-                       "is enabled. Not going to fetch.");
-        return;
-      }
-
-      if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
-          m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
-        NLSR_LOG_ERROR("Got an update for coordinate LSA when link-state " <<
-                       "is enabled. Not going to fetch.");
-        return;
-      }
-
-      onNewLsa(updateName, seqNo, originRouter, incomingFaceId);
+  if (m_isLsaNew(originRouter, lsaType, seqNo, incomingFaceId)) {
+    if (lsaType == Lsa::Type::ADJACENCY && seqNo != 0 &&
+        m_hyperbolicState == HYPERBOLIC_STATE_ON) {
+      NLSR_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing "
+                      "is enabled. Not going to fetch.");
+      return;
     }
+
+    if (lsaType == Lsa::Type::COORDINATE && seqNo != 0 &&
+        m_hyperbolicState == HYPERBOLIC_STATE_OFF) {
+      NLSR_LOG_ERROR("Got an update for coordinate LSA when link-state "
+                      "is enabled. Not going to fetch.");
+      return;
+    }
+
+    onNewLsa(updateName, seqNo, originRouter, incomingFaceId);
   }
 }
 
 void
-SyncLogicHandler::publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo)
+SyncLogicHandler::publishRoutingUpdate(Lsa::Type type, uint64_t seqNo)
 {
   switch (type) {
   case Lsa::Type::ADJACENCY:
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 6eee213..3782663 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2022,  The University of Memphis,
+ * Copyright (c) 2014-2024,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -28,14 +28,30 @@
 #include "sync-protocol-adapter.hpp"
 #include "test-access-control.hpp"
 
+#include <boost/lexical_cast.hpp>
+
 namespace nlsr {
 
-/*! \brief NLSR-to-ChronoSync interaction point
+struct SyncLogicOptions
+{
+  SyncProtocol syncProtocol;
+  ndn::Name syncPrefix;
+  ndn::Name userPrefix;
+  ndn::time::milliseconds syncInterestLifetime;
+  ndn::Name routerPrefix;
+  HyperbolicState hyperbolicState;
+};
+
+inline ndn::Name
+makeLsaUserPrefix(const ndn::Name& userPrefix, Lsa::Type lsaType)
+{
+  return ndn::Name(userPrefix).append(boost::lexical_cast<std::string>(lsaType));
+}
+
+/*! \brief NLSR-to-sync interaction point
  *
  * This class serves as the abstraction for the syncing portion of
- * NLSR and its components. NLSR has no particular reliance on
- * ChronoSync, except that the NLSR source would need to be modified
- * for use with other sync protocols.
+ * NLSR and its components.
  */
 class SyncLogicHandler
 {
@@ -46,11 +62,12 @@
     using std::runtime_error::runtime_error;
   };
 
-  using IsLsaNew =
-    std::function<bool(const ndn::Name&, const Lsa::Type& lsaType, const uint64_t&, uint64_t/*inFace*/)>;
+  using IsLsaNew = std::function<
+    bool (const ndn::Name& routerName, Lsa::Type lsaType, uint64_t seqNo, uint64_t inFace)
+  >;
 
   SyncLogicHandler(ndn::Face& face, ndn::KeyChain& keyChain,
-                   IsLsaNew isLsaNew, const ConfParameter& conf);
+                   IsLsaNew isLsaNew, const SyncLogicOptions& opts);
 
   /*! \brief Instruct ChronoSync to publish an update.
    *
@@ -62,7 +79,7 @@
    * \sa publishSyncUpdate
    */
   void
-  publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo);
+  publishRoutingUpdate(Lsa::Type type, uint64_t seqNo);
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   /*! \brief Callback from Sync protocol
@@ -91,7 +108,8 @@
 
 private:
   IsLsaNew m_isLsaNew;
-  const ConfParameter& m_confParam;
+  ndn::Name m_routerPrefix;
+  HyperbolicState m_hyperbolicState;
 
 PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   ndn::Name m_nameLsaUserPrefix;
diff --git a/src/conf-parameter.hpp b/src/conf-parameter.hpp
index 687aa1c..40eb7dd 100644
--- a/src/conf-parameter.hpp
+++ b/src/conf-parameter.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2023,  The University of Memphis,
+ * Copyright (c) 2014-2024,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -340,12 +340,12 @@
   }
 
   void
-  setHyperbolicState(int32_t ihc)
+  setHyperbolicState(HyperbolicState ihc)
   {
     m_hyperbolicState = ihc;
   }
 
-  int32_t
+  HyperbolicState
   getHyperbolicState() const
   {
     return m_hyperbolicState;
@@ -517,7 +517,7 @@
 
   uint32_t m_infoInterestInterval;
 
-  int32_t m_hyperbolicState;
+  HyperbolicState m_hyperbolicState;
   double m_corR;
   std::vector<double> m_corTheta;
 
diff --git a/src/lsdb.cpp b/src/lsdb.cpp
index 608b575..844de22 100644
--- a/src/lsdb.cpp
+++ b/src/lsdb.cpp
@@ -36,10 +36,17 @@
   , m_scheduler(face.getIoContext())
   , m_confParam(confParam)
   , m_sync(m_face, keyChain,
-           [this] (const auto& routerName, const Lsa::Type& lsaType,
-                   uint64_t sequenceNumber, uint64_t incomingFaceId) {
-             return isLsaNew(routerName, lsaType, sequenceNumber);
-           }, m_confParam)
+      [this] (const auto& routerName, Lsa::Type lsaType, uint64_t seqNo, uint64_t) {
+        return isLsaNew(routerName, lsaType, seqNo);
+      },
+      SyncLogicOptions{
+        confParam.getSyncProtocol(),
+        confParam.getSyncPrefix(),
+        confParam.getSyncUserPrefix(),
+        confParam.getSyncInterestLifetime(),
+        confParam.getRouterPrefix(),
+        confParam.getHyperbolicState()
+      })
   , m_lsaRefreshTime(ndn::time::seconds(m_confParam.getLsaRefreshTime()))
   , m_adjLsaBuildInterval(m_confParam.getAdjLsaBuildInterval())
   , m_thisRouterPrefix(m_confParam.getRouterPrefix())
diff --git a/src/lsdb.hpp b/src/lsdb.hpp
index 1116e98..93e1ad9 100644
--- a/src/lsdb.hpp
+++ b/src/lsdb.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2023,  The University of Memphis,
+ * Copyright (c) 2014-2024,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -220,7 +220,7 @@
     \param seqNo The sequence number to check.
   */
   bool
-  isLsaNew(const ndn::Name& originRouter, const Lsa::Type& lsaType, uint64_t seqNo) const
+  isLsaNew(const ndn::Name& originRouter, Lsa::Type lsaType, uint64_t seqNo) const
   {
     // Is the name in the LSDB and the supplied seq no is the highest so far
     auto lsaPtr = findLsa(originRouter, lsaType);