blob: 651a19bb74fdee527192edf02a97c67e89296b4f [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -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 Afanasyev9cbf70a2014-02-17 18:07:51 -080020 */
21
22#ifndef NDN_HELPERS_COMMAND_INTEREST_GENERATOR_HPP
23#define NDN_HELPERS_COMMAND_INTEREST_GENERATOR_HPP
24
25#include "../interest.hpp"
26#include "../security/key-chain.hpp"
27#include "../util/time.hpp"
28#include "../util/random.hpp"
29
30namespace ndn {
31
32/**
33 * @brief Helper class to generate CommandInterests
34 *
Yingdi Yu50b13902014-07-09 15:05:46 -070035 * @deprecated Use SignedInterest (generated by KeyChain) instead.
36 * See KeyChain::sign and KeyChain::signByIdentity methods.
37 *
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080038 * @see http://redmine.named-data.net/projects/nfd/wiki/Command_Interests
39 */
40class CommandInterestGenerator
41{
42public:
43 static const Name DEFAULT_CERTIFICATE_NAME;
44
45 CommandInterestGenerator()
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070046 : m_lastTimestamp(time::toUnixTimestamp(time::system_clock::now()))
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080047 {
48 }
49
50 virtual
51 ~CommandInterestGenerator()
52 {
53 }
54
55 void
56 generate(Interest& interest, const Name& certificateName = Name());
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070057
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080058 void
59 generateWithIdentity(Interest& interest, const Name& identity);
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070060
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080061private:
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070062 time::milliseconds m_lastTimestamp;
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080063 KeyChain m_keyChain;
64};
65
66
67inline void
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070068CommandInterestGenerator::generate(Interest& interest,
Yingdi Yue66bf2a2014-04-28 17:07:36 -070069 const Name& certificateName /*= Name()*/)
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080070{
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070071 if (certificateName.empty())
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080072 m_keyChain.sign(interest);
73 else
74 m_keyChain.sign(interest, certificateName);
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080075}
Alexander Afanasyevaa0e7da2014-03-17 14:37:33 -070076
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080077inline void
78CommandInterestGenerator::generateWithIdentity(Interest& interest, const Name& identity)
79{
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080080 m_keyChain.signByIdentity(interest, identity);
Alexander Afanasyev9cbf70a2014-02-17 18:07:51 -080081}
82
83
84} // namespace ndn
85
86#endif // NDN_HELPERS_COMMAND_INTEREST_GENERATOR_HPP