File name format change and Removed warning messages (Except warning from boost for Logging)
Change-Id: If3a3a5411d377d925527fc3e8809c228a9a81e26
diff --git a/src/communication/sync-logic-handler.cpp b/src/communication/sync-logic-handler.cpp
new file mode 100644
index 0000000..a38fe98
--- /dev/null
+++ b/src/communication/sync-logic-handler.cpp
@@ -0,0 +1,156 @@
+#include "nlsr.hpp"
+#include "sync-logic-handler.hpp"
+#include "security/key-manager.hpp"
+#include "utility/tokenizer.hpp"
+
+
+namespace nlsr {
+
+void
+SyncLogicHandler::createSyncSocket(Nlsr& pnlsr)
+{
+ std::cout << "Creating Sync socket ......" << std::endl;
+ std::cout << "Sync prefix: " << m_syncPrefix.toUri() << std::endl;
+ m_syncSocket = make_shared<Sync::SyncSocket>(m_syncPrefix, m_validator,
+ m_syncFace,
+ bind(&SyncLogicHandler::nsyncUpdateCallBack, this,
+ _1, _2, boost::ref(pnlsr)),
+ bind(&SyncLogicHandler::nsyncRemoveCallBack, this,
+ _1, boost::ref(pnlsr)));
+}
+
+void
+SyncLogicHandler::nsyncUpdateCallBack(const vector<Sync::MissingDataInfo>& v,
+ Sync::SyncSocket* socket, Nlsr& pnlsr)
+{
+ std::cout << "nsyncUpdateCallBack called ...." << std::endl;
+ int n = v.size();
+ for (int i = 0; i < n; i++)
+ {
+ std::cout << "Data Name: " << v[i].prefix << " Seq: " << v[i].high.getSeq() <<
+ endl;
+ processUpdateFromSync(v[i].prefix, v[i].high.getSeq(), pnlsr);
+ }
+}
+
+void
+SyncLogicHandler::nsyncRemoveCallBack(const string& prefix, Nlsr& pnlsr)
+{
+ std::cout << "nsyncRemoveCallBack called ...." << std::endl;
+}
+
+void
+SyncLogicHandler::removeRouterFromSyncing(string& routerPrefix)
+{
+}
+
+void
+SyncLogicHandler::processUpdateFromSync(std::string updateName,
+ uint64_t seqNo, Nlsr& pnlsr)
+{
+ Tokenizer nt(updateName, "/");
+ string chkString("LSA");
+ if (nt.doesTokenExist(chkString))
+ {
+ //process LSA Update here
+ string routerName = nt.getTokenString(nt.getTokenPosition(chkString) + 1);
+ processRoutingUpdateFromSync(routerName, seqNo, pnlsr);
+ }
+ chkString = "keys";
+ if (nt.doesTokenExist(chkString))
+ {
+ //process keys update here
+ std::string certName = nt.getTokenString(0);
+ processKeysUpdateFromSync(certName, seqNo, pnlsr);
+ }
+}
+
+void
+SyncLogicHandler::processRoutingUpdateFromSync(std::string routerName,
+ uint64_t seqNo, Nlsr& pnlsr)
+{
+ if (routerName != pnlsr.getConfParameter().getRouterPrefix())
+ {
+ SequencingManager sm(seqNo);
+ std::cout << sm;
+ std::cout << "Router Name: " << routerName << endl;
+ if (pnlsr.getLsdb().isNameLsaNew(routerName + "/1", sm.getNameLsaSeq()))
+ {
+ std::cout << "Updated Name LSA. Need to fetch it" << std::endl;
+ string lsaPrefix =
+ pnlsr.getConfParameter().getChronosyncLsaPrefix() +
+ routerName + "/1/" +
+ boost::lexical_cast<std::string>(sm.getNameLsaSeq());
+ pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
+ pnlsr.getConfParameter().getInterestResendTime());
+ }
+ if (pnlsr.getLsdb().isAdjLsaNew(routerName + "/2", sm.getAdjLsaSeq()))
+ {
+ std::cout << "Updated Adj LSA. Need to fetch it" << std::endl;
+ string lsaPrefix =
+ pnlsr.getConfParameter().getChronosyncLsaPrefix() +
+ routerName + "/2/" +
+ boost::lexical_cast<std::string>(sm.getAdjLsaSeq());
+ pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
+ pnlsr.getConfParameter().getInterestResendTime());
+ }
+ if (pnlsr.getLsdb().isCorLsaNew(routerName + "/3", sm.getCorLsaSeq()))
+ {
+ std::cout << "Updated Cor LSA. Need to fetch it" << std::endl;
+ string lsaPrefix =
+ pnlsr.getConfParameter().getChronosyncLsaPrefix() +
+ routerName + "/3/" +
+ boost::lexical_cast<std::string>(sm.getCorLsaSeq());
+ pnlsr.getIm().expressInterest(pnlsr, lsaPrefix, 3,
+ pnlsr.getConfParameter().getInterestResendTime());
+ }
+ }
+}
+
+void
+SyncLogicHandler::processKeysUpdateFromSync(std::string certName,
+ uint64_t seqNo, Nlsr& pnlsr)
+{
+ std::cout << "Cert Name: " << certName << std::endl;
+ if (pnlsr.getKeyManager().isNewCertificate(certName, seqNo))
+ {
+ string certNamePrefix = certName + "/" +
+ boost::lexical_cast<string>(seqNo);
+ pnlsr.getIm().expressInterest(pnlsr, certNamePrefix, 3,
+ pnlsr.getConfParameter().getInterestResendTime());
+ }
+}
+
+void
+SyncLogicHandler::publishRoutingUpdate(SequencingManager& sm,
+ string updatePrefix)
+{
+ sm.writeSeqNoToFile();
+ publishSyncUpdate(updatePrefix, sm.getCombinedSeqNo());
+}
+
+void
+SyncLogicHandler::publishKeyUpdate(KeyManager& km)
+{
+ publishSyncUpdate(km.getProcessCertName().toUri(), km.getCertSeqNo());
+}
+
+void
+SyncLogicHandler::publishIdentityUpdate(string identityName)
+{
+ publishSyncUpdate(identityName, 0);
+}
+
+void
+SyncLogicHandler::publishSyncUpdate(string updatePrefix, uint64_t seqNo)
+{
+ std::cout << "Publishing Sync Update ......" << std::endl;
+ std::cout << "Update in prefix: " << updatePrefix << std::endl;
+ std::cout << "Seq No: " << seqNo << std::endl;
+ ndn::Name updateName(updatePrefix);
+ string data("NoData");
+ m_syncSocket->publishData(updateName, 0, data.c_str(), data.size(), 1000,
+ seqNo);
+}
+
+}//namespace nlsr