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 #include "PSync/detail/state.hpp"
25 
26 #include <map>
27 #include <random>
28 #include <set>
29 
30 #include <ndn-cxx/face.hpp>
31 #include <ndn-cxx/security/key-chain.hpp>
32 #include <ndn-cxx/util/scheduler.hpp>
33 #include <ndn-cxx/util/segment-fetcher.hpp>
34 #include <ndn-cxx/util/time.hpp>
35 
36 namespace psync {
37 
38 // Name has to be different than PendingEntryInfo
39 // used in partial-producer otherwise get strange segmentation-faults
40 // when partial producer is destructed
42 {
44  ndn::scheduler::ScopedEventId expirationEvent;
45 };
46 
47 typedef std::function<void(const std::vector<MissingDataInfo>&)> UpdateCallback;
48 
49 const ndn::time::milliseconds SYNC_INTEREST_LIFTIME = 1_s;
50 
60 class FullProducer : public ProducerBase
61 {
62 public:
78  FullProducer(size_t expectedNumEntries,
79  ndn::Face& face,
80  const ndn::Name& syncPrefix,
81  const ndn::Name& userPrefix,
82  const UpdateCallback& onUpdateCallBack,
83  ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFTIME,
84  ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS,
86  CompressionScheme contentCompression = CompressionScheme::ZLIB);
87 
88  ~FullProducer();
89 
101  void
102  publishName(const ndn::Name& prefix, ndn::optional<uint64_t> seq = ndn::nullopt);
103 
112  void
113  sendSyncInterest();
114 
129  void
130  onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& interest);
131 
142  void
143  sendSyncData(const ndn::Name& name, const ndn::Block& block);
144 
160  void
161  onSyncData(const ndn::Interest& interest, const ndn::ConstBufferPtr& bufferPtr);
162 
163 private:
171  void
172  satisfyPendingInterests();
173 
177  void
178  deletePendingInterests(const ndn::Name& interestName);
179 
186  bool
187  isFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative);
188 
189 private:
190  std::map<ndn::Name, PendingEntryInfoFull> m_pendingEntries;
191  ndn::time::milliseconds m_syncInterestLifetime;
192  UpdateCallback m_onUpdate;
193  ndn::scheduler::ScopedEventId m_scheduledSyncInterestId;
194  std::uniform_int_distribution<> m_jitter;
195  ndn::Name m_outstandingInterestName;
196  ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
197  std::shared_ptr<ndn::util::SegmentFetcher> m_fetcher;
198 };
199 
200 } // namespace psync
201 
202 #endif // PSYNC_FULL_PRODUCER_HPP
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...
ndn::scheduler::ScopedEventId expirationEvent
Invertible Bloom Lookup Table (Invertible Bloom Filter)
Definition: iblt.hpp:82
const ndn::time::milliseconds SYNC_INTEREST_LIFTIME
CompressionScheme
Definition: util.hpp:51
#define PSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE
std::function< void(const std::vector< MissingDataInfo > &)> UpdateCallback
Definition: consumer.hpp:41
Base class for PartialProducer and FullProducer.