src: change initialization order

Send Hello Interest after route to neighbor is successfully registered
--> First Hello interval is eliminated
--> After Hello Nack, wait exponentially before processing it as a timeout
Register sync route for each neighbor after its Hello Data is validated

refs: #5009

Change-Id: Ice39a591f1e58e474b494d93c913fa45e10f24f2
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 1784267..308457e 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -33,59 +33,29 @@
 
 INIT_LOGGER(SyncLogicHandler);
 
-template<class T>
-class NullDeleter
-{
-public:
-  void
-  operator()(T*)
-  {
-  }
-};
-
 SyncLogicHandler::SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew,
                                    const ConfParameter& conf)
   : onNewLsa(std::make_unique<OnNewLsa>())
   , m_syncFace(face)
   , m_isLsaNew(isLsaNew)
   , m_confParam(conf)
+  , m_nameLsaUserPrefix(ndn::Name(m_confParam.getSyncUserPrefix()).append(std::to_string(Lsa::Type::NAME)))
+  , m_syncLogic(m_syncFace, m_confParam.getSyncProtocol(), m_confParam.getSyncPrefix(),
+                m_nameLsaUserPrefix, m_confParam.getSyncInterestLifetime(),
+                std::bind(&SyncLogicHandler::processUpdate, this, _1, _2))
 {
-  createSyncLogic(conf.getSyncPrefix());
-}
+  m_adjLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
+                         .append(std::to_string(Lsa::Type::ADJACENCY));
+  m_coorLsaUserPrefix = ndn::Name(m_confParam.getSyncUserPrefix())
+                         .append(std::to_string(Lsa::Type::COORDINATE));
 
-void
-SyncLogicHandler::createSyncLogic(const ndn::Name& syncPrefix, const ndn::time::milliseconds& syncInterestLifetime)
-{
-  if (m_syncLogic != nullptr) {
-    NLSR_LOG_WARN("Trying to create Sync Logic object, but Sync Logic object already exists");
-    return;
+  if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF ||
+      m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
+    m_syncLogic.addUserNode(m_adjLsaUserPrefix);
   }
-
-  // Build LSA sync update prefix
-  buildUpdatePrefix();
-
-  NLSR_LOG_DEBUG("Creating Sync Logic object. Sync Prefix: " << syncPrefix);
-
-  // 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>());
-
-  m_syncLogic = std::make_shared<SyncProtocolAdapter>(*facePtr,
-                  m_confParam.getSyncProtocol(),
-                  syncPrefix,
-                  m_nameLsaUserPrefix,
-                  syncInterestLifetime,
-                  std::bind(&SyncLogicHandler::processUpdate, this, _1, _2));
-
-  if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_OFF) {
-    m_syncLogic->addUserNode(m_adjLsaUserPrefix);
-  }
-  else if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
-    m_syncLogic->addUserNode(m_coorLsaUserPrefix);
-  }
-  else {
-    m_syncLogic->addUserNode(m_adjLsaUserPrefix);
-    m_syncLogic->addUserNode(m_coorLsaUserPrefix);
+  else if (m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON ||
+           m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_DRY_RUN) {
+    m_syncLogic.addUserNode(m_coorLsaUserPrefix);
   }
 }
 
@@ -148,42 +118,19 @@
 void
 SyncLogicHandler::publishRoutingUpdate(const Lsa::Type& type, const uint64_t& seqNo)
 {
-  if (m_syncLogic == nullptr) {
-    NLSR_LOG_FATAL("Cannot publish routing update; SyncLogic does not exist");
-
-    BOOST_THROW_EXCEPTION(SyncLogicHandler::Error("Cannot publish routing update; SyncLogic does not exist"));
-  }
-
   switch (type) {
   case Lsa::Type::ADJACENCY:
-    m_syncLogic->publishUpdate(m_adjLsaUserPrefix, seqNo);
+    m_syncLogic.publishUpdate(m_adjLsaUserPrefix, seqNo);
     break;
   case Lsa::Type::COORDINATE:
-    m_syncLogic->publishUpdate(m_coorLsaUserPrefix, seqNo);
+    m_syncLogic.publishUpdate(m_coorLsaUserPrefix, seqNo);
     break;
   case Lsa::Type::NAME:
-    m_syncLogic->publishUpdate(m_nameLsaUserPrefix, seqNo);
+    m_syncLogic.publishUpdate(m_nameLsaUserPrefix, seqNo);
     break;
   default:
     break;
   }
 }
 
-void
-SyncLogicHandler::buildUpdatePrefix()
-{
-  ndn::Name updatePrefix = m_confParam.getLsaPrefix();
-  updatePrefix.append(m_confParam.getSiteName());
-  updatePrefix.append(m_confParam.getRouterName());
-
-  m_nameLsaUserPrefix = updatePrefix;
-  m_nameLsaUserPrefix.append(std::to_string(Lsa::Type::NAME));
-
-  m_adjLsaUserPrefix = updatePrefix;
-  m_adjLsaUserPrefix.append(std::to_string(Lsa::Type::ADJACENCY));
-
-  m_coorLsaUserPrefix = updatePrefix;
-  m_coorLsaUserPrefix.append(std::to_string(Lsa::Type::COORDINATE));
-}
-
 } // namespace nlsr