blob: 408e164de45e6fe914bc0b2798b17895e2bc268c [file] [log] [blame]
Yingdi Yuf7ede412014-08-30 20:37:52 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Ashlesh Gawande9a306fe2019-01-04 11:38:18 -06003 * Copyright (c) 2012-2019 University of California, Los Angeles
Yingdi Yuf7ede412014-08-30 20:37:52 -07004 *
5 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
7 *
8 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
11 *
12 * ChronoSync 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
20 * @author Chaoyi Bian <bcy@pku.edu.cn>
21 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
22 * @author Yingdi Yu <yingdi@cs.ucla.edu>
Sonu Mishra4d3a2e02017-01-18 20:27:51 -080023 * @author Sonu Mishra <https://www.linkedin.com/in/mishrasonu>
Yingdi Yuf7ede412014-08-30 20:37:52 -070024 */
25
26#ifndef CHRONOSYNC_LOGIC_HPP
27#define CHRONOSYNC_LOGIC_HPP
28
Ashlesh Gawande687cf922017-05-30 15:04:16 -050029#include "diff-state-container.hpp"
30#include "interest-table.hpp"
31
Ashlesh Gawande9a306fe2019-01-04 11:38:18 -060032#include <ndn-cxx/util/random.hpp>
33
Ashlesh Gawande08784d42017-09-06 23:40:21 -050034#include <boost/archive/iterators/dataflow_exception.hpp>
35#include <boost/archive/iterators/transform_width.hpp>
36#include <boost/assert.hpp>
37#include <boost/iterator/transform_iterator.hpp>
Ashlesh Gawande08784d42017-09-06 23:40:21 -050038#include <boost/throw_exception.hpp>
39
Yingdi Yuf7ede412014-08-30 20:37:52 -070040#include <memory>
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080041#include <unordered_map>
Yingdi Yuf7ede412014-08-30 20:37:52 -070042
Yingdi Yuf7ede412014-08-30 20:37:52 -070043namespace chronosync {
44
45/**
46 * @brief The missing sequence numbers for a session
47 *
48 * This class is used to notify the clients of Logic
49 * the details of state changes.
50 *
51 * Instances of this class is usually used as elements of some containers
52 * such as std::vector, thus it is copyable.
53 */
Sonu Mishra4d3a2e02017-01-18 20:27:51 -080054class NodeInfo
55{
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080056public:
57 Name userPrefix;
58 Name signingId;
59 Name sessionName;
60 SeqNo seqNo;
61};
62
Yingdi Yuf7ede412014-08-30 20:37:52 -070063class MissingDataInfo
64{
65public:
66 /// @brief session name
67 Name session;
68 /// @brief the lowest one of missing sequence numbers
69 SeqNo low;
70 /// @brief the highest one of missing sequence numbers
71 SeqNo high;
72};
73
74/**
75 * @brief The callback function to handle state updates
76 *
77 * The parameter is a set of MissingDataInfo, of which each corresponds to
78 * a session that has changed its state.
79 */
Ashlesh Gawande08784d42017-09-06 23:40:21 -050080using UpdateCallback = function<void(const std::vector<MissingDataInfo>&)>;
Yingdi Yuf7ede412014-08-30 20:37:52 -070081
82/**
83 * @brief Logic of ChronoSync
84 */
85class Logic : noncopyable
86{
87public:
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080088 class Error : public std::runtime_error
89 {
90 public:
91 explicit
92 Error(const std::string& what)
93 : std::runtime_error(what)
94 {
95 }
96 };
97
98public:
Yingdi Yuf7ede412014-08-30 20:37:52 -070099 static const time::steady_clock::Duration DEFAULT_RESET_TIMER;
100 static const time::steady_clock::Duration DEFAULT_CANCEL_RESET_TIMER;
101 static const time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME;
102 static const time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME;
103 static const time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800104 static const time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700105
106 /**
107 * @brief Constructor
108 *
Yingdi Yu9d5679a2015-02-01 00:17:58 -0800109 * @param face The face used to communication, will be shutdown in destructor
Yingdi Yuf7ede412014-08-30 20:37:52 -0700110 * @param syncPrefix The prefix of the sync group
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800111 * @param defaultUserPrefix The prefix of the first user added to this session
Yingdi Yuf7ede412014-08-30 20:37:52 -0700112 * @param onUpdate The callback function to handle state updates
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800113 * @param defaultSigningId The signing Id of the default user
Yingdi Yucd339022014-11-05 17:51:19 -0800114 * @param validator The validator for packet validation
Yingdi Yuf7ede412014-08-30 20:37:52 -0700115 * @param resetTimer The timer to periodically send Reset Interest
Yingdi Yuf7ede412014-08-30 20:37:52 -0700116 * @param cancelResetTimer The timer to exit from Reset state
Ashlesh Gawande097bb442017-05-31 13:38:00 -0500117 * @param resetInterestLifetime The lifetime of Reset Interest
118 * @param syncInterestLifetime The lifetime of sync interest
119 * @param syncReplyFreshness The FreshnessPeriod of sync reply
120 * @param recoveryInterestLifetime The lifetime of recovery interest
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500121 * @param session Manually defined session ID
Yingdi Yuf7ede412014-08-30 20:37:52 -0700122 */
123 Logic(ndn::Face& face,
124 const Name& syncPrefix,
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800125 const Name& defaultUserPrefix,
Yingdi Yuf7ede412014-08-30 20:37:52 -0700126 const UpdateCallback& onUpdate,
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800127 const Name& defaultSigningId = DEFAULT_NAME,
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500128 std::shared_ptr<Validator> validator = DEFAULT_VALIDATOR,
Yingdi Yuf7ede412014-08-30 20:37:52 -0700129 const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER,
130 const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER,
131 const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME,
132 const time::milliseconds& syncInterestLifetime = DEFAULT_SYNC_INTEREST_LIFETIME,
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800133 const time::milliseconds& syncReplyFreshness = DEFAULT_SYNC_REPLY_FRESHNESS,
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500134 const time::milliseconds& recoveryInterestLifetime = DEFAULT_RECOVERY_INTEREST_LIFETIME,
Ashlesh Gawandedb862e02018-03-30 17:15:08 -0500135 const name::Component& session = name::Component());
Yingdi Yuf7ede412014-08-30 20:37:52 -0700136
137 ~Logic();
138
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -0800139 /**
140 * @brief Reset the sync tree (and restart synchronization again)
141 *
142 * @param isOnInterest a flag that tells whether the reset is called by reset interest.
143 */
Yingdi Yuf7ede412014-08-30 20:37:52 -0700144 void
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -0800145 reset(bool isOnInterest = false);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700146
147 /**
148 * @brief Set user prefix
149 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800150 * This method will also change the default user and signing Id of that user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700151 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800152 * @param defaultUserPrefix The prefix of user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700153 */
154 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800155 setDefaultUserPrefix(const Name& defaultUserPrefix);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700156
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800157 /// @brief Get the name of default user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700158 const Name&
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800159 getDefaultUserPrefix() const
Yingdi Yuf7ede412014-08-30 20:37:52 -0700160 {
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800161 return m_defaultUserPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700162 }
163
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800164 /**
165 * @brief Add user node into the local session.
166 *
167 * This method also reset after adding
168 *
169 * @param userPrefix prefix of the added node
170 * @param signingId signing Id of the added node
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500171 * @param session manually defined session ID
Davide Pesaventod7de2d42019-08-01 20:55:50 -0400172 * @param shouldSendReset enable/disable sending the reset interest
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800173 */
174 void
Ashlesh Gawandedb862e02018-03-30 17:15:08 -0500175 addUserNode(const Name& userPrefix, const Name& signingId = DEFAULT_NAME,
Davide Pesaventod7de2d42019-08-01 20:55:50 -0400176 const name::Component& session = name::Component(), bool shouldSendReset = true);
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800177
178 /// @brief remove the node from the local session
179 void
180 removeUserNode(const Name& userPrefix);
181
182 /**
183 * @brief Get the name of the local session.
184 *
185 * This method gets the session name according to prefix, if prefix is not specified,
186 * it returns the session name of default user.
187 *
188 * @param prefix prefix of the node
189 */
190 const Name&
191 getSessionName(Name prefix = EMPTY_NAME);
192
193 /**
194 * @brief Get current seqNo of the local session.
195 *
196 * This method gets the seqNo according to prefix, if prefix is not specified,
197 * it returns the seqNo of default user.
198 *
199 * @param prefix prefix of the node
200 */
Yingdi Yuf7ede412014-08-30 20:37:52 -0700201 const SeqNo&
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800202 getSeqNo(Name prefix = EMPTY_NAME);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700203
204 /**
205 * @brief Update the seqNo of the local session
206 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800207 * The method updates the existing seqNo with the supplied seqNo and prefix.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700208 *
209 * @param seq The new seqNo.
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800210 * @param updatePrefix The prefix of node to update.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700211 */
212 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800213 updateSeqNo(const SeqNo& seq, const Name& updatePrefix = EMPTY_NAME);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700214
215 /// @brief Get root digest of current sync tree
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500216 ConstBufferPtr
Yingdi Yuf7ede412014-08-30 20:37:52 -0700217 getRootDigest() const;
218
219 /// @brief Get the name of all sessions
220 std::set<Name>
221 getSessionNames() const;
222
Yingdi Yu906c2ea2014-10-31 11:24:50 -0700223CHRONOSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yuf7ede412014-08-30 20:37:52 -0700224 void
225 printState(std::ostream& os) const;
226
227 ndn::Scheduler&
228 getScheduler()
229 {
230 return m_scheduler;
231 }
232
233 State&
234 getState()
235 {
236 return m_state;
237 }
238
Alexander Afanasyev6ee98ff2018-02-13 19:12:28 -0500239 /// Create a subset @p partialState excluding @p nExcludedStates from @p state
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -0600240 void
Alexander Afanasyev6ee98ff2018-02-13 19:12:28 -0500241 trimState(State& partialState, const State& state, size_t excludedStates);
242
243 Data
244 encodeSyncReply(const Name& nodePrefix, const Name& name, const State& state);
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800245
Yingdi Yuf7ede412014-08-30 20:37:52 -0700246private:
247 /**
248 * @brief Callback to handle Sync Interest
249 *
250 * This method checks whether an incoming interest is a normal one or a reset
251 * and dispatches the incoming interest to corresponding processing methods.
252 *
253 * @param prefix The prefix of the sync group.
254 * @param interest The incoming sync interest.
255 */
256 void
257 onSyncInterest(const Name& prefix, const Interest& interest);
258
259 /**
260 * @brief Callback to handle Sync prefix registration failure
261 *
262 * This method does nothing for now.
263 *
264 * @param prefix The prefix of the sync group.
265 * @param msg The error message.
266 */
267 void
268 onSyncRegisterFailed(const Name& prefix, const std::string& msg);
269
270 /**
271 * @brief Callback to handle Sync Reply
272 *
273 * This method calls validator to validate Sync Reply.
274 * For now, validation is disabled, Logic::onSyncDataValidated is called
275 * directly.
276 *
277 * @param interest The Sync Interest
278 * @param data The reply to the Sync Interest
279 */
280 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800281 onSyncData(const Interest& interest, const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700282
283 /**
284 * @brief Callback to handle reply to Reset Interest.
285 *
286 * This method does nothing, since reply to Reset Interest is not useful for now.
287 *
288 * @param interest The Reset Interest
289 * @param data The reply to the Reset Interest
290 */
291 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800292 onResetData(const Interest& interest, const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700293
294 /**
295 * @brief Callback to handle Sync Interest timeout.
296 *
297 * This method does nothing, since Logic per se handles timeout explicitly.
298 *
299 * @param interest The Sync Interest
300 */
301 void
302 onSyncTimeout(const Interest& interest);
303
304 /**
305 * @brief Callback to invalid Sync Reply.
306 *
307 * This method does nothing but drops the invalid reply.
308 *
309 * @param data The invalid Sync Reply
310 */
311 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500312 onSyncDataValidationFailed(const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700313
314 /**
315 * @brief Callback to valid Sync Reply.
316 *
317 * This method simply passes the valid reply to processSyncData.
318 *
319 * @param data The valid Sync Reply.
320 */
321 void
Ashlesh Gawande1d1092d2018-08-03 14:36:49 -0500322 onSyncDataValidated(const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700323
324 /**
325 * @brief Process normal Sync Interest
326 *
327 * This method extracts the digest from the incoming Sync Interest,
328 * compares it against current local digest, and process the Sync
329 * Interest according to the comparison result. See docs/design.rst
330 * for more details.
331 *
332 * @param interest The incoming interest
333 * @param isTimedProcessing True if the interest needs an immediate reply,
334 * otherwise hold the interest for a while before
335 * making a reply (to avoid unnecessary recovery)
336 */
337 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500338 processSyncInterest(const Interest& interest, bool isTimedProcessing = false);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700339
340 /**
341 * @brief Process reset Sync Interest
342 *
343 * This method simply call Logic::reset()
344 *
345 * @param interest The incoming interest.
346 */
347 void
348 processResetInterest(const Interest& interest);
349
350 /**
351 * @brief Process Sync Reply.
352 *
353 * This method extracts state update information from Sync Reply and applies
354 * it to the Sync Tree and re-express Sync Interest.
355 *
356 * @param name The data name of the Sync Reply.
357 * @param digest The digest in the data name.
358 * @param syncReplyBlock The content of the Sync Reply.
359 */
360 void
361 processSyncData(const Name& name,
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500362 ConstBufferPtr digest,
Ashlesh Gawande1d1092d2018-08-03 14:36:49 -0500363 const Block& syncReplyBlock);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700364
365 /**
366 * @brief Insert state diff into log
367 *
368 * @param diff The diff .
369 * @param previousRoot The root digest before state changes.
370 */
371 void
372 insertToDiffLog(DiffStatePtr diff,
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500373 ConstBufferPtr previousRoot);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700374
375 /**
376 * @brief Reply to all pending Sync Interests with a particular commit (or diff)
377 *
378 * @param commit The diff.
379 */
380 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800381 satisfyPendingSyncInterests(const Name& updatedPrefix, ConstDiffStatePtr commit);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700382
383 /// @brief Helper method to send normal Sync Interest
384 void
385 sendSyncInterest();
386
387 /// @brief Helper method to send reset Sync Interest
388 void
389 sendResetInterest();
390
391 /// @brief Helper method to send Sync Reply
392 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800393 sendSyncData(const Name& nodePrefix, const Name& name, const State& state);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700394
395 /**
396 * @brief Unset reset status
397 *
398 * By invoking this method, one can add its own state into the Sync Tree, thus
399 * jumping out of the reset status
400 */
401 void
402 cancelReset();
403
404 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500405 printDigest(ConstBufferPtr digest);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700406
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800407 /**
408 * @brief Helper method to send Recovery Interest
409 *
410 * @param digest The digest to be included in the recovery interest
411 */
412 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500413 sendRecoveryInterest(ConstBufferPtr digest);
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800414
415 /**
416 * @brief Process Recovery Interest
417 *
418 * This method extracts the digest from the incoming Recovery Interest.
419 * If it recognizes this incoming digest, then it sends its full state
420 * as reply.
421 *
422 * @param interest The incoming interest
423 */
424 void
425 processRecoveryInterest(const Interest& interest);
426
427 /**
428 * @brief Callback to handle Recovery Reply
429 *
430 * This method calls Logic::onSyncDataValidated directly.
431 *
432 * @param interest The Recovery Interest
433 * @param data The reply to the Recovery Interest
434 */
435 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800436 onRecoveryData(const Interest& interest, const Data& data);
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800437
438 /**
439 * @brief Callback to handle Recovery Interest timeout.
440 *
441 * This method does nothing.
442 *
443 * @param interest The Recovery Interest
444 */
445 void
446 onRecoveryTimeout(const Interest& interest);
447
Alexander Afanasyevfcbf81d2018-02-19 10:25:46 -0500448 // /**
449 // * @brief Helper method to send Exclude Interest
450 // *
451 // * @param interest The interest whose exclude filter will be augmented
452 // * @param data The data whose implicit digest will be inserted into exclude filter
453 // */
454 // void
455 // sendExcludeInterest(const Interest& interest, const Data& data);
Sonu Mishraf42aa2c2017-01-22 18:47:33 -0800456
Alexander Afanasyevfcbf81d2018-02-19 10:25:46 -0500457 // /**
458 // * @brief Helper method to form the exclude Interest and calls sendExcludeInterest
459 // *
460 // * @param interest The interest whose exclude filter will be augmented
461 // * @param nodePrefix The prefix of the sender node
462 // * @param commit The commit whose contents will be used to obtain the implicit
463 // digest to be excluded
464 // * @param previousRoot The digest to be included in the interest
465 // */
466 // void
467 // formAndSendExcludeInterest(const Name& nodePrefix,
468 // const State& commit,
469 // ConstBufferPtr previousRoot);
Sonu Mishraf42aa2c2017-01-22 18:47:33 -0800470
Nick Gordon0b3beab2018-03-02 13:03:28 -0600471 void
472 cleanupPendingInterest(const ndn::PendingInterestId* pendingInterestId);
473
Yingdi Yucd339022014-11-05 17:51:19 -0800474public:
475 static const ndn::Name DEFAULT_NAME;
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800476 static const ndn::Name EMPTY_NAME;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500477 static const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
Yingdi Yucd339022014-11-05 17:51:19 -0800478
Yingdi Yuf7ede412014-08-30 20:37:52 -0700479private:
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500480 using NodeList = std::unordered_map<ndn::Name, NodeInfo>;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700481
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500482 static const ConstBufferPtr EMPTY_DIGEST;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700483 static const ndn::name::Component RESET_COMPONENT;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800484 static const ndn::name::Component RECOVERY_COMPONENT;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700485
486 // Communication
487 ndn::Face& m_face;
488 Name m_syncPrefix;
Junxiao Shi8e4e76d2019-02-08 15:25:08 -0700489 ndn::ScopedRegisteredPrefixHandle m_syncRegisteredPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700490 Name m_syncReset;
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800491 Name m_defaultUserPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700492
493 // State
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800494 NodeList m_nodeList;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700495 State m_state;
496 DiffStateContainer m_log;
497 InterestTable m_interestTable;
Junxiao Shi8e4e76d2019-02-08 15:25:08 -0700498 Name m_pendingSyncInterestName;
499 ndn::ScopedPendingInterestHandle m_pendingSyncInterest;
500 ndn::ScopedPendingInterestHandle m_pendingResetInterest;
501 std::map<std::string, ndn::ScopedPendingInterestHandle> m_pendingRecoveryInterests;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700502 bool m_isInReset;
503 bool m_needPeriodReset;
504
505 // Callback
506 UpdateCallback m_onUpdate;
507
508 // Event
Davide Pesavento0d837e32019-03-16 22:31:14 -0400509 ndn::Scheduler m_scheduler;
510 ndn::scheduler::ScopedEventId m_delayedInterestProcessingId;
511 ndn::scheduler::ScopedEventId m_reexpressingInterestId;
512 ndn::scheduler::ScopedEventId m_resetInterestId;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700513
514 // Timer
Ashlesh Gawande9a306fe2019-01-04 11:38:18 -0600515 ndn::random::RandomNumberEngine& m_rng;
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -0600516 std::uniform_int_distribution<> m_rangeUniformRandom;
517 std::uniform_int_distribution<> m_reexpressionJitter;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700518 /// @brief Timer to send next reset 0 for no reset
519 time::steady_clock::Duration m_resetTimer;
520 /// @brief Timer to cancel reset state
521 time::steady_clock::Duration m_cancelResetTimer;
522 /// @brief Lifetime of reset interest
523 time::milliseconds m_resetInterestLifetime;
524 /// @brief Lifetime of sync interest
525 time::milliseconds m_syncInterestLifetime;
526 /// @brief FreshnessPeriod of SyncReply
527 time::milliseconds m_syncReplyFreshness;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800528 /// @brief Lifetime of recovery interest
529 time::milliseconds m_recoveryInterestLifetime;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700530
Yingdi Yucd339022014-11-05 17:51:19 -0800531 // Security
Yingdi Yuf7ede412014-08-30 20:37:52 -0700532 ndn::KeyChain m_keyChain;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500533 std::shared_ptr<Validator> m_validator;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700534
Yingdi Yuf7ede412014-08-30 20:37:52 -0700535 int m_instanceId;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500536 static int s_instanceCounter;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700537};
538
Alexander Afanasyev89036292018-02-13 17:19:50 -0500539#ifdef CHRONOSYNC_HAVE_TESTS
540size_t
541getMaxPacketLimit();
542#endif // CHRONOSYNC_HAVE_TESTS
Yingdi Yuf7ede412014-08-30 20:37:52 -0700543
544} // namespace chronosync
545
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800546#endif // CHRONOSYNC_LOGIC_HPP