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