full-producer.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2022, 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_FULL_PRODUCER_HPP
21 #define PSYNC_FULL_PRODUCER_HPP
22 
23 #include "PSync/producer-base.hpp"
24 
25 #include <random>
26 #include <set>
27 
28 #include <ndn-cxx/util/segment-fetcher.hpp>
29 
30 namespace psync {
31 
41 class FullProducer : public ProducerBase
42 {
43 public:
60  FullProducer(ndn::Face& face,
61  ndn::KeyChain& keyChain,
62  size_t expectedNumEntries,
63  const ndn::Name& syncPrefix,
64  const ndn::Name& userPrefix,
65  UpdateCallback onUpdateCallBack,
66  ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFETIME,
67  ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
69  CompressionScheme contentCompression = CompressionScheme::DEFAULT);
70 
71  ~FullProducer();
72 
84  void
85  publishName(const ndn::Name& prefix, std::optional<uint64_t> seq = std::nullopt);
86 
95  void
96  sendSyncInterest();
97 
112  void
113  onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& interest);
114 
125  void
126  sendSyncData(const ndn::Name& name, const ndn::Block& block);
127 
143  void
144  onSyncData(const ndn::Interest& interest, const ndn::ConstBufferPtr& bufferPtr);
145 
146 private:
154  void
155  satisfyPendingInterests();
156 
160  void
161  deletePendingInterests(const ndn::Name& interestName);
162 
169  bool
170  isFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative);
171 
172 #ifdef PSYNC_WITH_TESTS
173 public:
174  size_t nIbfDecodeFailuresAboveThreshold = 0;
175  size_t nIbfDecodeFailuresBelowThreshold = 0;
176 #endif // PSYNC_WITH_TESTS
177 
178 private:
179  struct PendingEntryInfo
180  {
181  detail::IBLT iblt;
182  ndn::scheduler::ScopedEventId expirationEvent;
183  };
184 
185  std::map<ndn::Name, PendingEntryInfo> m_pendingEntries;
186  ndn::time::milliseconds m_syncInterestLifetime;
187  UpdateCallback m_onUpdate;
188  ndn::scheduler::ScopedEventId m_scheduledSyncInterestId;
189  std::uniform_int_distribution<> m_jitter{100, 500};
190  ndn::Name m_outstandingInterestName;
191  ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
192  std::shared_ptr<ndn::util::SegmentFetcher> m_fetcher;
193  uint64_t m_incomingFace = 0;
194 };
195 
196 } // namespace psync
197 
198 #endif // PSYNC_FULL_PRODUCER_HPP
#define PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Full sync logic to synchronize with other nodes where all nodes wants to get all names prefixes synce...
FullProducer(ndn::Face &face, ndn::KeyChain &keyChain, size_t expectedNumEntries, const ndn::Name &syncPrefix, const ndn::Name &userPrefix, UpdateCallback onUpdateCallBack, ndn::time::milliseconds syncInterestLifetime=SYNC_INTEREST_LIFETIME, ndn::time::milliseconds syncReplyFreshness=SYNC_REPLY_FRESHNESS, CompressionScheme ibltCompression=CompressionScheme::DEFAULT, CompressionScheme contentCompression=CompressionScheme::DEFAULT)
Constructor.
void publishName(const ndn::Name &prefix, std::optional< uint64_t > seq=std::nullopt)
Publish name to let others know.
Base class for PartialProducer and FullProducer.
Invertible Bloom Lookup Table (Invertible Bloom Filter)
Definition: iblt.hpp:81
Definition: common.hpp:34
CompressionScheme
Definition: common.hpp:43
constexpr ndn::time::milliseconds SYNC_INTEREST_LIFETIME
Definition: common.hpp:40
constexpr ndn::time::milliseconds SYNC_REPLY_FRESHNESS
Definition: common.hpp:41
std::function< void(const std::vector< MissingDataInfo > &)> UpdateCallback
Definition: common.hpp:71