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> |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 28 | #include <ndn-cxx/security/key-chain.hpp> |
| 29 | |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 30 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 31 | #include <ChronoSync/logic.hpp> |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 32 | #endif |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 33 | #ifdef HAVE_PSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 34 | #include <PSync/full-producer.hpp> |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 35 | #endif |
| 36 | #ifdef HAVE_SVS |
| 37 | #include <ndn-svs/core.hpp> |
| 38 | #endif |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 39 | |
| 40 | namespace nlsr { |
| 41 | |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 42 | using SyncUpdateCallback = std::function<void(const ndn::Name& updateName, |
| 43 | uint64_t seqNo, uint64_t incomingFaceId)>; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 44 | |
| 45 | class SyncProtocolAdapter |
| 46 | { |
| 47 | public: |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 48 | SyncProtocolAdapter(ndn::Face& face, |
| 49 | ndn::KeyChain& keyChain, |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 50 | SyncProtocol syncProtocol, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 51 | const ndn::Name& syncPrefix, |
| 52 | const ndn::Name& userPrefix, |
| 53 | ndn::time::milliseconds syncInterestLifetime, |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 54 | SyncUpdateCallback syncUpdateCallback); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 55 | |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 56 | /*! \brief Add user node to Sync |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 57 | * |
| 58 | * \param userPrefix the Name under which the application will publishData |
| 59 | */ |
| 60 | void |
| 61 | addUserNode(const ndn::Name& userPrefix); |
| 62 | |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 63 | /*! \brief Publish update to Sync |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 64 | * |
| 65 | * NLSR forces sequences number on the sync protocol |
| 66 | * as it manages is its own sequence number by storing it in a file. |
| 67 | * |
| 68 | * \param userPrefix the Name to be updated |
| 69 | * \param seq the sequence of userPrefix |
| 70 | */ |
| 71 | void |
| 72 | publishUpdate(const ndn::Name& userPrefix, uint64_t seq); |
| 73 | |
| 74 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 75 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 76 | /*! \brief Hook function to call whenever ChronoSync detects new data. |
| 77 | * |
| 78 | * This function packages the sync information into discrete updates |
| 79 | * and passes those off to another function, m_syncUpdateCallback. |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 80 | * |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 81 | * \param updates A container with the new information sync has received |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 82 | */ |
| 83 | void |
| 84 | onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates); |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 85 | #endif // HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 86 | |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 87 | #ifdef HAVE_PSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 88 | /*! \brief Hook function to call whenever PSync detects new data. |
| 89 | * |
| 90 | * This function packages the sync information into discrete updates |
| 91 | * and passes those off to another function, m_syncUpdateCallback. |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 92 | * |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 93 | * \param updates A container with the new information sync has received |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 94 | */ |
| 95 | void |
| 96 | onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates); |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 97 | #endif // HAVE_PSYNC |
| 98 | |
| 99 | #ifdef HAVE_SVS |
| 100 | /*! \brief Hook function to call whenever SVS detects new data. |
| 101 | * |
| 102 | * This function packages the sync information into discrete updates |
| 103 | * and passes those off to another function, m_syncUpdateCallback. |
| 104 | * |
| 105 | * \param updates A container with the new information sync has received |
| 106 | */ |
| 107 | void |
| 108 | onSvsUpdate(const std::vector<ndn::svs::MissingDataInfo>& updates); |
| 109 | #endif // HAVE_SVS |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 110 | |
| 111 | private: |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 112 | SyncProtocol m_syncProtocol; |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 113 | SyncUpdateCallback m_syncUpdateCallback; |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 114 | |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 115 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 116 | std::shared_ptr<chronosync::Logic> m_chronoSyncLogic; |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 117 | #endif |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 118 | #ifdef HAVE_PSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 119 | std::shared_ptr<psync::FullProducer> m_psyncLogic; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 120 | #endif |
| 121 | #ifdef HAVE_SVS |
| 122 | std::shared_ptr<ndn::svs::SVSyncCore> m_svsCore; |
| 123 | #endif |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace nlsr |
| 127 | |
| 128 | #endif // NLSR_SYNC_PROTOCOL_ADAPTER_HPP |