Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 3 | * Copyright (c) 2012-2017 University of California, Los Angeles |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -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 | */ |
| 23 | |
| 24 | #include "leaf.hpp" |
| 25 | |
| 26 | namespace chronosync { |
| 27 | |
| 28 | Leaf::Leaf(const Name& sessionName, const SeqNo& seq) |
| 29 | : m_sessionName(sessionName) |
| 30 | , m_seq(seq) |
| 31 | { |
| 32 | updateDigest(); |
| 33 | } |
| 34 | |
| 35 | Leaf::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 | |
| 43 | Leaf::~Leaf() |
| 44 | { |
| 45 | } |
| 46 | |
Ashlesh Gawande | 08784d4 | 2017-09-06 23:40:21 -0500 | [diff] [blame] | 47 | ConstBufferPtr |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 48 | Leaf::getDigest() const |
| 49 | { |
| 50 | return m_digest.computeDigest(); |
| 51 | } |
| 52 | |
| 53 | void |
| 54 | Leaf::setSeq(const SeqNo& seq) |
| 55 | { |
| 56 | if (seq > m_seq) { |
| 57 | m_seq = seq; |
| 58 | updateDigest(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | Leaf::updateDigest() |
| 64 | { |
| 65 | m_digest.reset(); |
| 66 | m_digest << getSessionName().wireEncode() << getSeq(); |
| 67 | m_digest.computeDigest(); |
| 68 | } |
| 69 | |
| 70 | std::ostream& |
| 71 | operator<<(std::ostream& os, const Leaf& leaf) |
| 72 | { |
| 73 | os << leaf.getSessionName() << "(" << leaf.getSeq() << ")"; |
| 74 | return os; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | } // namespace chronosync |