blob: 55cbc5a4517073e6f29e9c6eba6c0ffe70097980 [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 Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 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 Afanasyevaa0e7da2014-03-17 14:37:33 -070032
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080033/**
34 * @brief Cache of validated certificates with freshness-based eviction policy
35 *
36 * Validated certificates will stay in cache for the duration of their freshness period.
37 * The lifetime of the certificate in cache can be extended by "re-inserting" it in the cache.
38 */
Yingdi Yu7640cb32014-01-29 20:00:50 -080039class CertificateCacheTtl : public CertificateCache
40{
41public:
Alexander Afanasyeva4297a62014-06-19 13:29:34 -070042 explicit
Yingdi Yu58f33712014-04-16 16:57:47 -070043 CertificateCacheTtl(boost::asio::io_service& io,
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080044 const time::seconds& defaultTtl = time::seconds(3600));
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070045
Yingdi Yu7640cb32014-01-29 20:00:50 -080046 virtual
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080047 ~CertificateCacheTtl();
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070048
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080049 virtual void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070050 insertCertificate(shared_ptr<const IdentityCertificate> certificate);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070051
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080052 virtual shared_ptr<const IdentityCertificate>
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070053 getCertificate(const Name& certificateNameWithoutVersion);
Yingdi Yu7640cb32014-01-29 20:00:50 -080054
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080055 virtual void
Yingdi Yu58f33712014-04-16 16:57:47 -070056 reset();
57
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080058 virtual size_t
Yingdi Yu58f33712014-04-16 16:57:47 -070059 getSize();
60
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070061private:
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080062 void
Yingdi Yu4b8c6a22014-04-15 23:00:54 -070063 insert(shared_ptr<const IdentityCertificate> certificate);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070064
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080065 void
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070066 remove(const Name& certificateName);
Yingdi Yu7640cb32014-01-29 20:00:50 -080067
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080068 void
Yingdi Yu58f33712014-04-16 16:57:47 -070069 removeAll();
70
Yingdi Yu7640cb32014-01-29 20:00:50 -080071protected:
Yingdi Yu58f33712014-04-16 16:57:47 -070072 typedef std::map<Name, std::pair<shared_ptr<const IdentityCertificate>, EventId> > Cache;
Yingdi Yu7640cb32014-01-29 20:00:50 -080073
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070074 time::seconds m_defaultTtl;
Yingdi Yu7640cb32014-01-29 20:00:50 -080075 Cache m_cache;
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080076 boost::asio::io_service& m_io;
Yingdi Yu7640cb32014-01-29 20:00:50 -080077 Scheduler m_scheduler;
78};
79
Yingdi Yufc40d872014-02-18 12:56:04 -080080} // namespace ndn
Yingdi Yu7640cb32014-01-29 20:00:50 -080081
Alexander Afanasyeveabffdf2014-11-13 13:50:33 -080082#endif // NDN_SECURITY_CERTIFICATE_CACHE_TTL_HPP