blob: 952b063c6af1cc25dcbb1cbba4fa3f6a4195c045 [file] [log] [blame]
Yingdi Yudea99be2014-08-15 10:45:43 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Davide Pesavento07684bc2021-02-07 20:09:28 -05003 * Copyright (c) 2012-2021 University of California, Los Angeles
Yingdi Yudea99be2014-08-15 10:45:43 -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>
23 */
24
25#ifndef CHRONOSYNC_LEAF_HPP
26#define CHRONOSYNC_LEAF_HPP
27
Davide Pesavento07684bc2021-02-07 20:09:28 -050028#include "detail/common.hpp"
Ashlesh Gawande08784d42017-09-06 23:40:21 -050029
Ashlesh Gawande687cf922017-05-30 15:04:16 -050030#include <ndn-cxx/util/sha256.hpp>
Yingdi Yudea99be2014-08-15 10:45:43 -070031
32namespace chronosync {
33
Ashlesh Gawande08784d42017-09-06 23:40:21 -050034using SeqNo = uint64_t;
Yingdi Yudea99be2014-08-15 10:45:43 -070035
36/**
37 * @brief Sync tree leaf
38 *
39 * The leaf node should be copyable when used to construct diff between two states.
40 */
41class Leaf
42{
43public:
44 Leaf(const Name& sessionName, const SeqNo& seq);
45
46 Leaf(const Name& userPrefix, uint64_t session, const SeqNo& seq);
47
48 virtual
49 ~Leaf();
50
51 const Name&
52 getSessionName() const
53 {
54 return m_sessionName;
55 }
56
57 const SeqNo&
58 getSeq() const
59 {
60 return m_seq;
61 }
62
Ashlesh Gawande08784d42017-09-06 23:40:21 -050063 ConstBufferPtr
Yingdi Yudea99be2014-08-15 10:45:43 -070064 getDigest() const;
65
66 /**
67 * @brief Update sequence number of the leaf
68 * @param seq Sequence number
69 *
70 * If seq is no greater than getSeq(), this operation has no effect.
71 */
72 virtual void
73 setSeq(const SeqNo& seq);
74
75private:
76 void
77 updateDigest();
78
79private:
80 Name m_sessionName;
81 SeqNo m_seq;
82
83 mutable ndn::util::Sha256 m_digest;
84};
85
Ashlesh Gawande08784d42017-09-06 23:40:21 -050086using LeafPtr = shared_ptr<Leaf>;
87using ConstLeafPtr = shared_ptr<const Leaf>;
Yingdi Yudea99be2014-08-15 10:45:43 -070088
89std::ostream&
90operator<<(std::ostream& os, const Leaf& leaf);
91
92} // namespace chronosync
93
94#endif // CHRONOSYNC_LEAF_HPP