sync: removed ref to lsdb.
Sync now emits to a signal whenever a new LSA is detected, and the LSDB
listens to this signal. Sync consults a function object gotten at ctor time
to determine LSA newness. This means Sync no longer needs a reference to
the LSDB, and LSA newness criteria can be freely manipulated.
Change-Id: Ifce3ebfc921ad846fcfa12d99c78f3b337180827
refs: #4264
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
index 5a4d709..95b656c 100644
--- a/src/communication/sync-logic-handler.cpp
+++ b/src/communication/sync-logic-handler.cpp
@@ -20,13 +20,11 @@
**/
#include "sync-logic-handler.hpp"
-
#include "common.hpp"
#include "conf-parameter.hpp"
-#include "logger.hpp"
#include "lsa.hpp"
-#include "lsdb.hpp"
#include "utility/name-helper.hpp"
+#include "logger.hpp"
namespace nlsr {
@@ -45,10 +43,10 @@
}
};
-SyncLogicHandler::SyncLogicHandler(ndn::Face& face,
- Lsdb& lsdb, ConfParameter& conf)
- : m_syncFace(face)
- , m_lsdb(lsdb)
+SyncLogicHandler::SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew, ConfParameter& conf)
+ : onNewLsa(ndn::make_unique<OnNewLsa>())
+ , m_syncFace(face)
+ , m_isLsaNew(isLsaNew)
, m_confParam(conf)
{
}
@@ -125,7 +123,7 @@
_LOG_DEBUG("Received sync update with higher " << lsaType
<< " sequence number than entry in LSDB");
- if (isLsaNew(originRouter, lsaType, seqNo)) {
+ if (m_isLsaNew(originRouter, lsaType, seqNo)) {
if (lsaType == AdjLsa::TYPE_STRING && seqNo != 0 &&
m_confParam.getHyperbolicState() == HYPERBOLIC_STATE_ON) {
_LOG_ERROR("Got an update for adjacency LSA when hyperbolic routing"
@@ -139,44 +137,11 @@
<< " is enabled. Not going to fetch.");
return;
}
- expressInterestForLsa(updateName, seqNo);
+ (*onNewLsa)(updateName, seqNo);
}
}
}
-bool
-SyncLogicHandler::isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
- const uint64_t& seqNo)
-{
- ndn::Name lsaKey = originRouter;
- lsaKey.append(lsaType);
-
- if (lsaType == NameLsa::TYPE_STRING)
- {
- return m_lsdb.isNameLsaNew(lsaKey, seqNo);
- }
- else if (lsaType == AdjLsa::TYPE_STRING)
- {
- return m_lsdb.isAdjLsaNew(lsaKey, seqNo);
- }
- else if (lsaType == CoordinateLsa::TYPE_STRING)
- {
- return m_lsdb.isCoordinateLsaNew(lsaKey, seqNo);
- }
-
- return false;
-}
-
-void
-SyncLogicHandler::expressInterestForLsa(const ndn::Name& updateName,
- const uint64_t& seqNo)
-{
- ndn::Name interest(updateName);
- interest.appendNumber(seqNo);
-
- m_lsdb.expressInterest(interest, 0);
-}
-
void
SyncLogicHandler::publishRoutingUpdate(const ndn::Name& type, const uint64_t& seqNo)
{
diff --git a/src/communication/sync-logic-handler.hpp b/src/communication/sync-logic-handler.hpp
index 6de6113..b46ac7c 100644
--- a/src/communication/sync-logic-handler.hpp
+++ b/src/communication/sync-logic-handler.hpp
@@ -23,13 +23,11 @@
#define NLSR_SYNC_LOGIC_HANDLER_HPP
#include "test-access-control.hpp"
+#include "signals.hpp"
#include <ndn-cxx/face.hpp>
+#include <ndn-cxx/util/signal.hpp>
#include <ChronoSync/socket.hpp>
-
-#include <iostream>
-#include <unistd.h>
-#include <boost/cstdint.hpp>
#include <boost/throw_exception.hpp>
class InterestManager;
@@ -37,7 +35,6 @@
namespace nlsr {
class ConfParameter;
-class Lsdb;
/*! \brief NLSR-to-ChronoSync interaction point
*
@@ -50,6 +47,9 @@
class SyncLogicHandler
{
public:
+ using IsLsaNew =
+ std::function<bool(const ndn::Name&, const std::string& lsaType, const uint64_t&)>;
+
class Error : public std::runtime_error
{
public:
@@ -60,7 +60,7 @@
}
};
- SyncLogicHandler(ndn::Face& face, Lsdb& lsdb, ConfParameter& conf);
+ SyncLogicHandler(ndn::Face& face, const IsLsaNew& isLsaNew, ConfParameter& conf);
/*! \brief Hook function to call whenever sync detects new data.
*
@@ -112,21 +112,6 @@
processUpdateFromSync(const ndn::Name& originRouter,
const ndn::Name& updateName, const uint64_t& seqNo);
- /*! \brief Consults the LSDB to determine if a sync update has a new LSA.
- *
- * Given some information about an LSA, consult the LSDB to
- * determine if the sequence number represents a new LSA from the
- * origin router.
- */
- bool
- isLsaNew(const ndn::Name& originRouter, const std::string& lsaType,
- const uint64_t& seqNo);
-
- /*! \brief Fetch an LSA of a certain type, with a certain sequence number.
- */
- void
- expressInterestForLsa(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
@@ -136,13 +121,14 @@
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;
ndn::Name m_syncPrefix;
-
-private:
- Lsdb& m_lsdb;
+ IsLsaNew m_isLsaNew;
const ConfParameter& m_confParam;
PUBLIC_WITH_TESTS_ELSE_PRIVATE: