blob: 3e887949ba5a08610ae008ee1bdb7b38f42bf033 [file] [log] [blame]
Yingdi Yuf7ede412014-08-30 20:37:52 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -06003 * Copyright (c) 2012-2018 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 Gawande08784d42017-09-06 23:40:21 -050032#include <boost/archive/iterators/dataflow_exception.hpp>
33#include <boost/archive/iterators/transform_width.hpp>
34#include <boost/assert.hpp>
35#include <boost/iterator/transform_iterator.hpp>
Ashlesh Gawande08784d42017-09-06 23:40:21 -050036#include <boost/throw_exception.hpp>
37
Yingdi Yuf7ede412014-08-30 20:37:52 -070038#include <memory>
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -060039#include <random>
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080040#include <unordered_map>
Yingdi Yuf7ede412014-08-30 20:37:52 -070041
Yingdi Yuf7ede412014-08-30 20:37:52 -070042namespace chronosync {
43
44/**
45 * @brief The missing sequence numbers for a session
46 *
47 * This class is used to notify the clients of Logic
48 * the details of state changes.
49 *
50 * Instances of this class is usually used as elements of some containers
51 * such as std::vector, thus it is copyable.
52 */
Sonu Mishra4d3a2e02017-01-18 20:27:51 -080053class NodeInfo
54{
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080055public:
56 Name userPrefix;
57 Name signingId;
58 Name sessionName;
59 SeqNo seqNo;
60};
61
Yingdi Yuf7ede412014-08-30 20:37:52 -070062class MissingDataInfo
63{
64public:
65 /// @brief session name
66 Name session;
67 /// @brief the lowest one of missing sequence numbers
68 SeqNo low;
69 /// @brief the highest one of missing sequence numbers
70 SeqNo high;
71};
72
73/**
74 * @brief The callback function to handle state updates
75 *
76 * The parameter is a set of MissingDataInfo, of which each corresponds to
77 * a session that has changed its state.
78 */
Ashlesh Gawande08784d42017-09-06 23:40:21 -050079using UpdateCallback = function<void(const std::vector<MissingDataInfo>&)>;
Yingdi Yuf7ede412014-08-30 20:37:52 -070080
81/**
82 * @brief Logic of ChronoSync
83 */
84class Logic : noncopyable
85{
86public:
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080087 class Error : public std::runtime_error
88 {
89 public:
90 explicit
91 Error(const std::string& what)
92 : std::runtime_error(what)
93 {
94 }
95 };
96
97public:
Yingdi Yuf7ede412014-08-30 20:37:52 -070098 static const time::steady_clock::Duration DEFAULT_RESET_TIMER;
99 static const time::steady_clock::Duration DEFAULT_CANCEL_RESET_TIMER;
100 static const time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME;
101 static const time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME;
102 static const time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800103 static const time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700104
105 /**
106 * @brief Constructor
107 *
Yingdi Yu9d5679a2015-02-01 00:17:58 -0800108 * @param face The face used to communication, will be shutdown in destructor
Yingdi Yuf7ede412014-08-30 20:37:52 -0700109 * @param syncPrefix The prefix of the sync group
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800110 * @param defaultUserPrefix The prefix of the first user added to this session
Yingdi Yuf7ede412014-08-30 20:37:52 -0700111 * @param onUpdate The callback function to handle state updates
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800112 * @param defaultSigningId The signing Id of the default user
Yingdi Yucd339022014-11-05 17:51:19 -0800113 * @param validator The validator for packet validation
Yingdi Yuf7ede412014-08-30 20:37:52 -0700114 * @param resetTimer The timer to periodically send Reset Interest
Yingdi Yuf7ede412014-08-30 20:37:52 -0700115 * @param cancelResetTimer The timer to exit from Reset state
Ashlesh Gawande097bb442017-05-31 13:38:00 -0500116 * @param resetInterestLifetime The lifetime of Reset Interest
117 * @param syncInterestLifetime The lifetime of sync interest
118 * @param syncReplyFreshness The FreshnessPeriod of sync reply
119 * @param recoveryInterestLifetime The lifetime of recovery interest
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500120 * @param session Manually defined session ID
Yingdi Yuf7ede412014-08-30 20:37:52 -0700121 */
122 Logic(ndn::Face& face,
123 const Name& syncPrefix,
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800124 const Name& defaultUserPrefix,
Yingdi Yuf7ede412014-08-30 20:37:52 -0700125 const UpdateCallback& onUpdate,
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800126 const Name& defaultSigningId = DEFAULT_NAME,
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500127 std::shared_ptr<Validator> validator = DEFAULT_VALIDATOR,
Yingdi Yuf7ede412014-08-30 20:37:52 -0700128 const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER,
129 const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER,
130 const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME,
131 const time::milliseconds& syncInterestLifetime = DEFAULT_SYNC_INTEREST_LIFETIME,
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800132 const time::milliseconds& syncReplyFreshness = DEFAULT_SYNC_REPLY_FRESHNESS,
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500133 const time::milliseconds& recoveryInterestLifetime = DEFAULT_RECOVERY_INTEREST_LIFETIME,
134 const name::Component& session = {});
Yingdi Yuf7ede412014-08-30 20:37:52 -0700135
136 ~Logic();
137
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -0800138 /**
139 * @brief Reset the sync tree (and restart synchronization again)
140 *
141 * @param isOnInterest a flag that tells whether the reset is called by reset interest.
142 */
Yingdi Yuf7ede412014-08-30 20:37:52 -0700143 void
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -0800144 reset(bool isOnInterest = false);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700145
146 /**
147 * @brief Set user prefix
148 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800149 * This method will also change the default user and signing Id of that user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700150 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800151 * @param defaultUserPrefix The prefix of user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700152 */
153 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800154 setDefaultUserPrefix(const Name& defaultUserPrefix);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700155
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800156 /// @brief Get the name of default user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700157 const Name&
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800158 getDefaultUserPrefix() const
Yingdi Yuf7ede412014-08-30 20:37:52 -0700159 {
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800160 return m_defaultUserPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700161 }
162
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800163 /**
164 * @brief Add user node into the local session.
165 *
166 * This method also reset after adding
167 *
168 * @param userPrefix prefix of the added node
169 * @param signingId signing Id of the added node
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500170 * @param session manually defined session ID
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800171 */
172 void
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500173 addUserNode(const Name& userPrefix, const Name& signingId = DEFAULT_NAME, const name::Component& session = {});
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800174
175 /// @brief remove the node from the local session
176 void
177 removeUserNode(const Name& userPrefix);
178
179 /**
180 * @brief Get the name of the local session.
181 *
182 * This method gets the session name according to prefix, if prefix is not specified,
183 * it returns the session name of default user.
184 *
185 * @param prefix prefix of the node
186 */
187 const Name&
188 getSessionName(Name prefix = EMPTY_NAME);
189
190 /**
191 * @brief Get current seqNo of the local session.
192 *
193 * This method gets the seqNo according to prefix, if prefix is not specified,
194 * it returns the seqNo of default user.
195 *
196 * @param prefix prefix of the node
197 */
Yingdi Yuf7ede412014-08-30 20:37:52 -0700198 const SeqNo&
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800199 getSeqNo(Name prefix = EMPTY_NAME);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700200
201 /**
202 * @brief Update the seqNo of the local session
203 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800204 * The method updates the existing seqNo with the supplied seqNo and prefix.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700205 *
206 * @param seq The new seqNo.
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800207 * @param updatePrefix The prefix of node to update.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700208 */
209 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800210 updateSeqNo(const SeqNo& seq, const Name& updatePrefix = EMPTY_NAME);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700211
212 /// @brief Get root digest of current sync tree
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500213 ConstBufferPtr
Yingdi Yuf7ede412014-08-30 20:37:52 -0700214 getRootDigest() const;
215
216 /// @brief Get the name of all sessions
217 std::set<Name>
218 getSessionNames() const;
219
Yingdi Yu906c2ea2014-10-31 11:24:50 -0700220CHRONOSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yuf7ede412014-08-30 20:37:52 -0700221 void
222 printState(std::ostream& os) const;
223
224 ndn::Scheduler&
225 getScheduler()
226 {
227 return m_scheduler;
228 }
229
230 State&
231 getState()
232 {
233 return m_state;
234 }
235
Alexander Afanasyev6ee98ff2018-02-13 19:12:28 -0500236 /// Create a subset @p partialState excluding @p nExcludedStates from @p state
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -0600237 void
Alexander Afanasyev6ee98ff2018-02-13 19:12:28 -0500238 trimState(State& partialState, const State& state, size_t excludedStates);
239
240 Data
241 encodeSyncReply(const Name& nodePrefix, const Name& name, const State& state);
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800242
Yingdi Yuf7ede412014-08-30 20:37:52 -0700243private:
244 /**
245 * @brief Callback to handle Sync Interest
246 *
247 * This method checks whether an incoming interest is a normal one or a reset
248 * and dispatches the incoming interest to corresponding processing methods.
249 *
250 * @param prefix The prefix of the sync group.
251 * @param interest The incoming sync interest.
252 */
253 void
254 onSyncInterest(const Name& prefix, const Interest& interest);
255
256 /**
257 * @brief Callback to handle Sync prefix registration failure
258 *
259 * This method does nothing for now.
260 *
261 * @param prefix The prefix of the sync group.
262 * @param msg The error message.
263 */
264 void
265 onSyncRegisterFailed(const Name& prefix, const std::string& msg);
266
267 /**
268 * @brief Callback to handle Sync Reply
269 *
270 * This method calls validator to validate Sync Reply.
271 * For now, validation is disabled, Logic::onSyncDataValidated is called
272 * directly.
273 *
274 * @param interest The Sync Interest
275 * @param data The reply to the Sync Interest
276 */
277 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800278 onSyncData(const Interest& interest, const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700279
280 /**
281 * @brief Callback to handle reply to Reset Interest.
282 *
283 * This method does nothing, since reply to Reset Interest is not useful for now.
284 *
285 * @param interest The Reset Interest
286 * @param data The reply to the Reset Interest
287 */
288 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800289 onResetData(const Interest& interest, const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700290
291 /**
292 * @brief Callback to handle Sync Interest timeout.
293 *
294 * This method does nothing, since Logic per se handles timeout explicitly.
295 *
296 * @param interest The Sync Interest
297 */
298 void
299 onSyncTimeout(const Interest& interest);
300
301 /**
302 * @brief Callback to invalid Sync Reply.
303 *
304 * This method does nothing but drops the invalid reply.
305 *
306 * @param data The invalid Sync Reply
307 */
308 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500309 onSyncDataValidationFailed(const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700310
311 /**
312 * @brief Callback to valid Sync Reply.
313 *
314 * This method simply passes the valid reply to processSyncData.
315 *
316 * @param data The valid Sync Reply.
Sonu Mishraf42aa2c2017-01-22 18:47:33 -0800317 * @param firstData Whether the data is new or that obtained using exclude filter
Yingdi Yuf7ede412014-08-30 20:37:52 -0700318 */
319 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500320 onSyncDataValidated(const Data& data, bool firstData = true);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700321
322 /**
323 * @brief Process normal Sync Interest
324 *
325 * This method extracts the digest from the incoming Sync Interest,
326 * compares it against current local digest, and process the Sync
327 * Interest according to the comparison result. See docs/design.rst
328 * for more details.
329 *
330 * @param interest The incoming interest
331 * @param isTimedProcessing True if the interest needs an immediate reply,
332 * otherwise hold the interest for a while before
333 * making a reply (to avoid unnecessary recovery)
334 */
335 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500336 processSyncInterest(const Interest& interest, bool isTimedProcessing = false);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700337
338 /**
339 * @brief Process reset Sync Interest
340 *
341 * This method simply call Logic::reset()
342 *
343 * @param interest The incoming interest.
344 */
345 void
346 processResetInterest(const Interest& interest);
347
348 /**
349 * @brief Process Sync Reply.
350 *
351 * This method extracts state update information from Sync Reply and applies
352 * it to the Sync Tree and re-express Sync Interest.
353 *
354 * @param name The data name of the Sync Reply.
355 * @param digest The digest in the data name.
356 * @param syncReplyBlock The content of the Sync Reply.
Sonu Mishraf42aa2c2017-01-22 18:47:33 -0800357 * @param firstData Whether the data is new or obtained using exclude filter
Yingdi Yuf7ede412014-08-30 20:37:52 -0700358 */
359 void
360 processSyncData(const Name& name,
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500361 ConstBufferPtr digest,
Sonu Mishraf42aa2c2017-01-22 18:47:33 -0800362 const Block& syncReplyBlock,
363 bool firstData);
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;
489 const ndn::RegisteredPrefixId* m_syncRegisteredPrefixId;
490 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;
498 Name m_outstandingInterestName;
499 const ndn::PendingInterestId* m_outstandingInterestId;
Nick Gordon0b3beab2018-03-02 13:03:28 -0600500 std::vector<const ndn::PendingInterestId*> m_pendingInterests;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700501 bool m_isInReset;
502 bool m_needPeriodReset;
503
504 // Callback
505 UpdateCallback m_onUpdate;
506
507 // Event
508 ndn::Scheduler m_scheduler;
509 ndn::EventId m_delayedInterestProcessingId;
510 ndn::EventId m_reexpressingInterestId;
511 ndn::EventId m_resetInterestId;
512
513 // Timer
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -0600514 std::mt19937 m_rng;
515 std::uniform_int_distribution<> m_rangeUniformRandom;
516 std::uniform_int_distribution<> m_reexpressionJitter;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700517 /// @brief Timer to send next reset 0 for no reset
518 time::steady_clock::Duration m_resetTimer;
519 /// @brief Timer to cancel reset state
520 time::steady_clock::Duration m_cancelResetTimer;
521 /// @brief Lifetime of reset interest
522 time::milliseconds m_resetInterestLifetime;
523 /// @brief Lifetime of sync interest
524 time::milliseconds m_syncInterestLifetime;
525 /// @brief FreshnessPeriod of SyncReply
526 time::milliseconds m_syncReplyFreshness;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800527 /// @brief Lifetime of recovery interest
528 time::milliseconds m_recoveryInterestLifetime;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700529
Yingdi Yucd339022014-11-05 17:51:19 -0800530 // Security
Yingdi Yuf7ede412014-08-30 20:37:52 -0700531 ndn::KeyChain m_keyChain;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500532 std::shared_ptr<Validator> m_validator;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700533
Yingdi Yuf7ede412014-08-30 20:37:52 -0700534 int m_instanceId;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500535 static int s_instanceCounter;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700536};
537
Alexander Afanasyev89036292018-02-13 17:19:50 -0500538#ifdef CHRONOSYNC_HAVE_TESTS
539size_t
540getMaxPacketLimit();
541#endif // CHRONOSYNC_HAVE_TESTS
Yingdi Yuf7ede412014-08-30 20:37:52 -0700542
543} // namespace chronosync
544
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800545#endif // CHRONOSYNC_LOGIC_HPP