blob: 3f8b0a5898052bc07a37b4fced787fe1d92d3901 [file] [log] [blame]
peizhen guocf4df2d2014-08-12 13:22:32 -07001/* -*- 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 Yu0c3e5912015-03-17 14:22:38 -070019 * See AUTHORS.md for complete list of nsl authors and contributors.
peizhen guocf4df2d2014-08-12 13:22:32 -070020 */
peizhen guocf4df2d2014-08-12 13:22:32 -070021
Yingdi Yu0c3e5912015-03-17 14:22:38 -070022#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 guocf4df2d2014-08-12 13:22:32 -070029
30namespace nsl {
31
Yingdi Yu0c3e5912015-03-17 14:22:38 -070032class Leaf
peizhen guocf4df2d2014-08-12 13:22:32 -070033{
34public:
Yingdi Yu0c3e5912015-03-17 14:22:38 -070035 class Error : public std::runtime_error
peizhen guocf4df2d2014-08-12 13:22:32 -070036 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070037 public:
38 explicit
39 Error(const std::string& what)
40 : std::runtime_error(what)
41 {
42 }
43 };
44
45public:
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 guocf4df2d2014-08-12 13:22:32 -070061 }
62
Yingdi Yu0c3e5912015-03-17 14:22:38 -070063 void
64 setDataName(const Name& dataName);
peizhen guocf4df2d2014-08-12 13:22:32 -070065
Yingdi Yu0c3e5912015-03-17 14:22:38 -070066 const Name&
67 getDataName() const
peizhen guocf4df2d2014-08-12 13:22:32 -070068 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070069 return m_dataName;
peizhen guocf4df2d2014-08-12 13:22:32 -070070 }
71
Yingdi Yu0c3e5912015-03-17 14:22:38 -070072 void
73 setTimestamp(const Timestamp& timestamp);
peizhen guocf4df2d2014-08-12 13:22:32 -070074
Yingdi Yu0c3e5912015-03-17 14:22:38 -070075 const Timestamp&
76 getTimestamp() const
peizhen guocf4df2d2014-08-12 13:22:32 -070077 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070078 return m_timestamp;
peizhen guocf4df2d2014-08-12 13:22:32 -070079 }
80
Yingdi Yu0c3e5912015-03-17 14:22:38 -070081 void
82 setSignerSeqNo(const NonNegativeInteger& signerSeqNo);
peizhen guocf4df2d2014-08-12 13:22:32 -070083
Yingdi Yu0c3e5912015-03-17 14:22:38 -070084 const NonNegativeInteger&
85 getSignerSeqNo() const
peizhen guocf4df2d2014-08-12 13:22:32 -070086 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070087 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 guocf4df2d2014-08-12 13:22:32 -070097 }
98
99 ndn::ConstBufferPtr
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700100 getHash() const;
peizhen guocf4df2d2014-08-12 13:22:32 -0700101
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700102 shared_ptr<Data>
103 encode() const;
peizhen guocf4df2d2014-08-12 13:22:32 -0700104
105 void
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700106 decode(const Data& data);
107
108NSL_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
122public:
123 static const Name EMPTY_NAME;
124
125NSL_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 guocf4df2d2014-08-12 13:22:32 -0700129
130private:
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700131 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 guocf4df2d2014-08-12 13:22:32 -0700139};
140
141} // namespace nsl
142
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700143#endif // NSL_CORE_LEAF_HPP