blob: abc375b2567d13f0edd8ffd487daf3225a5bf74c [file] [log] [blame]
Yanbiao Li4ee73d42015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#ifndef NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP
27#define NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP
28
29#include "common.hpp"
30
31#include <ndn-cxx/face.hpp>
32#include <ndn-cxx/security/key-chain.hpp>
33#include <ndn-cxx/transport/transport.hpp>
Junxiao Shi643b36b2015-09-23 17:17:41 -070034#include <ndn-cxx/lp/packet.hpp>
Yanbiao Li4ee73d42015-08-19 16:30:16 -070035
36namespace nfd {
37
38class InternalFace;
39class InternalClientFace;
40
41shared_ptr<InternalClientFace>
42makeInternalClientFace(const shared_ptr<InternalFace>& face, ndn::KeyChain& keyChain);
43
44/** \brief a client face that is connected to NFD InternalFace
45 */
46class InternalClientFace : public ndn::Face
47{
48public:
49 template<typename Packet>
50 void
51 receive(const Packet& packet);
52
53private:
54 class Transport : public ndn::Transport
55 {
56 public:
57 signal::Signal<Transport, Block> onSendBlock;
58
59 void
60 receive(const Block& block);
61
62 virtual void
63 close() DECL_OVERRIDE;
64
65 virtual void
66 send(const Block& wire) DECL_OVERRIDE;
67
68 virtual void
69 send(const Block& header, const Block& payload) DECL_OVERRIDE;
70
71 virtual void
72 pause() DECL_OVERRIDE;
73
74 virtual void
75 resume() DECL_OVERRIDE;
76 };
77
78private:
79 InternalClientFace(const shared_ptr<InternalFace>& face,
80 const shared_ptr<InternalClientFace::Transport>& transport,
81 ndn::KeyChain& keyChain);
82
83 void
84 construct();
85
86 friend shared_ptr<InternalClientFace>
87 makeInternalClientFace(const shared_ptr<InternalFace>& face,
88 ndn::KeyChain& keyChain);
89
90private:
91 shared_ptr<InternalFace> m_face;
92 shared_ptr<InternalClientFace::Transport> m_transport;
93};
94
95template<typename Packet>
96void
97InternalClientFace::receive(const Packet& packet)
98{
Junxiao Shi643b36b2015-09-23 17:17:41 -070099 lp::Packet lpPacket(packet.wireEncode());
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700100
Junxiao Shi643b36b2015-09-23 17:17:41 -0700101 ndn::nfd::LocalControlHeader localControlHeader = packet.getLocalControlHeader();
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700102
Junxiao Shi643b36b2015-09-23 17:17:41 -0700103 if (localControlHeader.hasIncomingFaceId()) {
104 lpPacket.add<lp::IncomingFaceIdField>(localControlHeader.getIncomingFaceId());
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700105 }
Junxiao Shi643b36b2015-09-23 17:17:41 -0700106
107 if (localControlHeader.hasNextHopFaceId()) {
108 lpPacket.add<lp::NextHopFaceIdField>(localControlHeader.getNextHopFaceId());
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700109 }
Junxiao Shi643b36b2015-09-23 17:17:41 -0700110
111 m_transport->receive(lpPacket.wireEncode());
Yanbiao Li4ee73d42015-08-19 16:30:16 -0700112}
113
114} // namespace nfd
115
116#endif // NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP