blob: 4ee11d38d199675ff07cdc49409197527b71508c [file] [log] [blame]
peizhen guocf4df2d2014-08-12 13:22:32 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07003 * Copyright (c) 2014-2017, Regents of the University of California
peizhen guocf4df2d2014-08-12 13:22:32 -07004 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07005 * 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 guocf4df2d2014-08-12 13:22:32 -07008 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -07009 * 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 guocf4df2d2014-08-12 13:22:32 -070013 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070014 * 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 guocf4df2d2014-08-12 13:22:32 -070017 *
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070018 * 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 guocf4df2d2014-08-12 13:22:32 -070020 */
peizhen guocf4df2d2014-08-12 13:22:32 -070021
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -070022#ifndef NDN_DELOREAN_CORE_LEAF_HPP
23#define NDN_DELOREAN_CORE_LEAF_HPP
Yingdi Yu0c3e5912015-03-17 14:22:38 -070024
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
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700108NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700109 /// @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
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700125NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700126 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
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700143#endif // NDN_DELOREAN_CORE_LEAF_HPP