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-2019, 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 <unordered_set>
28 #include <random>
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::util::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:
76  FullProducer(size_t expectedNumEntries,
77  ndn::Face& face,
78  const ndn::Name& syncPrefix,
79  const ndn::Name& userPrefix,
80  const UpdateCallback& onUpdateCallBack,
81  ndn::time::milliseconds syncInterestLifetime = SYNC_INTEREST_LIFTIME,
82  ndn::time::milliseconds syncReplyFreshness = SYNC_REPLY_FRESHNESS);
83 
84  ~FullProducer();
85 
97  void
98  publishName(const ndn::Name& prefix, ndn::optional<uint64_t> seq = ndn::nullopt);
99 
100 private:
108  void
109  sendSyncInterest();
110 
126  void
127  onSyncInterest(const ndn::Name& prefixName, const ndn::Interest& interest);
128 
129 private:
140  void
141  sendSyncData(const ndn::Name& name, const ndn::Block& block);
142 
158  void
159  onSyncData(const ndn::Interest& interest, const ndn::ConstBufferPtr& bufferPtr);
160 
168  void
169  satisfyPendingInterests();
170 
174  void
175  deletePendingInterests(const ndn::Name& interestName);
176 
183  bool
184  isFutureHash(const ndn::Name& prefix, const std::set<uint32_t>& negative);
185 
186 private:
187  std::map<ndn::Name, PendingEntryInfoFull> m_pendingEntries;
188  ndn::time::milliseconds m_syncInterestLifetime;
189  UpdateCallback m_onUpdate;
190  ndn::util::scheduler::ScopedEventId m_scheduledSyncInterestId;
191  std::uniform_int_distribution<> m_jitter;
192  ndn::Name m_outstandingInterestName;
193  ndn::ScopedRegisteredPrefixHandle m_registeredPrefix;
194  std::shared_ptr<ndn::util::SegmentFetcher> m_fetcher;
195 };
196 
197 } // namespace psync
198 
199 #endif // PSYNC_FULL_PRODUCER_HPP
#define PUBLIC_WITH_TESTS_ELSE_PRIVATE
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...
Invertible Bloom Lookup Table (Invertible Bloom Filter)
Definition: iblt.hpp:80
const ndn::time::milliseconds SYNC_INTEREST_LIFTIME
ndn::util::scheduler::ScopedEventId expirationEvent
std::function< void(const std::vector< MissingDataInfo > &)> UpdateCallback
Definition: consumer.hpp:41
Base class for PartialProducer and FullProducer.