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-2020, 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 
32 const ndn::time::milliseconds SYNC_INTEREST_LIFTIME = 1_s;
33 
43 class FullProducer : public ProducerBase
44 {
45 public:
61  FullProducer(size_t expectedNumEntries,
62  ndn::Face& face,
63  const ndn::Name& syncPrefix,
64  const ndn::Name& userPrefix,
65  const UpdateCallback& onUpdateCallBack,
66  ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFTIME,
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, ndn::optional<uint64_t> seq = ndn::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 private:
173  struct PendingEntryInfo
174  {
175  detail::IBLT iblt;
176  ndn::scheduler::ScopedEventId expirationEvent;
177  };
178 
179  std::map<ndn::Name, PendingEntryInfo> m_pendingEntries;
180  ndn::time::milliseconds m_syncInterestLifetime;
181  UpdateCallback m_onUpdate;
182  ndn::scheduler::ScopedEventId m_scheduledSyncInterestId;
183  std::uniform_int_distribution<> m_jitter;
184  ndn::Name m_outstandingInterestName;
185  ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
186  std::shared_ptr<ndn::util::SegmentFetcher> m_fetcher;
187 };
188 
189 } // namespace psync
190 
191 #endif // PSYNC_FULL_PRODUCER_HPP
FullProducer(size_t expectedNumEntries, ndn::Face &face, const ndn::Name &syncPrefix, const ndn::Name &userPrefix, const UpdateCallback &onUpdateCallBack, ndn::time::milliseconds syncInterestLifetime=SYNC_INTEREST_LIFTIME, ndn::time::milliseconds syncReplyFreshness=SYNC_REPLY_FRESHNESS, CompressionScheme ibltCompression=CompressionScheme::DEFAULT, CompressionScheme contentCompression=CompressionScheme::DEFAULT)
constructor
Invertible Bloom Lookup Table (Invertible Bloom Filter)
Definition: iblt.hpp:81
Definition: common.hpp:33
const ndn::time::milliseconds SYNC_REPLY_FRESHNESS
Full sync logic to synchronize with other nodes where all nodes wants to get all names prefixes synce...
void publishName(const ndn::Name &prefix, ndn::optional< uint64_t > seq=ndn::nullopt)
Publish name to let others know.
const ndn::time::milliseconds SYNC_INTEREST_LIFTIME
std::function< void(const std::vector< MissingDataInfo > &)> UpdateCallback
Definition: common.hpp:62
CompressionScheme
Definition: common.hpp:35
#define PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE
Base class for PartialProducer and FullProducer.