Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 2 | /* |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame^] | 3 | * Copyright (c) 2014-2022, The University of Memphis, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 4 | * Regents of the University of California, |
| 5 | * Arizona Board of Regents. |
| 6 | * |
| 7 | * This file is part of NLSR (Named-data Link State Routing). |
| 8 | * See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | * |
| 10 | * NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | * of the GNU General Public License as published by the Free Software Foundation, |
| 12 | * either version 3 of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE. See the GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along with |
| 19 | * NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 20 | */ |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 21 | |
| 22 | #ifndef NLSR_SYNC_PROTOCOL_ADAPTER_HPP |
| 23 | #define NLSR_SYNC_PROTOCOL_ADAPTER_HPP |
| 24 | |
| 25 | #include "conf-parameter.hpp" |
| 26 | |
| 27 | #include <ndn-cxx/face.hpp> |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 28 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 29 | #include <ChronoSync/logic.hpp> |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 30 | #endif |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 31 | #include <PSync/full-producer.hpp> |
| 32 | |
| 33 | namespace nlsr { |
| 34 | |
| 35 | typedef std::function<void(const ndn::Name& updateName, |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame^] | 36 | uint64_t seqNo, uint64_t incomingFaceId)> SyncUpdateCallback; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 37 | |
| 38 | class SyncProtocolAdapter |
| 39 | { |
| 40 | public: |
| 41 | SyncProtocolAdapter(ndn::Face& facePtr, |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 42 | SyncProtocol syncProtocol, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 43 | const ndn::Name& syncPrefix, |
| 44 | const ndn::Name& userPrefix, |
| 45 | ndn::time::milliseconds syncInterestLifetime, |
| 46 | const SyncUpdateCallback& syncUpdateCallback); |
| 47 | |
| 48 | /*! \brief Add user node to ChronoSync or PSync |
| 49 | * |
| 50 | * \param userPrefix the Name under which the application will publishData |
| 51 | */ |
| 52 | void |
| 53 | addUserNode(const ndn::Name& userPrefix); |
| 54 | |
| 55 | /*! \brief Publish update to ChronoSync or PSync |
| 56 | * |
| 57 | * NLSR forces sequences number on the sync protocol |
| 58 | * as it manages is its own sequence number by storing it in a file. |
| 59 | * |
| 60 | * \param userPrefix the Name to be updated |
| 61 | * \param seq the sequence of userPrefix |
| 62 | */ |
| 63 | void |
| 64 | publishUpdate(const ndn::Name& userPrefix, uint64_t seq); |
| 65 | |
| 66 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 67 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 68 | /*! \brief Hook function to call whenever ChronoSync detects new data. |
| 69 | * |
| 70 | * This function packages the sync information into discrete updates |
| 71 | * and passes those off to another function, m_syncUpdateCallback. |
| 72 | * \sa m_syncUpdateCallback |
| 73 | * |
| 74 | * \param v A container with the new information sync has received |
| 75 | */ |
| 76 | void |
| 77 | onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates); |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 78 | #endif |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 79 | |
| 80 | /*! \brief Hook function to call whenever PSync detects new data. |
| 81 | * |
| 82 | * This function packages the sync information into discrete updates |
| 83 | * and passes those off to another function, m_syncUpdateCallback. |
| 84 | * \sa m_syncUpdateCallback |
| 85 | * |
| 86 | * \param v A container with the new information sync has received |
| 87 | */ |
| 88 | void |
| 89 | onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates); |
| 90 | |
| 91 | private: |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 92 | SyncProtocol m_syncProtocol; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 93 | SyncUpdateCallback m_syncUpdateCallback; |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 94 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 95 | std::shared_ptr<chronosync::Logic> m_chronoSyncLogic; |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 96 | #endif |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 97 | std::shared_ptr<psync::FullProducer> m_psyncLogic; |
| 98 | }; |
| 99 | |
| 100 | } // namespace nlsr |
| 101 | |
| 102 | #endif // NLSR_SYNC_PROTOCOL_ADAPTER_HPP |