Loading...
Searching...
No Matches
producer-base.hpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2014-2024, The University of Memphis
4 *
5 * This file is part of PSync.
6 * See AUTHORS.md for complete list of PSync authors and contributors.
7 *
8 * PSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU Lesser General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License along with
17 * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef PSYNC_PRODUCER_BASE_HPP
21#define PSYNC_PRODUCER_BASE_HPP
22
23#include "PSync/common.hpp"
25#include "PSync/detail/iblt.hpp"
27
28#include <ndn-cxx/face.hpp>
29#include <ndn-cxx/security/key-chain.hpp>
30#include <ndn-cxx/util/random.hpp>
31#include <ndn-cxx/util/scheduler.hpp>
32
33#include <boost/bimap/bimap.hpp>
34#include <boost/bimap/unordered_set_of.hpp>
35
36#include <map>
37
38namespace psync {
39
40namespace bm = boost::bimaps;
41
48{
49public:
50 class Error : public std::runtime_error
51 {
52 public:
53 using std::runtime_error::runtime_error;
54 };
55
68 ProducerBase(ndn::Face& face,
69 ndn::KeyChain& keyChain,
70 size_t expectedNumEntries,
71 const ndn::Name& syncPrefix,
72 ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
74 CompressionScheme contentCompression = CompressionScheme::NONE);
75
76public:
82 std::optional<uint64_t>
83 getSeqNo(const ndn::Name& prefix) const
84 {
85 auto it = m_prefixes.find(prefix);
86 if (it == m_prefixes.end()) {
87 return std::nullopt;
88 }
89 return it->second;
90 }
91
103 bool
104 addUserNode(const ndn::Name& prefix);
105
113 void
114 removeUserNode(const ndn::Name& prefix);
115
128 void
129 updateSeqNo(const ndn::Name& prefix, uint64_t seq);
130
131 bool
132 isUserNode(const ndn::Name& prefix) const
133 {
134 return m_prefixes.find(prefix) != m_prefixes.end();
135 }
136
145 void
146 sendApplicationNack(const ndn::Name& name);
147
151 [[noreturn]] static void
152 onRegisterFailed(const ndn::Name& prefix, const std::string& msg);
153
155 ndn::Face& m_face;
156 ndn::KeyChain& m_keyChain;
157 ndn::Scheduler m_scheduler;
158 ndn::random::RandomNumberEngine& m_rng;
159
161
162 // prefix and sequence number
163 std::map<ndn::Name, uint64_t> m_prefixes;
164
165 using HashNameBiMap = bm::bimap<bm::unordered_set_of<uint32_t>,
166 bm::unordered_set_of<ndn::Name, std::hash<ndn::Name>>>;
168
170
172 // Threshold is used check if the differences are greater
173 // than it and whether we need to update the other side.
174 const size_t m_threshold;
175 const ndn::Name m_syncPrefix;
176 const ndn::time::milliseconds m_syncReplyFreshness;
179 uint64_t m_numOwnElements = 0;
180};
181
182} // namespace psync
183
184#endif // PSYNC_PRODUCER_BASE_HPP
#define PSYNC_PUBLIC_WITH_TESTS_ELSE_PROTECTED
Base class for PartialProducer and FullProducer.
const CompressionScheme m_contentCompression
void sendApplicationNack(const ndn::Name &name)
Sends a data packet with content type nack.
const ndn::Name m_syncPrefix
const ndn::time::milliseconds m_syncReplyFreshness
void removeUserNode(const ndn::Name &prefix)
Remove the user node from synchronization.
const size_t m_expectedNumEntries
bool addUserNode(const ndn::Name &prefix)
Adds a user node for synchronization.
std::map< ndn::Name, uint64_t > m_prefixes
ndn::Scheduler m_scheduler
static void onRegisterFailed(const ndn::Name &prefix, const std::string &msg)
Logs a message and throws if setting an interest filter fails.
bool isUserNode(const ndn::Name &prefix) const
const CompressionScheme m_ibltCompression
void updateSeqNo(const ndn::Name &prefix, uint64_t seq)
Update m_prefixes and IBF with the given prefix and seq.
bm::bimap< bm::unordered_set_of< uint32_t >, bm::unordered_set_of< ndn::Name, std::hash< ndn::Name > > > HashNameBiMap
SegmentPublisher m_segmentPublisher
ndn::KeyChain & m_keyChain
std::optional< uint64_t > getSeqNo(const ndn::Name &prefix) const
Returns the current sequence number of the given prefix.
ndn::random::RandomNumberEngine & m_rng
Helper class to publish segmented data.
Invertible Bloom Lookup Table (Invertible Bloom Filter)
Definition iblt.hpp:95
CompressionScheme
Definition common.hpp:43
constexpr ndn::time::milliseconds SYNC_REPLY_FRESHNESS
Definition common.hpp:41