blob: 2bf63252997a41083076a40e33840dd96467b8b9 [file] [log] [blame]
Yingdi Yudea99be2014-08-15 10:45:43 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Ashlesh Gawande08784d42017-09-06 23:40:21 -05003 * Copyright (c) 2012-2017 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 */
23
24#include "leaf.hpp"
25
26namespace chronosync {
27
28Leaf::Leaf(const Name& sessionName, const SeqNo& seq)
29 : m_sessionName(sessionName)
30 , m_seq(seq)
31{
32 updateDigest();
33}
34
35Leaf::Leaf(const Name& userPrefix, uint64_t session, const SeqNo& seq)
36 : m_sessionName(userPrefix)
37 , m_seq(seq)
38{
39 m_sessionName.appendNumber(session);
40 updateDigest();
41}
42
43Leaf::~Leaf()
44{
45}
46
Ashlesh Gawande08784d42017-09-06 23:40:21 -050047ConstBufferPtr
Yingdi Yudea99be2014-08-15 10:45:43 -070048Leaf::getDigest() const
49{
50 return m_digest.computeDigest();
51}
52
53void
54Leaf::setSeq(const SeqNo& seq)
55{
56 if (seq > m_seq) {
57 m_seq = seq;
58 updateDigest();
59 }
60}
61
62void
63Leaf::updateDigest()
64{
65 m_digest.reset();
66 m_digest << getSessionName().wireEncode() << getSeq();
67 m_digest.computeDigest();
68}
69
70std::ostream&
71operator<<(std::ostream& os, const Leaf& leaf)
72{
73 os << leaf.getSessionName() << "(" << leaf.getSeq() << ")";
74 return os;
75}
76
77
78} // namespace chronosync