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 | */ |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 21 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 22 | #ifndef NDN_DELOREAN_CORE_LEAF_HPP |
| 23 | #define NDN_DELOREAN_CORE_LEAF_HPP |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 24 | |
| 25 | #include "common.hpp" |
| 26 | #include "util/non-negative-integer.hpp" |
| 27 | #include "util/timestamp.hpp" |
| 28 | #include <ndn-cxx/encoding/buffer.hpp> |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 29 | |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame] | 30 | namespace ndn { |
| 31 | namespace delorean { |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 32 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 33 | class Leaf |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 34 | { |
| 35 | public: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 36 | class Error : public std::runtime_error |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 37 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 38 | public: |
| 39 | explicit |
| 40 | Error(const std::string& what) |
| 41 | : std::runtime_error(what) |
| 42 | { |
| 43 | } |
| 44 | }; |
| 45 | |
| 46 | public: |
| 47 | Leaf(); |
| 48 | |
| 49 | Leaf(const Name& dataName, |
| 50 | const Timestamp& timestamp, |
| 51 | const NonNegativeInteger& leafSeqNo, |
| 52 | const NonNegativeInteger& signerSeqNo, |
| 53 | const Name& loggerName = EMPTY_NAME); |
| 54 | |
| 55 | void |
| 56 | setDataSeqNo(const NonNegativeInteger& dataSeqNo); |
| 57 | |
| 58 | const NonNegativeInteger& |
| 59 | getDataSeqNo() const |
| 60 | { |
| 61 | return m_dataSeqNo; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 64 | void |
| 65 | setDataName(const Name& dataName); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 66 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 67 | const Name& |
| 68 | getDataName() const |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 69 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 70 | return m_dataName; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 73 | void |
| 74 | setTimestamp(const Timestamp& timestamp); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 75 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 76 | const Timestamp& |
| 77 | getTimestamp() const |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 78 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 79 | return m_timestamp; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 82 | void |
| 83 | setSignerSeqNo(const NonNegativeInteger& signerSeqNo); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 84 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 85 | const NonNegativeInteger& |
| 86 | getSignerSeqNo() const |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 87 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 88 | return m_signerSeqNo; |
| 89 | } |
| 90 | |
| 91 | void |
| 92 | setLoggerName(const Name& loggerName); |
| 93 | |
| 94 | const Name& |
| 95 | getLoggerName() const |
| 96 | { |
| 97 | return m_loggerName; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | ndn::ConstBufferPtr |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 101 | getHash() const; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 102 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 103 | shared_ptr<Data> |
| 104 | encode() const; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 105 | |
| 106 | void |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 107 | decode(const Data& data); |
| 108 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 109 | NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 110 | /// @brief Encode to a wire format or estimate wire format |
| 111 | template<ndn::encoding::Tag TAG> |
| 112 | size_t |
| 113 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 114 | |
| 115 | /// @brief Encode to a wire format |
| 116 | const Block& |
| 117 | wireEncode() const; |
| 118 | |
| 119 | /// @brief Decode from a wire format |
| 120 | void |
| 121 | wireDecode(const Block& wire); |
| 122 | |
| 123 | public: |
| 124 | static const Name EMPTY_NAME; |
| 125 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 126 | NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 127 | static const size_t N_LOGGER_LEAF_SUFFIX; |
| 128 | static const ssize_t OFFSET_LEAF_SEQNO; |
| 129 | static const ssize_t OFFSET_LEAF_HASH; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 130 | |
| 131 | private: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame] | 132 | Name m_dataName; |
| 133 | Timestamp m_timestamp; |
| 134 | NonNegativeInteger m_dataSeqNo; |
| 135 | NonNegativeInteger m_signerSeqNo; |
| 136 | |
| 137 | mutable Block m_wire; |
| 138 | |
| 139 | Name m_loggerName; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Alexander Afanasyev | 49e2e4c | 2017-05-06 13:42:57 -0700 | [diff] [blame] | 142 | } // namespace delorean |
| 143 | } // namespace ndn |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 144 | |
Alexander Afanasyev | be998ac | 2017-05-06 13:11:42 -0700 | [diff] [blame] | 145 | #endif // NDN_DELOREAN_CORE_LEAF_HPP |