blob: fb5cdbee1e72fc01258b53bdee1ff0a6f6c01203 [file] [log] [blame]
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Ashlesh Gawande30d96e42021-03-21 19:15:33 -07002/*
Alexander Afanasyev135288c2022-04-23 23:06:56 -04003 * Copyright (c) 2014-2022, The University of Memphis,
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -05004 * 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 Gawande30d96e42021-03-21 19:15:33 -070020 */
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050021
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 Pesavento1954a0c2022-09-30 15:56:04 -040028#include <ndn-cxx/security/key-chain.hpp>
29
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070030#ifdef HAVE_CHRONOSYNC
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050031#include <ChronoSync/logic.hpp>
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070032#endif
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050033#include <PSync/full-producer.hpp>
34
35namespace nlsr {
36
Davide Pesavento1954a0c2022-09-30 15:56:04 -040037using SyncUpdateCallback = std::function<void(const ndn::Name& updateName,
38 uint64_t seqNo, uint64_t incomingFaceId)>;
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050039
40class SyncProtocolAdapter
41{
42public:
Davide Pesavento1954a0c2022-09-30 15:56:04 -040043 SyncProtocolAdapter(ndn::Face& face,
44 ndn::KeyChain& keyChain,
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070045 SyncProtocol syncProtocol,
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050046 const ndn::Name& syncPrefix,
47 const ndn::Name& userPrefix,
48 ndn::time::milliseconds syncInterestLifetime,
Davide Pesavento1954a0c2022-09-30 15:56:04 -040049 SyncUpdateCallback syncUpdateCallback);
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050050
51 /*! \brief Add user node to ChronoSync or PSync
52 *
53 * \param userPrefix the Name under which the application will publishData
54 */
55 void
56 addUserNode(const ndn::Name& userPrefix);
57
58 /*! \brief Publish update to ChronoSync or PSync
59 *
60 * NLSR forces sequences number on the sync protocol
61 * as it manages is its own sequence number by storing it in a file.
62 *
63 * \param userPrefix the Name to be updated
64 * \param seq the sequence of userPrefix
65 */
66 void
67 publishUpdate(const ndn::Name& userPrefix, uint64_t seq);
68
69PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070070#ifdef HAVE_CHRONOSYNC
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050071 /*! \brief Hook function to call whenever ChronoSync detects new data.
72 *
73 * This function packages the sync information into discrete updates
74 * and passes those off to another function, m_syncUpdateCallback.
75 * \sa m_syncUpdateCallback
76 *
77 * \param v A container with the new information sync has received
78 */
79 void
80 onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates);
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070081#endif
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050082
83 /*! \brief Hook function to call whenever PSync detects new data.
84 *
85 * This function packages the sync information into discrete updates
86 * and passes those off to another function, m_syncUpdateCallback.
87 * \sa m_syncUpdateCallback
88 *
89 * \param v A container with the new information sync has received
90 */
91 void
92 onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates);
93
94private:
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070095 SyncProtocol m_syncProtocol;
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050096 SyncUpdateCallback m_syncUpdateCallback;
Davide Pesavento1954a0c2022-09-30 15:56:04 -040097
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070098#ifdef HAVE_CHRONOSYNC
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050099 std::shared_ptr<chronosync::Logic> m_chronoSyncLogic;
Ashlesh Gawande30d96e42021-03-21 19:15:33 -0700100#endif
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500101 std::shared_ptr<psync::FullProducer> m_psyncLogic;
102};
103
104} // namespace nlsr
105
106#endif // NLSR_SYNC_PROTOCOL_ADAPTER_HPP