communication: sync protocol adapater to add psync
refs: #4082
Change-Id: Ibe4649e709dfbc3cdc1f2afbfc4ff03f75a3f136
diff --git a/src/communication/sync-protocol-adapter.hpp b/src/communication/sync-protocol-adapter.hpp
new file mode 100644
index 0000000..363f02d
--- /dev/null
+++ b/src/communication/sync-protocol-adapter.hpp
@@ -0,0 +1,96 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2014-2018, The University of Memphis,
+ * Regents of the University of California,
+ * Arizona Board of Regents.
+ *
+ * This file is part of NLSR (Named-data Link State Routing).
+ * See AUTHORS.md for complete list of NLSR authors and contributors.
+ *
+ * NLSR is free software: you can redistribute it and/or modify it under the terms
+ * of the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
+ * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
+ **/
+
+#ifndef NLSR_SYNC_PROTOCOL_ADAPTER_HPP
+#define NLSR_SYNC_PROTOCOL_ADAPTER_HPP
+
+#include "conf-parameter.hpp"
+
+#include <ndn-cxx/face.hpp>
+#include <ChronoSync/logic.hpp>
+#include <PSync/full-producer.hpp>
+
+namespace nlsr {
+
+typedef std::function<void(const ndn::Name& updateName,
+ uint64_t seqNo)> SyncUpdateCallback;
+
+class SyncProtocolAdapter
+{
+public:
+ SyncProtocolAdapter(ndn::Face& facePtr,
+ int32_t syncProtocol,
+ const ndn::Name& syncPrefix,
+ const ndn::Name& userPrefix,
+ ndn::time::milliseconds syncInterestLifetime,
+ const SyncUpdateCallback& syncUpdateCallback);
+
+ /*! \brief Add user node to ChronoSync or PSync
+ *
+ * \param userPrefix the Name under which the application will publishData
+ */
+ void
+ addUserNode(const ndn::Name& userPrefix);
+
+ /*! \brief Publish update to ChronoSync or PSync
+ *
+ * NLSR forces sequences number on the sync protocol
+ * as it manages is its own sequence number by storing it in a file.
+ *
+ * \param userPrefix the Name to be updated
+ * \param seq the sequence of userPrefix
+ */
+ void
+ publishUpdate(const ndn::Name& userPrefix, uint64_t seq);
+
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
+ /*! \brief Hook function to call whenever ChronoSync detects new data.
+ *
+ * This function packages the sync information into discrete updates
+ * and passes those off to another function, m_syncUpdateCallback.
+ * \sa m_syncUpdateCallback
+ *
+ * \param v A container with the new information sync has received
+ */
+ void
+ onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates);
+
+ /*! \brief Hook function to call whenever PSync detects new data.
+ *
+ * This function packages the sync information into discrete updates
+ * and passes those off to another function, m_syncUpdateCallback.
+ * \sa m_syncUpdateCallback
+ *
+ * \param v A container with the new information sync has received
+ */
+ void
+ onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates);
+
+private:
+ int32_t m_syncProtocol;
+ SyncUpdateCallback m_syncUpdateCallback;
+ std::shared_ptr<chronosync::Logic> m_chronoSyncLogic;
+ std::shared_ptr<psync::FullProducer> m_psyncLogic;
+};
+
+} // namespace nlsr
+
+#endif // NLSR_SYNC_PROTOCOL_ADAPTER_HPP