blob: 1383ef24c7235da436db793d7b4ac52fbc9520ce [file] [log] [blame]
Yingdi Yuf7ede412014-08-30 20:37:52 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Davide Pesavento5f5101a2022-03-11 20:05:03 -05003 * Copyright (c) 2012-2022 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
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080034#include <unordered_map>
Yingdi Yuf7ede412014-08-30 20:37:52 -070035
Yingdi Yuf7ede412014-08-30 20:37:52 -070036namespace chronosync {
37
38/**
39 * @brief The missing sequence numbers for a session
40 *
41 * This class is used to notify the clients of Logic
42 * the details of state changes.
43 *
44 * Instances of this class is usually used as elements of some containers
45 * such as std::vector, thus it is copyable.
46 */
Sonu Mishra4d3a2e02017-01-18 20:27:51 -080047class NodeInfo
48{
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080049public:
50 Name userPrefix;
51 Name signingId;
52 Name sessionName;
53 SeqNo seqNo;
54};
55
Yingdi Yuf7ede412014-08-30 20:37:52 -070056class MissingDataInfo
57{
58public:
59 /// @brief session name
60 Name session;
61 /// @brief the lowest one of missing sequence numbers
62 SeqNo low;
63 /// @brief the highest one of missing sequence numbers
64 SeqNo high;
65};
66
67/**
68 * @brief The callback function to handle state updates
69 *
70 * The parameter is a set of MissingDataInfo, of which each corresponds to
71 * a session that has changed its state.
72 */
Ashlesh Gawande08784d42017-09-06 23:40:21 -050073using UpdateCallback = function<void(const std::vector<MissingDataInfo>&)>;
Yingdi Yuf7ede412014-08-30 20:37:52 -070074
75/**
76 * @brief Logic of ChronoSync
77 */
78class Logic : noncopyable
79{
80public:
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080081 class Error : public std::runtime_error
82 {
83 public:
Davide Pesavento07684bc2021-02-07 20:09:28 -050084 using std::runtime_error::runtime_error;
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080085 };
86
Yingdi Yuf7ede412014-08-30 20:37:52 -070087 static const time::steady_clock::Duration DEFAULT_RESET_TIMER;
88 static const time::steady_clock::Duration DEFAULT_CANCEL_RESET_TIMER;
89 static const time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME;
90 static const time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME;
91 static const time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -080092 static const time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME;
Yingdi Yuf7ede412014-08-30 20:37:52 -070093
94 /**
95 * @brief Constructor
96 *
Yingdi Yu9d5679a2015-02-01 00:17:58 -080097 * @param face The face used to communication, will be shutdown in destructor
Yingdi Yuf7ede412014-08-30 20:37:52 -070098 * @param syncPrefix The prefix of the sync group
Qiuhan Ding8c095fd2014-11-19 17:38:32 -080099 * @param defaultUserPrefix The prefix of the first user added to this session
Yingdi Yuf7ede412014-08-30 20:37:52 -0700100 * @param onUpdate The callback function to handle state updates
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800101 * @param defaultSigningId The signing Id of the default user
Yingdi Yucd339022014-11-05 17:51:19 -0800102 * @param validator The validator for packet validation
Yingdi Yuf7ede412014-08-30 20:37:52 -0700103 * @param resetTimer The timer to periodically send Reset Interest
Yingdi Yuf7ede412014-08-30 20:37:52 -0700104 * @param cancelResetTimer The timer to exit from Reset state
Ashlesh Gawande097bb442017-05-31 13:38:00 -0500105 * @param resetInterestLifetime The lifetime of Reset Interest
106 * @param syncInterestLifetime The lifetime of sync interest
107 * @param syncReplyFreshness The FreshnessPeriod of sync reply
108 * @param recoveryInterestLifetime The lifetime of recovery interest
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500109 * @param session Manually defined session ID
Yingdi Yuf7ede412014-08-30 20:37:52 -0700110 */
111 Logic(ndn::Face& face,
112 const Name& syncPrefix,
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800113 const Name& defaultUserPrefix,
Yingdi Yuf7ede412014-08-30 20:37:52 -0700114 const UpdateCallback& onUpdate,
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800115 const Name& defaultSigningId = DEFAULT_NAME,
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500116 std::shared_ptr<Validator> validator = DEFAULT_VALIDATOR,
Yingdi Yuf7ede412014-08-30 20:37:52 -0700117 const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER,
118 const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER,
119 const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME,
120 const time::milliseconds& syncInterestLifetime = DEFAULT_SYNC_INTEREST_LIFETIME,
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800121 const time::milliseconds& syncReplyFreshness = DEFAULT_SYNC_REPLY_FRESHNESS,
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500122 const time::milliseconds& recoveryInterestLifetime = DEFAULT_RECOVERY_INTEREST_LIFETIME,
Ashlesh Gawandedb862e02018-03-30 17:15:08 -0500123 const name::Component& session = name::Component());
Yingdi Yuf7ede412014-08-30 20:37:52 -0700124
125 ~Logic();
126
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -0800127 /**
128 * @brief Reset the sync tree (and restart synchronization again)
129 *
130 * @param isOnInterest a flag that tells whether the reset is called by reset interest.
131 */
Yingdi Yuf7ede412014-08-30 20:37:52 -0700132 void
Qiuhan Dingfb8c9e02015-01-30 14:04:55 -0800133 reset(bool isOnInterest = false);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700134
135 /**
136 * @brief Set user prefix
137 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800138 * This method will also change the default user and signing Id of that user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700139 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800140 * @param defaultUserPrefix The prefix of user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700141 */
142 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800143 setDefaultUserPrefix(const Name& defaultUserPrefix);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700144
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800145 /// @brief Get the name of default user.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700146 const Name&
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800147 getDefaultUserPrefix() const
Yingdi Yuf7ede412014-08-30 20:37:52 -0700148 {
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800149 return m_defaultUserPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700150 }
151
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800152 /**
153 * @brief Add user node into the local session.
154 *
155 * This method also reset after adding
156 *
157 * @param userPrefix prefix of the added node
158 * @param signingId signing Id of the added node
Alexander Afanasyevbf5bc6c2018-02-19 11:26:09 -0500159 * @param session manually defined session ID
Davide Pesaventod7de2d42019-08-01 20:55:50 -0400160 * @param shouldSendReset enable/disable sending the reset interest
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800161 */
162 void
Ashlesh Gawandedb862e02018-03-30 17:15:08 -0500163 addUserNode(const Name& userPrefix, const Name& signingId = DEFAULT_NAME,
Davide Pesaventod7de2d42019-08-01 20:55:50 -0400164 const name::Component& session = name::Component(), bool shouldSendReset = true);
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800165
166 /// @brief remove the node from the local session
167 void
168 removeUserNode(const Name& userPrefix);
169
170 /**
171 * @brief Get the name of the local session.
172 *
173 * This method gets the session name according to prefix, if prefix is not specified,
174 * it returns the session name of default user.
175 *
176 * @param prefix prefix of the node
177 */
178 const Name&
179 getSessionName(Name prefix = EMPTY_NAME);
180
181 /**
182 * @brief Get current seqNo of the local session.
183 *
184 * This method gets the seqNo according to prefix, if prefix is not specified,
185 * it returns the seqNo of default user.
186 *
187 * @param prefix prefix of the node
188 */
Yingdi Yuf7ede412014-08-30 20:37:52 -0700189 const SeqNo&
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800190 getSeqNo(Name prefix = EMPTY_NAME);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700191
192 /**
193 * @brief Update the seqNo of the local session
194 *
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800195 * The method updates the existing seqNo with the supplied seqNo and prefix.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700196 *
197 * @param seq The new seqNo.
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800198 * @param updatePrefix The prefix of node to update.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700199 */
200 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800201 updateSeqNo(const SeqNo& seq, const Name& updatePrefix = EMPTY_NAME);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700202
203 /// @brief Get root digest of current sync tree
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500204 ConstBufferPtr
Yingdi Yuf7ede412014-08-30 20:37:52 -0700205 getRootDigest() const;
206
207 /// @brief Get the name of all sessions
208 std::set<Name>
209 getSessionNames() const;
210
Yingdi Yu906c2ea2014-10-31 11:24:50 -0700211CHRONOSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yuf7ede412014-08-30 20:37:52 -0700212 void
213 printState(std::ostream& os) const;
214
215 ndn::Scheduler&
216 getScheduler()
217 {
218 return m_scheduler;
219 }
220
221 State&
222 getState()
223 {
224 return m_state;
225 }
226
Alexander Afanasyev6ee98ff2018-02-13 19:12:28 -0500227 /// Create a subset @p partialState excluding @p nExcludedStates from @p state
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -0600228 void
Alexander Afanasyev6ee98ff2018-02-13 19:12:28 -0500229 trimState(State& partialState, const State& state, size_t excludedStates);
230
231 Data
232 encodeSyncReply(const Name& nodePrefix, const Name& name, const State& state);
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800233
Yingdi Yuf7ede412014-08-30 20:37:52 -0700234private:
235 /**
236 * @brief Callback to handle Sync Interest
237 *
238 * This method checks whether an incoming interest is a normal one or a reset
239 * and dispatches the incoming interest to corresponding processing methods.
240 *
241 * @param prefix The prefix of the sync group.
242 * @param interest The incoming sync interest.
243 */
244 void
245 onSyncInterest(const Name& prefix, const Interest& interest);
246
247 /**
248 * @brief Callback to handle Sync prefix registration failure
249 *
250 * This method does nothing for now.
251 *
252 * @param prefix The prefix of the sync group.
253 * @param msg The error message.
254 */
255 void
256 onSyncRegisterFailed(const Name& prefix, const std::string& msg);
257
258 /**
259 * @brief Callback to handle Sync Reply
260 *
261 * This method calls validator to validate Sync Reply.
262 * For now, validation is disabled, Logic::onSyncDataValidated is called
263 * directly.
264 *
265 * @param interest The Sync Interest
266 * @param data The reply to the Sync Interest
267 */
268 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800269 onSyncData(const Interest& interest, const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700270
271 /**
272 * @brief Callback to handle reply to Reset Interest.
273 *
274 * This method does nothing, since reply to Reset Interest is not useful for now.
275 *
276 * @param interest The Reset Interest
277 * @param data The reply to the Reset Interest
278 */
279 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800280 onResetData(const Interest& interest, const Data& data);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700281
282 /**
Ashlesh Gawandea1ad6042019-10-07 15:56:11 -0500283 * @brief Callback to handle Sync Interest Nack
284 *
285 * This method checks whether the Nack is of type NoRoute
286 * and schedules a sync interest in m_reexpressionJitter
287 *
288 * @param interest The sync interest for which the Nack happened
289 * @param nack The incoming Nack
290 */
291 void
292 onSyncNack(const Interest& interest, const ndn::lp::Nack& nack);
293
294 /**
Yingdi Yuf7ede412014-08-30 20:37:52 -0700295 * @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 *
Davide Pesavento27416442020-01-23 23:10:24 -0500356 * @param name The data name of the Sync Reply.
357 * @param digest The digest in the data name.
358 * @param syncReply The content of the Sync Reply.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700359 */
360 void
Davide Pesavento27416442020-01-23 23:10:24 -0500361 processSyncData(const Name& name, ConstBufferPtr digest, const Block& syncReply);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700362
363 /**
364 * @brief Insert state diff into log
365 *
Davide Pesavento27416442020-01-23 23:10:24 -0500366 * @param diff The diff.
Yingdi Yuf7ede412014-08-30 20:37:52 -0700367 * @param previousRoot The root digest before state changes.
368 */
369 void
Davide Pesavento27416442020-01-23 23:10:24 -0500370 insertToDiffLog(DiffStatePtr diff, ConstBufferPtr previousRoot);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700371
372 /**
373 * @brief Reply to all pending Sync Interests with a particular commit (or diff)
374 *
375 * @param commit The diff.
376 */
377 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800378 satisfyPendingSyncInterests(const Name& updatedPrefix, ConstDiffStatePtr commit);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700379
380 /// @brief Helper method to send normal Sync Interest
381 void
382 sendSyncInterest();
383
384 /// @brief Helper method to send reset Sync Interest
385 void
386 sendResetInterest();
387
388 /// @brief Helper method to send Sync Reply
389 void
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800390 sendSyncData(const Name& nodePrefix, const Name& name, const State& state);
Yingdi Yuf7ede412014-08-30 20:37:52 -0700391
392 /**
393 * @brief Unset reset status
394 *
395 * By invoking this method, one can add its own state into the Sync Tree, thus
396 * jumping out of the reset status
397 */
398 void
399 cancelReset();
400
401 void
Davide Pesavento5f5101a2022-03-11 20:05:03 -0500402 printDigest(const ConstBufferPtr& digest) const;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700403
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800404 /**
405 * @brief Helper method to send Recovery Interest
406 *
407 * @param digest The digest to be included in the recovery interest
408 */
409 void
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500410 sendRecoveryInterest(ConstBufferPtr digest);
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800411
412 /**
413 * @brief Process Recovery Interest
414 *
415 * This method extracts the digest from the incoming Recovery Interest.
416 * If it recognizes this incoming digest, then it sends its full state
417 * as reply.
418 *
419 * @param interest The incoming interest
420 */
421 void
422 processRecoveryInterest(const Interest& interest);
423
424 /**
425 * @brief Callback to handle Recovery Reply
426 *
427 * This method calls Logic::onSyncDataValidated directly.
428 *
429 * @param interest The Recovery Interest
430 * @param data The reply to the Recovery Interest
431 */
432 void
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800433 onRecoveryData(const Interest& interest, const Data& data);
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800434
435 /**
436 * @brief Callback to handle Recovery Interest timeout.
437 *
438 * This method does nothing.
439 *
440 * @param interest The Recovery Interest
441 */
442 void
443 onRecoveryTimeout(const Interest& interest);
444
Yingdi Yucd339022014-11-05 17:51:19 -0800445public:
446 static const ndn::Name DEFAULT_NAME;
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800447 static const ndn::Name EMPTY_NAME;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500448 static const std::shared_ptr<Validator> DEFAULT_VALIDATOR;
Yingdi Yucd339022014-11-05 17:51:19 -0800449
Yingdi Yuf7ede412014-08-30 20:37:52 -0700450private:
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500451 using NodeList = std::unordered_map<ndn::Name, NodeInfo>;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700452
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500453 static const ConstBufferPtr EMPTY_DIGEST;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700454 static const ndn::name::Component RESET_COMPONENT;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800455 static const ndn::name::Component RECOVERY_COMPONENT;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700456
457 // Communication
458 ndn::Face& m_face;
459 Name m_syncPrefix;
Junxiao Shi8e4e76d2019-02-08 15:25:08 -0700460 ndn::ScopedRegisteredPrefixHandle m_syncRegisteredPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700461 Name m_syncReset;
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800462 Name m_defaultUserPrefix;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700463
464 // State
Qiuhan Ding8c095fd2014-11-19 17:38:32 -0800465 NodeList m_nodeList;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700466 State m_state;
467 DiffStateContainer m_log;
468 InterestTable m_interestTable;
Junxiao Shi8e4e76d2019-02-08 15:25:08 -0700469 Name m_pendingSyncInterestName;
470 ndn::ScopedPendingInterestHandle m_pendingSyncInterest;
471 ndn::ScopedPendingInterestHandle m_pendingResetInterest;
472 std::map<std::string, ndn::ScopedPendingInterestHandle> m_pendingRecoveryInterests;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700473 bool m_isInReset;
474 bool m_needPeriodReset;
475
476 // Callback
477 UpdateCallback m_onUpdate;
478
479 // Event
Davide Pesavento0d837e32019-03-16 22:31:14 -0400480 ndn::Scheduler m_scheduler;
481 ndn::scheduler::ScopedEventId m_delayedInterestProcessingId;
482 ndn::scheduler::ScopedEventId m_reexpressingInterestId;
483 ndn::scheduler::ScopedEventId m_resetInterestId;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700484
485 // Timer
Ashlesh Gawande9a306fe2019-01-04 11:38:18 -0600486 ndn::random::RandomNumberEngine& m_rng;
Ashlesh Gawande4a9ecd52018-02-06 14:36:19 -0600487 std::uniform_int_distribution<> m_rangeUniformRandom;
488 std::uniform_int_distribution<> m_reexpressionJitter;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700489 /// @brief Timer to send next reset 0 for no reset
490 time::steady_clock::Duration m_resetTimer;
491 /// @brief Timer to cancel reset state
492 time::steady_clock::Duration m_cancelResetTimer;
493 /// @brief Lifetime of reset interest
494 time::milliseconds m_resetInterestLifetime;
495 /// @brief Lifetime of sync interest
496 time::milliseconds m_syncInterestLifetime;
497 /// @brief FreshnessPeriod of SyncReply
498 time::milliseconds m_syncReplyFreshness;
Sonu Mishra4d3a2e02017-01-18 20:27:51 -0800499 /// @brief Lifetime of recovery interest
500 time::milliseconds m_recoveryInterestLifetime;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700501
Yingdi Yucd339022014-11-05 17:51:19 -0800502 // Security
Yingdi Yuf7ede412014-08-30 20:37:52 -0700503 ndn::KeyChain m_keyChain;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500504 std::shared_ptr<Validator> m_validator;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700505
Yingdi Yuf7ede412014-08-30 20:37:52 -0700506 int m_instanceId;
Ashlesh Gawande08784d42017-09-06 23:40:21 -0500507 static int s_instanceCounter;
Yingdi Yuf7ede412014-08-30 20:37:52 -0700508};
509
Davide Pesavento07684bc2021-02-07 20:09:28 -0500510#ifdef CHRONOSYNC_WITH_TESTS
Alexander Afanasyev89036292018-02-13 17:19:50 -0500511size_t
512getMaxPacketLimit();
Davide Pesavento07684bc2021-02-07 20:09:28 -0500513#endif // CHRONOSYNC_WITH_TESTS
Yingdi Yuf7ede412014-08-30 20:37:52 -0700514
515} // namespace chronosync
516
Alexander Afanasyeve9eda8a2017-03-09 14:40:03 -0800517#endif // CHRONOSYNC_LOGIC_HPP