esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ping-server.hpp
Go to the documentation of this file.
1#ifndef NDNPH_APP_PING_SERVER_HPP
2#define NDNPH_APP_PING_SERVER_HPP
3
4#include "../face/packet-handler.hpp"
5#include "../keychain/digest.hpp"
6
7namespace ndnph {
8
10class PingServer : public PacketHandler {
11public:
17 explicit PingServer(Name prefix, Face& face, const PrivateKey& signer = DigestKey::get())
18 : PacketHandler(face)
19 , m_prefix(std::move(prefix))
20 , m_signer(signer) {}
21
22private:
23 bool processInterest(Interest interest) final {
24 if (!m_prefix.isPrefixOf(interest.getName())) {
25 return false;
26 }
27
28 StaticRegion<1024> region;
29 Data data = region.create<Data>();
30 NDNPH_ASSERT(!!data);
31 data.setName(interest.getName());
32 data.setFreshnessPeriod(1);
33 reply(data.sign(m_signer));
34 return true;
35 }
36
37private:
38 Name m_prefix;
39 const PrivateKey& m_signer;
40};
41
42} // namespace ndnph
43
44#endif // NDNPH_APP_PING_SERVER_HPP
Data packet.
Definition data.hpp:136
void setName(const Name &v)
Definition data.hpp:144
Signed sign(const PrivateKey &key, DSigInfo sigInfo=DSigInfo()) const
Sign the packet with a private key.
Definition data.hpp:254
void setFreshnessPeriod(uint32_t v)
Definition data.hpp:160
static const DigestKey & get()
Definition digest.hpp:16
Network layer face.
Definition face.hpp:12
Interest packet.
Definition interest.hpp:284
Name.
Definition name.hpp:14
bool isPrefixOf(const Name &other) const
Determine if this name is a prefix of other.
Definition name.hpp:239
Base class to receive packets from Face.
Definition packet-handler.hpp:10
bool reply(Arg &&... arg)
Synchronously transmit a packet in reply to current processing packet.
Definition packet-handler.hpp:119
Respond to every incoming Interest with empty Data.
Definition ping-server.hpp:10
bool processInterest(Interest interest) final
Override to receive Interest packets.
Definition ping-server.hpp:23
PingServer(Name prefix, Face &face, const PrivateKey &signer=DigestKey::get())
Constructor.
Definition ping-server.hpp:17
Private key.
Definition private-key.hpp:9
RefType create(Arg &&... arg)
Allocate and create an object, and return its reference.
Definition region.hpp:90
Region with statically allocated memory.
Definition region.hpp:143
#define NDNPH_ASSERT(x)
Definition common.hpp:30
Definition fs.hpp:33