certificate-cache.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2017 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_SECURITY_V2_CERTIFICATE_CACHE_HPP
23 #define NDN_SECURITY_V2_CERTIFICATE_CACHE_HPP
24 
25 #include "../../interest.hpp"
26 #include "certificate.hpp"
27 
28 #include <boost/multi_index_container.hpp>
29 #include <boost/multi_index/ordered_index.hpp>
30 #include <boost/multi_index/mem_fun.hpp>
31 #include <boost/multi_index/member.hpp>
32 
33 namespace ndn {
34 namespace security {
35 namespace v2 {
36 
43 class CertificateCache : noncopyable
44 {
45 public:
51  explicit
52  CertificateCache(const time::nanoseconds& maxLifetime = getDefaultLifetime());
53 
62  void
63  insert(const Certificate& cert);
64 
68  void
69  clear();
70 
78  const Certificate*
79  find(const Name& certPrefix) const;
80 
90  const Certificate*
91  find(const Interest& interest) const;
92 
93 private:
94  class Entry
95  {
96  public:
97  Entry(const Certificate& cert, const time::system_clock::TimePoint& removalTime)
98  : cert(cert)
99  , removalTime(removalTime)
100  {
101  }
102 
103  const Name&
104  getCertName() const
105  {
106  return cert.getName();
107  }
108 
109  public:
110  Certificate cert;
111  time::system_clock::TimePoint removalTime;
112  };
113 
117  void
118  refresh();
119 
120 public:
121  static const time::nanoseconds&
123 
124 private:
126  typedef boost::multi_index::multi_index_container<
127  Entry,
128  boost::multi_index::indexed_by<
129  boost::multi_index::ordered_non_unique<
130  boost::multi_index::member<Entry, const time::system_clock::TimePoint, &Entry::removalTime>
131  >,
132  boost::multi_index::ordered_unique<
133  boost::multi_index::const_mem_fun<Entry, const Name&, &Entry::getCertName>
134  >
135  >
136  > CertIndex;
137 
138  typedef CertIndex::nth_index<0>::type CertIndexByTime;
139  typedef CertIndex::nth_index<1>::type CertIndexByName;
140  CertIndex m_certs;
141  CertIndexByTime& m_certsByTime;
142  CertIndexByName& m_certsByName;
143  time::nanoseconds m_maxLifetime;
144 };
145 
146 } // namespace v2
147 } // namespace security
148 } // namespace ndn
149 
150 #endif // NDN_SECURITY_V2_CERTIFICATE_CACHE_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
The certificate following the certificate format naming convention.
Definition: certificate.hpp:81
void clear()
Remove all certificates from cache.
represents an Interest packet
Definition: interest.hpp:42
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
Represents a container for verified certificates.
CertificateCache(const time::nanoseconds &maxLifetime=getDefaultLifetime())
Create an object for certificate cache.
Represents an absolute name.
Definition: name.hpp:42
time_point TimePoint
Definition: time.hpp:90
static const time::nanoseconds & getDefaultLifetime()
const Name & getName() const
Get name.
Definition: data.hpp:121
void insert(const Certificate &cert)
Insert certificate into cache.