blob: e0ef8374bc2d0fc660c4faa7e7d524f51556fc20 [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Yingdi Yu7640cb32014-01-29 20:00:50 -08002/**
Alexander Afanasyev2fa59392016-07-29 17:24:23 -07003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -070020 *
21 * @author Yingdi Yu <http://irl.cs.ucla.edu/~yingdi/>
Yingdi Yu7640cb32014-01-29 20:00:50 -080022 */
23
Yingdi Yufc40d872014-02-18 12:56:04 -080024#ifndef NDN_SECURITY_CERTIFICATE_CACHE_TTL_HPP
25#define NDN_SECURITY_CERTIFICATE_CACHE_TTL_HPP
Yingdi Yu7640cb32014-01-29 20:00:50 -080026
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080027#include "../common.hpp"
Yingdi Yu7640cb32014-01-29 20:00:50 -080028#include "certificate-cache.hpp"
29#include "../util/scheduler.hpp"
Yingdi Yu7640cb32014-01-29 20:00:50 -080030
Alexander Afanasyeve2dcdfd2014-02-07 15:53:28 -080031namespace ndn {
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070032namespace security {
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070033
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080034/**
35 * @brief Cache of validated certificates with freshness-based eviction policy
36 *
37 * Validated certificates will stay in cache for the duration of their freshness period.
38 * The lifetime of the certificate in cache can be extended by "re-inserting" it in the cache.
39 */
Yingdi Yu7640cb32014-01-29 20:00:50 -080040class CertificateCacheTtl : public CertificateCache
41{
42public:
Alexander Afanasyeva4297a62014-06-19 13:29:34 -070043 explicit
Yingdi Yu58f33712014-04-16 16:57:47 -070044 CertificateCacheTtl(boost::asio::io_service& io,
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080045 const time::seconds& defaultTtl = time::seconds(3600));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070046
Yingdi Yu7640cb32014-01-29 20:00:50 -080047 virtual
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080048 ~CertificateCacheTtl();
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070049
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080050 virtual void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070051 insertCertificate(shared_ptr<const v1::IdentityCertificate> certificate);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070052
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070053 virtual shared_ptr<const v1::IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070054 getCertificate(const Name& certificateNameWithoutVersion);
Yingdi Yu7640cb32014-01-29 20:00:50 -080055
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080056 virtual void
Yingdi Yu58f33712014-04-16 16:57:47 -070057 reset();
58
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080059 virtual size_t
Yingdi Yu58f33712014-04-16 16:57:47 -070060 getSize();
61
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070062private:
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080063 void
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070064 insert(shared_ptr<const v1::IdentityCertificate> certificate);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070065
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080066 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070067 remove(const Name& certificateName);
Yingdi Yu7640cb32014-01-29 20:00:50 -080068
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080069 void
Yingdi Yu58f33712014-04-16 16:57:47 -070070 removeAll();
71
Yingdi Yu7640cb32014-01-29 20:00:50 -080072protected:
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070073 typedef std::map<Name, std::pair<shared_ptr<const v1::IdentityCertificate>, EventId> > Cache;
Yingdi Yu7640cb32014-01-29 20:00:50 -080074
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070075 time::seconds m_defaultTtl;
Yingdi Yu7640cb32014-01-29 20:00:50 -080076 Cache m_cache;
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080077 boost::asio::io_service& m_io;
Yingdi Yu7640cb32014-01-29 20:00:50 -080078 Scheduler m_scheduler;
79};
80
Alexander Afanasyev2fa59392016-07-29 17:24:23 -070081} // namespace security
82
83using security::CertificateCacheTtl;
84
Yingdi Yufc40d872014-02-18 12:56:04 -080085} // namespace ndn
Yingdi Yu7640cb32014-01-29 20:00:50 -080086
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080087#endif // NDN_SECURITY_CERTIFICATE_CACHE_TTL_HPP