peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 3 | * Copyright (c) 2014-2017, Regents of the University of California |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 4 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 5 | * This file is part of NDN DeLorean, An Authentication System for Data Archives in |
| 6 | * Named Data Networking. See AUTHORS.md for complete list of NDN DeLorean authors |
| 7 | * and contributors. |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 8 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 9 | * NDN DeLorean is free software: you can redistribute it and/or modify it under |
| 10 | * the terms of the GNU General Public License as published by the Free Software |
| 11 | * Foundation, either version 3 of the License, or (at your option) any later |
| 12 | * version. |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 13 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 14 | * NDN DeLorean is distributed in the hope that it will be useful, but WITHOUT ANY |
| 15 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 16 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 17 | * |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 18 | * You should have received a copy of the GNU General Public License along with NDN |
| 19 | * DeLorean, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 22 | #ifndef NDN_DELOREAN_CORE_NODE_HPP |
| 23 | #define NDN_DELOREAN_CORE_NODE_HPP |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 24 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 25 | #include "common.hpp" |
| 26 | #include "util/non-negative-integer.hpp" |
| 27 | #include <ndn-cxx/encoding/buffer.hpp> |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 28 | |
| 29 | namespace nsl { |
| 30 | |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 31 | class Node |
| 32 | { |
| 33 | public: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 34 | class Error : public std::runtime_error |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 35 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 36 | public: |
| 37 | explicit |
| 38 | Error(const std::string& what) |
| 39 | : std::runtime_error(what) |
| 40 | { |
| 41 | } |
| 42 | }; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 43 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 44 | class Index |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 45 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 46 | public: |
| 47 | explicit |
| 48 | Index(const NonNegativeInteger& seqNo = 0, size_t level = 0); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 49 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 50 | /** |
| 51 | * @brief compare two indices |
| 52 | * |
| 53 | * A index is larger than the other if its seqNo is larger than the other, |
| 54 | * or their seqNos are equal but its level is lower. |
| 55 | */ |
| 56 | bool |
| 57 | operator<(const Index& other) const; |
| 58 | |
| 59 | bool |
| 60 | operator==(const Index& other) const; |
| 61 | |
| 62 | bool |
| 63 | operator!=(const Index& other) const; |
| 64 | |
| 65 | bool |
| 66 | equals(const Index& other) const; |
| 67 | |
| 68 | public: |
| 69 | NonNegativeInteger seqNo; |
| 70 | size_t level; |
| 71 | NonNegativeInteger range; |
| 72 | }; |
| 73 | |
| 74 | public: |
| 75 | Node(const NonNegativeInteger& seqNo, |
| 76 | size_t level, |
| 77 | const NonNegativeInteger& leafSeqNo = 0, |
| 78 | ndn::ConstBufferPtr hash = nullptr); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 79 | |
| 80 | const Index& |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 81 | getIndex() const |
| 82 | { |
| 83 | return m_index; |
| 84 | } |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 85 | |
| 86 | void |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 87 | setLeafSeqNo(const NonNegativeInteger& leafSeqNo); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 88 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 89 | const NonNegativeInteger& |
| 90 | getLeafSeqNo() const |
| 91 | { |
| 92 | return m_leafSeqNo; |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | setHash(ndn::ConstBufferPtr hash); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 97 | |
| 98 | ndn::ConstBufferPtr |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 99 | getHash() const |
| 100 | { |
| 101 | return m_hash; |
| 102 | } |
| 103 | |
| 104 | bool |
| 105 | isFull() const; |
| 106 | |
| 107 | static ndn::ConstBufferPtr |
| 108 | getEmptyHash(); |
| 109 | |
| 110 | protected: |
| 111 | Index m_index; |
| 112 | NonNegativeInteger m_leafSeqNo; |
| 113 | ndn::ConstBufferPtr m_hash; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 114 | |
| 115 | private: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 116 | static ndn::ConstBufferPtr EMPTY_HASH; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 119 | typedef shared_ptr<Node> NodePtr; |
| 120 | typedef shared_ptr<const Node> ConstNodePtr; |
| 121 | |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 122 | } // namespace nsl |
| 123 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame^] | 124 | #endif // NDN_DELOREAN_CORE_NODE_HPP |