blob: fa07cabaf480994d3acf5f6857e762e6b9d0d529 [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
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -070030namespace ndn {
31namespace delorean {
peizhen guocf4df2d2014-08-12 13:22:32 -070032
Yingdi Yu0c3e5912015-03-17 14:22:38 -070033class Leaf
peizhen guocf4df2d2014-08-12 13:22:32 -070034{
35public:
Yingdi Yu0c3e5912015-03-17 14:22:38 -070036 class Error : public std::runtime_error
peizhen guocf4df2d2014-08-12 13:22:32 -070037 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070038 public:
39 explicit
40 Error(const std::string& what)
41 : std::runtime_error(what)
42 {
43 }
44 };
45
46public:
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 guocf4df2d2014-08-12 13:22:32 -070062 }
63
Yingdi Yu0c3e5912015-03-17 14:22:38 -070064 void
65 setDataName(const Name& dataName);
peizhen guocf4df2d2014-08-12 13:22:32 -070066
Yingdi Yu0c3e5912015-03-17 14:22:38 -070067 const Name&
68 getDataName() const
peizhen guocf4df2d2014-08-12 13:22:32 -070069 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070070 return m_dataName;
peizhen guocf4df2d2014-08-12 13:22:32 -070071 }
72
Yingdi Yu0c3e5912015-03-17 14:22:38 -070073 void
74 setTimestamp(const Timestamp& timestamp);
peizhen guocf4df2d2014-08-12 13:22:32 -070075
Yingdi Yu0c3e5912015-03-17 14:22:38 -070076 const Timestamp&
77 getTimestamp() const
peizhen guocf4df2d2014-08-12 13:22:32 -070078 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070079 return m_timestamp;
peizhen guocf4df2d2014-08-12 13:22:32 -070080 }
81
Yingdi Yu0c3e5912015-03-17 14:22:38 -070082 void
83 setSignerSeqNo(const NonNegativeInteger& signerSeqNo);
peizhen guocf4df2d2014-08-12 13:22:32 -070084
Yingdi Yu0c3e5912015-03-17 14:22:38 -070085 const NonNegativeInteger&
86 getSignerSeqNo() const
peizhen guocf4df2d2014-08-12 13:22:32 -070087 {
Yingdi Yu0c3e5912015-03-17 14:22:38 -070088 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 guocf4df2d2014-08-12 13:22:32 -070098 }
99
100 ndn::ConstBufferPtr
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700101 getHash() const;
peizhen guocf4df2d2014-08-12 13:22:32 -0700102
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700103 shared_ptr<Data>
104 encode() const;
peizhen guocf4df2d2014-08-12 13:22:32 -0700105
106 void
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700107 decode(const Data& data);
108
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700109NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700110 /// @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
123public:
124 static const Name EMPTY_NAME;
125
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700126NDN_DELOREAN_PUBLIC_WITH_TESTS_ELSE_PRIVATE:
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700127 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 guocf4df2d2014-08-12 13:22:32 -0700130
131private:
Yingdi Yu0c3e5912015-03-17 14:22:38 -0700132 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 guocf4df2d2014-08-12 13:22:32 -0700140};
141
Alexander Afanasyev49e2e4c2017-05-06 13:42:57 -0700142} // namespace delorean
143} // namespace ndn
peizhen guocf4df2d2014-08-12 13:22:32 -0700144
Alexander Afanasyevbe998ac2017-05-06 13:11:42 -0700145#endif // NDN_DELOREAN_CORE_LEAF_HPP