v2/certificate-cache.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
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 
72  const Certificate*
73  find(const Name& certPrefix) const;
74 
84  const Certificate*
85  find(const Interest& interest) const;
86 
87 private:
88  class Entry
89  {
90  public:
91  Entry(const Certificate& cert, const time::system_clock::TimePoint& removalTime)
92  : cert(cert)
93  , removalTime(removalTime)
94  {
95  }
96 
97  const Name&
98  getCertName() const
99  {
100  return cert.getName();
101  }
102 
103  public:
104  Certificate cert;
105  time::system_clock::TimePoint removalTime;
106  };
107 
111  void
112  refresh();
113 
114 public:
115  static const time::nanoseconds&
117 
118 private:
120  typedef boost::multi_index::multi_index_container<
121  Entry,
122  boost::multi_index::indexed_by<
123  boost::multi_index::ordered_non_unique<
124  boost::multi_index::member<Entry, const time::system_clock::TimePoint, &Entry::removalTime>
125  >,
126  boost::multi_index::ordered_unique<
127  boost::multi_index::const_mem_fun<Entry, const Name&, &Entry::getCertName>
128  >
129  >
130  > CertIndex;
131 
132  typedef CertIndex::nth_index<0>::type CertIndexByTime;
133  typedef CertIndex::nth_index<1>::type CertIndexByName;
134  CertIndex m_certs;
135  CertIndexByTime& m_certsByTime;
136  CertIndexByName& m_certsByName;
137  time::nanoseconds m_maxLifetime;
138 };
139 
140 } // namespace v2
141 } // namespace security
142 } // namespace ndn
143 
144 #endif // NDN_SECURITY_V2_CERTIFICATE_CACHE_HPP
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
The certificate following the certificate format naming convention.
represents an Interest packet
Definition: interest.hpp:42
const Certificate * find(const Name &certPrefix) const
Get certificate given key name.
const Name & getName() const
Get name of the Data packet.
Definition: data.hpp:318
Represents a container for verified certificates.
CertificateCache(const time::nanoseconds &maxLifetime=getDefaultLifetime())
Create an object for certificate cache.
Name abstraction to represent an absolute name.
Definition: name.hpp:46
time_point TimePoint
Definition: time.hpp:90
static const time::nanoseconds & getDefaultLifetime()
void insert(const Certificate &cert)
Insert certificate into cache.