All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
certificate-cache-v2.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
23 #ifndef NDN_CERTIFICATE_CACHE_V2_HPP
24 #define NDN_CERTIFICATE_CACHE_V2_HPP
25 
26 #include <float.h>
27 #include <map>
28 #include "../../interest.hpp"
29 #include "certificate-v2.hpp"
30 
31 namespace ndn {
32 
39 public:
46  CertificateCacheV2(Milliseconds maxLifetimeMilliseconds = getDefaultLifetime());
47 
54  void
55  insert(const CertificateV2& certificate);
56 
64  ptr_lib::shared_ptr<CertificateV2>
65  find(const Name& certificatePrefix) const;
66 
75  ptr_lib::shared_ptr<CertificateV2>
76  find(const Interest& interest) const;
77 
83  void
84  deleteCertificate(const Name& certificateName);
85 
89  void
91  {
92  certificatesByName_.clear();
93  nextRefreshTime_ = DBL_MAX;
94  }
95 
100  static Milliseconds
101  getDefaultLifetime() { return 3600.0 * 1000; }
102 
108  void
110  {
111  nowOffsetMilliseconds_ = nowOffsetMilliseconds;
112  }
113 
114 private:
118  class Entry {
119  public:
126  Entry
127  (const ptr_lib::shared_ptr<CertificateV2>& certificate,
128  MillisecondsSince1970 removalTime)
129  : certificate_(certificate), removalTime_(removalTime)
130  {}
131 
132  Entry()
133  {
134  removalTime_ = 0;
135  }
136 
137  ptr_lib::shared_ptr<CertificateV2> certificate_;
138  MillisecondsSince1970 removalTime_;
139  };
140 
144  void
145  refresh();
146 
147  // Disable the copy constructor and assignment operator.
149  CertificateCacheV2& operator=(const CertificateCacheV2& other);
150 
151  std::map<Name, Entry> certificatesByName_;
152  MillisecondsSince1970 nextRefreshTime_;
153  Milliseconds maxLifetimeMilliseconds_;
154  Milliseconds nowOffsetMilliseconds_;
155 };
156 
157 }
158 
159 #endif
double Milliseconds
A time interval represented as the number of milliseconds.
Definition: common.hpp:114
CertificateCacheV2(Milliseconds maxLifetimeMilliseconds=getDefaultLifetime())
Create a CertificateCacheV2.
Definition: certificate-cache-v2.cpp:34
CertificateV2 represents a certificate following the certificate format naming convention.
Definition: certificate-v2.hpp:81
static Milliseconds getDefaultLifetime()
Get the default maximum lifetime (1 hour).
Definition: certificate-cache-v2.hpp:101
void deleteCertificate(const Name &certificateName)
Remove the certificate whose name equals the given name.
Definition: certificate-cache-v2.cpp:110
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:43
void insert(const CertificateV2 &certificate)
Insert the certificate into the cache.
Definition: certificate-cache-v2.cpp:42
double MillisecondsSince1970
The calendar time represented as the number of milliseconds since 1/1/1970.
Definition: common.hpp:119
A CertificateCacheV2 holds other user's verified certificates in security v2 format CertificateV2...
Definition: certificate-cache-v2.hpp:38
void setNowOffsetMilliseconds_(Milliseconds nowOffsetMilliseconds)
Set the offset when insert() and refresh() get the current time, which should only be used for testin...
Definition: certificate-cache-v2.hpp:109
void clear()
Clear all certificates from the cache.
Definition: certificate-cache-v2.hpp:90
ptr_lib::shared_ptr< CertificateV2 > find(const Name &certificatePrefix) const
Find the certificate by the given key name.
Definition: certificate-cache-v2.cpp:69