peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California |
| 4 | * |
| 5 | * This file is part of NSL (NDN Signature Logger). |
| 6 | * See AUTHORS.md for complete list of NSL authors and contributors. |
| 7 | * |
| 8 | * NSL 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, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NSL 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 | * NSL, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 19 | * See AUTHORS.md for complete list of nsl authors and contributors. |
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 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 22 | #ifndef NSL_CORE_LEAF_HPP |
| 23 | #define NSL_CORE_LEAF_HPP |
| 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 | |
| 30 | namespace nsl { |
| 31 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 32 | class Leaf |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 33 | { |
| 34 | public: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 35 | class Error : public std::runtime_error |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 36 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 37 | public: |
| 38 | explicit |
| 39 | Error(const std::string& what) |
| 40 | : std::runtime_error(what) |
| 41 | { |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | public: |
| 46 | Leaf(); |
| 47 | |
| 48 | Leaf(const Name& dataName, |
| 49 | const Timestamp& timestamp, |
| 50 | const NonNegativeInteger& leafSeqNo, |
| 51 | const NonNegativeInteger& signerSeqNo, |
| 52 | const Name& loggerName = EMPTY_NAME); |
| 53 | |
| 54 | void |
| 55 | setDataSeqNo(const NonNegativeInteger& dataSeqNo); |
| 56 | |
| 57 | const NonNegativeInteger& |
| 58 | getDataSeqNo() const |
| 59 | { |
| 60 | return m_dataSeqNo; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 63 | void |
| 64 | setDataName(const Name& dataName); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 65 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 66 | const Name& |
| 67 | getDataName() const |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 68 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 69 | return m_dataName; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 72 | void |
| 73 | setTimestamp(const Timestamp& timestamp); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 74 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 75 | const Timestamp& |
| 76 | getTimestamp() const |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 77 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 78 | return m_timestamp; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 81 | void |
| 82 | setSignerSeqNo(const NonNegativeInteger& signerSeqNo); |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 84 | const NonNegativeInteger& |
| 85 | getSignerSeqNo() const |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 86 | { |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 87 | return m_signerSeqNo; |
| 88 | } |
| 89 | |
| 90 | void |
| 91 | setLoggerName(const Name& loggerName); |
| 92 | |
| 93 | const Name& |
| 94 | getLoggerName() const |
| 95 | { |
| 96 | return m_loggerName; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | ndn::ConstBufferPtr |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 100 | getHash() const; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 101 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 102 | shared_ptr<Data> |
| 103 | encode() const; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 104 | |
| 105 | void |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 106 | decode(const Data& data); |
| 107 | |
| 108 | NSL_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 109 | /// @brief Encode to a wire format or estimate wire format |
| 110 | template<ndn::encoding::Tag TAG> |
| 111 | size_t |
| 112 | wireEncode(ndn::EncodingImpl<TAG>& block) const; |
| 113 | |
| 114 | /// @brief Encode to a wire format |
| 115 | const Block& |
| 116 | wireEncode() const; |
| 117 | |
| 118 | /// @brief Decode from a wire format |
| 119 | void |
| 120 | wireDecode(const Block& wire); |
| 121 | |
| 122 | public: |
| 123 | static const Name EMPTY_NAME; |
| 124 | |
| 125 | NSL_PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
| 126 | static const size_t N_LOGGER_LEAF_SUFFIX; |
| 127 | static const ssize_t OFFSET_LEAF_SEQNO; |
| 128 | static const ssize_t OFFSET_LEAF_HASH; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 129 | |
| 130 | private: |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 131 | Name m_dataName; |
| 132 | Timestamp m_timestamp; |
| 133 | NonNegativeInteger m_dataSeqNo; |
| 134 | NonNegativeInteger m_signerSeqNo; |
| 135 | |
| 136 | mutable Block m_wire; |
| 137 | |
| 138 | Name m_loggerName; |
peizhen guo | cf4df2d | 2014-08-12 13:22:32 -0700 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | } // namespace nsl |
| 142 | |
Yingdi Yu | 0c3e591 | 2015-03-17 14:22:38 -0700 | [diff] [blame^] | 143 | #endif // NSL_CORE_LEAF_HPP |