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 | /* |
Varun Patil | 7543f59 | 2023-07-18 17:56:11 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2023, 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 | #include "sync-protocol-adapter.hpp" |
| 23 | #include "logger.hpp" |
| 24 | |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 25 | namespace nlsr { |
| 26 | |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 27 | INIT_LOGGER(SyncProtocolAdapter); |
| 28 | |
| 29 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 30 | const auto FIXED_SESSION = ndn::name::Component::fromNumber(0); |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 31 | #endif |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 32 | |
| 33 | SyncProtocolAdapter::SyncProtocolAdapter(ndn::Face& face, |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 34 | ndn::KeyChain& keyChain, |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 35 | SyncProtocol syncProtocol, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 36 | const ndn::Name& syncPrefix, |
| 37 | const ndn::Name& userPrefix, |
| 38 | ndn::time::milliseconds syncInterestLifetime, |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 39 | SyncUpdateCallback syncUpdateCallback) |
| 40 | : m_syncProtocol(syncProtocol) |
| 41 | , m_syncUpdateCallback(std::move(syncUpdateCallback)) |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 42 | { |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 43 | switch (m_syncProtocol) { |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 44 | #ifdef HAVE_CHRONOSYNC |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 45 | case SyncProtocol::CHRONOSYNC: |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 46 | NDN_LOG_DEBUG("Using ChronoSync"); |
| 47 | m_chronoSyncLogic = std::make_shared<chronosync::Logic>(face, |
| 48 | syncPrefix, |
| 49 | userPrefix, |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 50 | [this] (auto&&... args) { onChronoSyncUpdate(std::forward<decltype(args)>(args)...); }, |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 51 | chronosync::Logic::DEFAULT_NAME, |
| 52 | chronosync::Logic::DEFAULT_VALIDATOR, |
| 53 | chronosync::Logic::DEFAULT_RESET_TIMER, |
| 54 | chronosync::Logic::DEFAULT_CANCEL_RESET_TIMER, |
| 55 | chronosync::Logic::DEFAULT_RESET_INTEREST_LIFETIME, |
| 56 | syncInterestLifetime, |
| 57 | chronosync::Logic::DEFAULT_SYNC_REPLY_FRESHNESS, |
| 58 | chronosync::Logic::DEFAULT_RECOVERY_INTEREST_LIFETIME, |
| 59 | FIXED_SESSION); |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 60 | break; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 61 | #endif // HAVE_CHRONOSYNC |
| 62 | #ifdef HAVE_PSYNC |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 63 | case SyncProtocol::PSYNC: |
| 64 | NDN_LOG_DEBUG("Using PSync"); |
| 65 | m_psyncLogic = std::make_shared<psync::FullProducer>(face, |
| 66 | keyChain, |
| 67 | 80, |
| 68 | syncPrefix, |
| 69 | userPrefix, |
| 70 | [this] (auto&&... args) { onPSyncUpdate(std::forward<decltype(args)>(args)...); }, |
| 71 | syncInterestLifetime); |
| 72 | break; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 73 | #endif // HAVE_PSYNC |
| 74 | #ifdef HAVE_SVS |
| 75 | case SyncProtocol::SVS: |
| 76 | NDN_LOG_DEBUG("Using SVS"); |
| 77 | m_svsCore = std::make_shared<ndn::svs::SVSyncCore>(face, |
| 78 | syncPrefix, |
| 79 | [this] (auto&&... args) { onSvsUpdate(std::forward<decltype(args)>(args)...); }); |
| 80 | break; |
| 81 | #endif // HAVE_SVS |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 82 | default: |
| 83 | NDN_CXX_UNREACHABLE; |
| 84 | } |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | void |
| 88 | SyncProtocolAdapter::addUserNode(const ndn::Name& userPrefix) |
| 89 | { |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 90 | switch (m_syncProtocol) { |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 91 | #ifdef HAVE_CHRONOSYNC |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 92 | case SyncProtocol::CHRONOSYNC: |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 93 | m_chronoSyncLogic->addUserNode(userPrefix, chronosync::Logic::DEFAULT_NAME, FIXED_SESSION); |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 94 | break; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 95 | #endif // HAVE_CHRONOSYNC |
| 96 | #ifdef HAVE_PSYNC |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 97 | case SyncProtocol::PSYNC: |
| 98 | m_psyncLogic->addUserNode(userPrefix); |
| 99 | break; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 100 | #endif // HAVE_PSYNC |
| 101 | #ifdef HAVE_SVS |
| 102 | case SyncProtocol::SVS: |
| 103 | break; |
| 104 | #endif // HAVE_SVS |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 105 | default: |
| 106 | NDN_CXX_UNREACHABLE; |
| 107 | } |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | void |
| 111 | SyncProtocolAdapter::publishUpdate(const ndn::Name& userPrefix, uint64_t seq) |
| 112 | { |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 113 | switch (m_syncProtocol) { |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 114 | #ifdef HAVE_CHRONOSYNC |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 115 | case SyncProtocol::CHRONOSYNC: |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 116 | m_chronoSyncLogic->updateSeqNo(seq, userPrefix); |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 117 | break; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 118 | #endif // HAVE_CHRONOSYNC |
| 119 | #ifdef HAVE_PSYNC |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 120 | case SyncProtocol::PSYNC: |
| 121 | m_psyncLogic->publishName(userPrefix, seq); |
| 122 | break; |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 123 | #endif // HAVE_PSYNC |
| 124 | #ifdef HAVE_SVS |
| 125 | case SyncProtocol::SVS: |
| 126 | m_svsCore->updateSeqNo(seq, userPrefix); |
| 127 | break; |
| 128 | #endif // HAVE_SVS |
Davide Pesavento | 1954a0c | 2022-09-30 15:56:04 -0400 | [diff] [blame] | 129 | default: |
| 130 | NDN_CXX_UNREACHABLE; |
| 131 | } |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Ashlesh Gawande | 30d96e4 | 2021-03-21 19:15:33 -0700 | [diff] [blame] | 134 | #ifdef HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 135 | void |
| 136 | SyncProtocolAdapter::onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates) |
| 137 | { |
| 138 | NLSR_LOG_TRACE("Received ChronoSync update event"); |
| 139 | |
| 140 | for (const auto& update : updates) { |
| 141 | // Remove FIXED_SESSION |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 142 | m_syncUpdateCallback(update.session.getPrefix(-1), update.high, 0); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 143 | } |
| 144 | } |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 145 | #endif // HAVE_CHRONOSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 146 | |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 147 | #ifdef HAVE_PSYNC |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 148 | void |
| 149 | SyncProtocolAdapter::onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates) |
| 150 | { |
| 151 | NLSR_LOG_TRACE("Received PSync update event"); |
| 152 | |
| 153 | for (const auto& update : updates) { |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 154 | m_syncUpdateCallback(update.prefix, update.highSeq, update.incomingFace); |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 155 | } |
| 156 | } |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 157 | #endif // HAVE_PSYNC |
| 158 | |
| 159 | #ifdef HAVE_SVS |
| 160 | void |
| 161 | SyncProtocolAdapter::onSvsUpdate(const std::vector<ndn::svs::MissingDataInfo>& updates) |
| 162 | { |
| 163 | NLSR_LOG_TRACE("Received SVS update event"); |
| 164 | |
| 165 | for (const auto& update : updates) { |
Varun Patil | 7543f59 | 2023-07-18 17:56:11 -0700 | [diff] [blame^] | 166 | m_syncUpdateCallback(update.nodeId, update.high, update.incomingFace); |
Varun Patil | 7d2d689 | 2022-10-14 12:50:30 -0700 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | #endif // HAVE_SVS |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 170 | |
Alexander Afanasyev | 135288c | 2022-04-23 23:06:56 -0400 | [diff] [blame] | 171 | } // namespace nlsr |