Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2012-2017 University of California, Los Angeles |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 4 | * |
| 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 Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 23 | * @author Sonu Mishra <https://www.linkedin.com/in/mishrasonu> |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #ifndef CHRONOSYNC_LOGIC_HPP |
| 27 | #define CHRONOSYNC_LOGIC_HPP |
| 28 | |
| 29 | #include "boost-header.h" |
| 30 | #include <memory> |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 31 | #include <unordered_map> |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 32 | |
| 33 | #include <ndn-cxx/face.hpp> |
| 34 | #include <ndn-cxx/util/scheduler.hpp> |
| 35 | #include <ndn-cxx/security/key-chain.hpp> |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 36 | #include <ndn-cxx/security/validator.hpp> |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 37 | |
| 38 | #include "interest-table.hpp" |
| 39 | #include "diff-state-container.hpp" |
| 40 | |
| 41 | namespace chronosync { |
| 42 | |
| 43 | /** |
| 44 | * @brief The missing sequence numbers for a session |
| 45 | * |
| 46 | * This class is used to notify the clients of Logic |
| 47 | * the details of state changes. |
| 48 | * |
| 49 | * Instances of this class is usually used as elements of some containers |
| 50 | * such as std::vector, thus it is copyable. |
| 51 | */ |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 52 | class NodeInfo |
| 53 | { |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 54 | public: |
| 55 | Name userPrefix; |
| 56 | Name signingId; |
| 57 | Name sessionName; |
| 58 | SeqNo seqNo; |
| 59 | }; |
| 60 | |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 61 | class MissingDataInfo |
| 62 | { |
| 63 | public: |
| 64 | /// @brief session name |
| 65 | Name session; |
| 66 | /// @brief the lowest one of missing sequence numbers |
| 67 | SeqNo low; |
| 68 | /// @brief the highest one of missing sequence numbers |
| 69 | SeqNo high; |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * @brief The callback function to handle state updates |
| 74 | * |
| 75 | * The parameter is a set of MissingDataInfo, of which each corresponds to |
| 76 | * a session that has changed its state. |
| 77 | */ |
| 78 | typedef function<void(const std::vector<MissingDataInfo>&)> UpdateCallback; |
| 79 | |
| 80 | /** |
| 81 | * @brief Logic of ChronoSync |
| 82 | */ |
| 83 | class Logic : noncopyable |
| 84 | { |
| 85 | public: |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 86 | class Error : public std::runtime_error |
| 87 | { |
| 88 | public: |
| 89 | explicit |
| 90 | Error(const std::string& what) |
| 91 | : std::runtime_error(what) |
| 92 | { |
| 93 | } |
| 94 | }; |
| 95 | |
| 96 | public: |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 97 | static const time::steady_clock::Duration DEFAULT_RESET_TIMER; |
| 98 | static const time::steady_clock::Duration DEFAULT_CANCEL_RESET_TIMER; |
| 99 | static const time::milliseconds DEFAULT_RESET_INTEREST_LIFETIME; |
| 100 | static const time::milliseconds DEFAULT_SYNC_INTEREST_LIFETIME; |
| 101 | static const time::milliseconds DEFAULT_SYNC_REPLY_FRESHNESS; |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 102 | static const time::milliseconds DEFAULT_RECOVERY_INTEREST_LIFETIME; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * @brief Constructor |
| 106 | * |
Yingdi Yu | 9d5679a | 2015-02-01 00:17:58 -0800 | [diff] [blame] | 107 | * @param face The face used to communication, will be shutdown in destructor |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 108 | * @param syncPrefix The prefix of the sync group |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 109 | * @param defaultUserPrefix The prefix of the first user added to this session |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 110 | * @param onUpdate The callback function to handle state updates |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 111 | * @param defaultSigningId The signing Id of the default user |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 112 | * @param validator The validator for packet validation |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 113 | * @param resetTimer The timer to periodically send Reset Interest |
| 114 | * @param syncReplyFreshness The FreshnessPeriod of sync reply |
| 115 | * @param resetInterestLifetime The lifetime of sync interest |
| 116 | * @param resetInterestLifetime The lifetime of Reset Interest |
| 117 | * @param cancelResetTimer The timer to exit from Reset state |
| 118 | */ |
| 119 | Logic(ndn::Face& face, |
| 120 | const Name& syncPrefix, |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 121 | const Name& defaultUserPrefix, |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 122 | const UpdateCallback& onUpdate, |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 123 | const Name& defaultSigningId = DEFAULT_NAME, |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 124 | ndn::shared_ptr<ndn::Validator> validator = DEFAULT_VALIDATOR, |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 125 | const time::steady_clock::Duration& resetTimer = DEFAULT_RESET_TIMER, |
| 126 | const time::steady_clock::Duration& cancelResetTimer = DEFAULT_CANCEL_RESET_TIMER, |
| 127 | const time::milliseconds& resetInterestLifetime = DEFAULT_RESET_INTEREST_LIFETIME, |
| 128 | const time::milliseconds& syncInterestLifetime = DEFAULT_SYNC_INTEREST_LIFETIME, |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 129 | const time::milliseconds& syncReplyFreshness = DEFAULT_SYNC_REPLY_FRESHNESS, |
| 130 | const time::milliseconds& recoveryInterestLifetime = DEFAULT_RECOVERY_INTEREST_LIFETIME); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 131 | |
| 132 | ~Logic(); |
| 133 | |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 134 | /** |
| 135 | * @brief Reset the sync tree (and restart synchronization again) |
| 136 | * |
| 137 | * @param isOnInterest a flag that tells whether the reset is called by reset interest. |
| 138 | */ |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 139 | void |
Qiuhan Ding | fb8c9e0 | 2015-01-30 14:04:55 -0800 | [diff] [blame] | 140 | reset(bool isOnInterest = false); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 141 | |
| 142 | /** |
| 143 | * @brief Set user prefix |
| 144 | * |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 145 | * This method will also change the default user and signing Id of that user. |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 146 | * |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 147 | * @param defaultUserPrefix The prefix of user. |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 148 | */ |
| 149 | void |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 150 | setDefaultUserPrefix(const Name& defaultUserPrefix); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 151 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 152 | /// @brief Get the name of default user. |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 153 | const Name& |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 154 | getDefaultUserPrefix() const |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 155 | { |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 156 | return m_defaultUserPrefix; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 159 | /** |
| 160 | * @brief Add user node into the local session. |
| 161 | * |
| 162 | * This method also reset after adding |
| 163 | * |
| 164 | * @param userPrefix prefix of the added node |
| 165 | * @param signingId signing Id of the added node |
| 166 | */ |
| 167 | void |
| 168 | addUserNode(const Name& userPrefix, const Name& signingId = DEFAULT_NAME); |
| 169 | |
| 170 | /// @brief remove the node from the local session |
| 171 | void |
| 172 | removeUserNode(const Name& userPrefix); |
| 173 | |
| 174 | /** |
| 175 | * @brief Get the name of the local session. |
| 176 | * |
| 177 | * This method gets the session name according to prefix, if prefix is not specified, |
| 178 | * it returns the session name of default user. |
| 179 | * |
| 180 | * @param prefix prefix of the node |
| 181 | */ |
| 182 | const Name& |
| 183 | getSessionName(Name prefix = EMPTY_NAME); |
| 184 | |
| 185 | /** |
| 186 | * @brief Get current seqNo of the local session. |
| 187 | * |
| 188 | * This method gets the seqNo according to prefix, if prefix is not specified, |
| 189 | * it returns the seqNo of default user. |
| 190 | * |
| 191 | * @param prefix prefix of the node |
| 192 | */ |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 193 | const SeqNo& |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 194 | getSeqNo(Name prefix = EMPTY_NAME); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 195 | |
| 196 | /** |
| 197 | * @brief Update the seqNo of the local session |
| 198 | * |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 199 | * The method updates the existing seqNo with the supplied seqNo and prefix. |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 200 | * |
| 201 | * @param seq The new seqNo. |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 202 | * @param updatePrefix The prefix of node to update. |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 203 | */ |
| 204 | void |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 205 | updateSeqNo(const SeqNo& seq, const Name& updatePrefix = EMPTY_NAME); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 206 | |
| 207 | /// @brief Get root digest of current sync tree |
| 208 | ndn::ConstBufferPtr |
| 209 | getRootDigest() const; |
| 210 | |
| 211 | /// @brief Get the name of all sessions |
| 212 | std::set<Name> |
| 213 | getSessionNames() const; |
| 214 | |
Yingdi Yu | 906c2ea | 2014-10-31 11:24:50 -0700 | [diff] [blame] | 215 | CHRONOSYNC_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 216 | void |
| 217 | printState(std::ostream& os) const; |
| 218 | |
| 219 | ndn::Scheduler& |
| 220 | getScheduler() |
| 221 | { |
| 222 | return m_scheduler; |
| 223 | } |
| 224 | |
| 225 | State& |
| 226 | getState() |
| 227 | { |
| 228 | return m_state; |
| 229 | } |
| 230 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 231 | |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 232 | private: |
| 233 | /** |
| 234 | * @brief Callback to handle Sync Interest |
| 235 | * |
| 236 | * This method checks whether an incoming interest is a normal one or a reset |
| 237 | * and dispatches the incoming interest to corresponding processing methods. |
| 238 | * |
| 239 | * @param prefix The prefix of the sync group. |
| 240 | * @param interest The incoming sync interest. |
| 241 | */ |
| 242 | void |
| 243 | onSyncInterest(const Name& prefix, const Interest& interest); |
| 244 | |
| 245 | /** |
| 246 | * @brief Callback to handle Sync prefix registration failure |
| 247 | * |
| 248 | * This method does nothing for now. |
| 249 | * |
| 250 | * @param prefix The prefix of the sync group. |
| 251 | * @param msg The error message. |
| 252 | */ |
| 253 | void |
| 254 | onSyncRegisterFailed(const Name& prefix, const std::string& msg); |
| 255 | |
| 256 | /** |
| 257 | * @brief Callback to handle Sync Reply |
| 258 | * |
| 259 | * This method calls validator to validate Sync Reply. |
| 260 | * For now, validation is disabled, Logic::onSyncDataValidated is called |
| 261 | * directly. |
| 262 | * |
| 263 | * @param interest The Sync Interest |
| 264 | * @param data The reply to the Sync Interest |
| 265 | */ |
| 266 | void |
| 267 | onSyncData(const Interest& interest, Data& data); |
| 268 | |
| 269 | /** |
| 270 | * @brief Callback to handle reply to Reset Interest. |
| 271 | * |
| 272 | * This method does nothing, since reply to Reset Interest is not useful for now. |
| 273 | * |
| 274 | * @param interest The Reset Interest |
| 275 | * @param data The reply to the Reset Interest |
| 276 | */ |
| 277 | void |
| 278 | onResetData(const Interest& interest, Data& data); |
| 279 | |
| 280 | /** |
| 281 | * @brief Callback to handle Sync Interest timeout. |
| 282 | * |
| 283 | * This method does nothing, since Logic per se handles timeout explicitly. |
| 284 | * |
| 285 | * @param interest The Sync Interest |
| 286 | */ |
| 287 | void |
| 288 | onSyncTimeout(const Interest& interest); |
| 289 | |
| 290 | /** |
| 291 | * @brief Callback to invalid Sync Reply. |
| 292 | * |
| 293 | * This method does nothing but drops the invalid reply. |
| 294 | * |
| 295 | * @param data The invalid Sync Reply |
| 296 | */ |
| 297 | void |
| 298 | onSyncDataValidationFailed(const shared_ptr<const Data>& data); |
| 299 | |
| 300 | /** |
| 301 | * @brief Callback to valid Sync Reply. |
| 302 | * |
| 303 | * This method simply passes the valid reply to processSyncData. |
| 304 | * |
| 305 | * @param data The valid Sync Reply. |
| 306 | */ |
| 307 | void |
| 308 | onSyncDataValidated(const shared_ptr<const Data>& data); |
| 309 | |
| 310 | /** |
| 311 | * @brief Process normal Sync Interest |
| 312 | * |
| 313 | * This method extracts the digest from the incoming Sync Interest, |
| 314 | * compares it against current local digest, and process the Sync |
| 315 | * Interest according to the comparison result. See docs/design.rst |
| 316 | * for more details. |
| 317 | * |
| 318 | * @param interest The incoming interest |
| 319 | * @param isTimedProcessing True if the interest needs an immediate reply, |
| 320 | * otherwise hold the interest for a while before |
| 321 | * making a reply (to avoid unnecessary recovery) |
| 322 | */ |
| 323 | void |
| 324 | processSyncInterest(const shared_ptr<const Interest>& interest, |
| 325 | bool isTimedProcessing = false); |
| 326 | |
| 327 | /** |
| 328 | * @brief Process reset Sync Interest |
| 329 | * |
| 330 | * This method simply call Logic::reset() |
| 331 | * |
| 332 | * @param interest The incoming interest. |
| 333 | */ |
| 334 | void |
| 335 | processResetInterest(const Interest& interest); |
| 336 | |
| 337 | /** |
| 338 | * @brief Process Sync Reply. |
| 339 | * |
| 340 | * This method extracts state update information from Sync Reply and applies |
| 341 | * it to the Sync Tree and re-express Sync Interest. |
| 342 | * |
| 343 | * @param name The data name of the Sync Reply. |
| 344 | * @param digest The digest in the data name. |
| 345 | * @param syncReplyBlock The content of the Sync Reply. |
| 346 | */ |
| 347 | void |
| 348 | processSyncData(const Name& name, |
| 349 | ndn::ConstBufferPtr digest, |
| 350 | const Block& syncReplyBlock); |
| 351 | |
| 352 | /** |
| 353 | * @brief Insert state diff into log |
| 354 | * |
| 355 | * @param diff The diff . |
| 356 | * @param previousRoot The root digest before state changes. |
| 357 | */ |
| 358 | void |
| 359 | insertToDiffLog(DiffStatePtr diff, |
| 360 | ndn::ConstBufferPtr previousRoot); |
| 361 | |
| 362 | /** |
| 363 | * @brief Reply to all pending Sync Interests with a particular commit (or diff) |
| 364 | * |
| 365 | * @param commit The diff. |
| 366 | */ |
| 367 | void |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 368 | satisfyPendingSyncInterests(const Name& updatedPrefix, ConstDiffStatePtr commit); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 369 | |
| 370 | /// @brief Helper method to send normal Sync Interest |
| 371 | void |
| 372 | sendSyncInterest(); |
| 373 | |
| 374 | /// @brief Helper method to send reset Sync Interest |
| 375 | void |
| 376 | sendResetInterest(); |
| 377 | |
| 378 | /// @brief Helper method to send Sync Reply |
| 379 | void |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 380 | sendSyncData(const Name& nodePrefix, const Name& name, const State& state); |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * @brief Unset reset status |
| 384 | * |
| 385 | * By invoking this method, one can add its own state into the Sync Tree, thus |
| 386 | * jumping out of the reset status |
| 387 | */ |
| 388 | void |
| 389 | cancelReset(); |
| 390 | |
| 391 | void |
| 392 | printDigest(ndn::ConstBufferPtr digest); |
| 393 | |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 394 | /** |
| 395 | * @brief Helper method to send Recovery Interest |
| 396 | * |
| 397 | * @param digest The digest to be included in the recovery interest |
| 398 | */ |
| 399 | void |
| 400 | sendRecoveryInterest(ndn::ConstBufferPtr digest); |
| 401 | |
| 402 | /** |
| 403 | * @brief Process Recovery Interest |
| 404 | * |
| 405 | * This method extracts the digest from the incoming Recovery Interest. |
| 406 | * If it recognizes this incoming digest, then it sends its full state |
| 407 | * as reply. |
| 408 | * |
| 409 | * @param interest The incoming interest |
| 410 | */ |
| 411 | void |
| 412 | processRecoveryInterest(const Interest& interest); |
| 413 | |
| 414 | /** |
| 415 | * @brief Callback to handle Recovery Reply |
| 416 | * |
| 417 | * This method calls Logic::onSyncDataValidated directly. |
| 418 | * |
| 419 | * @param interest The Recovery Interest |
| 420 | * @param data The reply to the Recovery Interest |
| 421 | */ |
| 422 | void |
| 423 | onRecoveryData(const Interest& interest, Data& data); |
| 424 | |
| 425 | /** |
| 426 | * @brief Callback to handle Recovery Interest timeout. |
| 427 | * |
| 428 | * This method does nothing. |
| 429 | * |
| 430 | * @param interest The Recovery Interest |
| 431 | */ |
| 432 | void |
| 433 | onRecoveryTimeout(const Interest& interest); |
| 434 | |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 435 | public: |
| 436 | static const ndn::Name DEFAULT_NAME; |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 437 | static const ndn::Name EMPTY_NAME; |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 438 | static const ndn::shared_ptr<ndn::Validator> DEFAULT_VALIDATOR; |
| 439 | |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 440 | private: |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 441 | typedef std::unordered_map<ndn::Name, NodeInfo> NodeList; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 442 | |
| 443 | static const ndn::ConstBufferPtr EMPTY_DIGEST; |
| 444 | static const ndn::name::Component RESET_COMPONENT; |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 445 | static const ndn::name::Component RECOVERY_COMPONENT; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 446 | |
| 447 | // Communication |
| 448 | ndn::Face& m_face; |
| 449 | Name m_syncPrefix; |
| 450 | const ndn::RegisteredPrefixId* m_syncRegisteredPrefixId; |
| 451 | Name m_syncReset; |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 452 | Name m_defaultUserPrefix; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 453 | |
| 454 | // State |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 455 | NodeList m_nodeList; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 456 | State m_state; |
| 457 | DiffStateContainer m_log; |
| 458 | InterestTable m_interestTable; |
| 459 | Name m_outstandingInterestName; |
| 460 | const ndn::PendingInterestId* m_outstandingInterestId; |
| 461 | bool m_isInReset; |
| 462 | bool m_needPeriodReset; |
| 463 | |
| 464 | // Callback |
| 465 | UpdateCallback m_onUpdate; |
| 466 | |
| 467 | // Event |
| 468 | ndn::Scheduler m_scheduler; |
| 469 | ndn::EventId m_delayedInterestProcessingId; |
| 470 | ndn::EventId m_reexpressingInterestId; |
| 471 | ndn::EventId m_resetInterestId; |
| 472 | |
| 473 | // Timer |
| 474 | boost::mt19937 m_randomGenerator; |
| 475 | boost::variate_generator<boost::mt19937&, boost::uniform_int<> > m_rangeUniformRandom; |
| 476 | boost::variate_generator<boost::mt19937&, boost::uniform_int<> > m_reexpressionJitter; |
| 477 | /// @brief Timer to send next reset 0 for no reset |
| 478 | time::steady_clock::Duration m_resetTimer; |
| 479 | /// @brief Timer to cancel reset state |
| 480 | time::steady_clock::Duration m_cancelResetTimer; |
| 481 | /// @brief Lifetime of reset interest |
| 482 | time::milliseconds m_resetInterestLifetime; |
| 483 | /// @brief Lifetime of sync interest |
| 484 | time::milliseconds m_syncInterestLifetime; |
| 485 | /// @brief FreshnessPeriod of SyncReply |
| 486 | time::milliseconds m_syncReplyFreshness; |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 487 | /// @brief Lifetime of recovery interest |
| 488 | time::milliseconds m_recoveryInterestLifetime; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 489 | |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 490 | // Security |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 491 | ndn::Name m_defaultSigningId; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 492 | ndn::KeyChain m_keyChain; |
Yingdi Yu | cd33902 | 2014-11-05 17:51:19 -0800 | [diff] [blame] | 493 | ndn::shared_ptr<ndn::Validator> m_validator; |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 494 | |
Qiuhan Ding | 8c095fd | 2014-11-19 17:38:32 -0800 | [diff] [blame] | 495 | |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 496 | #ifdef _DEBUG |
| 497 | int m_instanceId; |
| 498 | static int m_instanceCounter; |
| 499 | #endif |
| 500 | }; |
| 501 | |
| 502 | |
| 503 | } // namespace chronosync |
| 504 | |
Sonu Mishra | 4d3a2e0 | 2017-01-18 20:27:51 -0800 | [diff] [blame^] | 505 | #endif // CHRONOSYNC_LOGIC_HPP |