blob: 363f02d136d76c01fe9492ec86e2132ec38f3196 [file] [log] [blame]
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2018, The University of Memphis,
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/>.
20 **/
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>
28#include <ChronoSync/logic.hpp>
29#include <PSync/full-producer.hpp>
30
31namespace nlsr {
32
33typedef std::function<void(const ndn::Name& updateName,
34 uint64_t seqNo)> SyncUpdateCallback;
35
36class SyncProtocolAdapter
37{
38public:
39 SyncProtocolAdapter(ndn::Face& facePtr,
40 int32_t syncProtocol,
41 const ndn::Name& syncPrefix,
42 const ndn::Name& userPrefix,
43 ndn::time::milliseconds syncInterestLifetime,
44 const SyncUpdateCallback& syncUpdateCallback);
45
46 /*! \brief Add user node to ChronoSync or PSync
47 *
48 * \param userPrefix the Name under which the application will publishData
49 */
50 void
51 addUserNode(const ndn::Name& userPrefix);
52
53 /*! \brief Publish update to ChronoSync or PSync
54 *
55 * NLSR forces sequences number on the sync protocol
56 * as it manages is its own sequence number by storing it in a file.
57 *
58 * \param userPrefix the Name to be updated
59 * \param seq the sequence of userPrefix
60 */
61 void
62 publishUpdate(const ndn::Name& userPrefix, uint64_t seq);
63
64PUBLIC_WITH_TESTS_ELSE_PRIVATE:
65 /*! \brief Hook function to call whenever ChronoSync detects new data.
66 *
67 * This function packages the sync information into discrete updates
68 * and passes those off to another function, m_syncUpdateCallback.
69 * \sa m_syncUpdateCallback
70 *
71 * \param v A container with the new information sync has received
72 */
73 void
74 onChronoSyncUpdate(const std::vector<chronosync::MissingDataInfo>& updates);
75
76 /*! \brief Hook function to call whenever PSync detects new data.
77 *
78 * This function packages the sync information into discrete updates
79 * and passes those off to another function, m_syncUpdateCallback.
80 * \sa m_syncUpdateCallback
81 *
82 * \param v A container with the new information sync has received
83 */
84 void
85 onPSyncUpdate(const std::vector<psync::MissingDataInfo>& updates);
86
87private:
88 int32_t m_syncProtocol;
89 SyncUpdateCallback m_syncUpdateCallback;
90 std::shared_ptr<chronosync::Logic> m_chronoSyncLogic;
91 std::shared_ptr<psync::FullProducer> m_psyncLogic;
92};
93
94} // namespace nlsr
95
96#endif // NLSR_SYNC_PROTOCOL_ADAPTER_HPP