Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 1 | /* -*- 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 Shi | 643b36b | 2015-09-23 17:17:41 -0700 | [diff] [blame^] | 34 | #include <ndn-cxx/lp/packet.hpp> |
Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 35 | |
| 36 | namespace nfd { |
| 37 | |
| 38 | class InternalFace; |
| 39 | class InternalClientFace; |
| 40 | |
| 41 | shared_ptr<InternalClientFace> |
| 42 | makeInternalClientFace(const shared_ptr<InternalFace>& face, ndn::KeyChain& keyChain); |
| 43 | |
| 44 | /** \brief a client face that is connected to NFD InternalFace |
| 45 | */ |
| 46 | class InternalClientFace : public ndn::Face |
| 47 | { |
| 48 | public: |
| 49 | template<typename Packet> |
| 50 | void |
| 51 | receive(const Packet& packet); |
| 52 | |
| 53 | private: |
| 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 | |
| 78 | private: |
| 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 | |
| 90 | private: |
| 91 | shared_ptr<InternalFace> m_face; |
| 92 | shared_ptr<InternalClientFace::Transport> m_transport; |
| 93 | }; |
| 94 | |
| 95 | template<typename Packet> |
| 96 | void |
| 97 | InternalClientFace::receive(const Packet& packet) |
| 98 | { |
Junxiao Shi | 643b36b | 2015-09-23 17:17:41 -0700 | [diff] [blame^] | 99 | lp::Packet lpPacket(packet.wireEncode()); |
Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 100 | |
Junxiao Shi | 643b36b | 2015-09-23 17:17:41 -0700 | [diff] [blame^] | 101 | ndn::nfd::LocalControlHeader localControlHeader = packet.getLocalControlHeader(); |
Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 102 | |
Junxiao Shi | 643b36b | 2015-09-23 17:17:41 -0700 | [diff] [blame^] | 103 | if (localControlHeader.hasIncomingFaceId()) { |
| 104 | lpPacket.add<lp::IncomingFaceIdField>(localControlHeader.getIncomingFaceId()); |
Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 105 | } |
Junxiao Shi | 643b36b | 2015-09-23 17:17:41 -0700 | [diff] [blame^] | 106 | |
| 107 | if (localControlHeader.hasNextHopFaceId()) { |
| 108 | lpPacket.add<lp::NextHopFaceIdField>(localControlHeader.getNextHopFaceId()); |
Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 109 | } |
Junxiao Shi | 643b36b | 2015-09-23 17:17:41 -0700 | [diff] [blame^] | 110 | |
| 111 | m_transport->receive(lpPacket.wireEncode()); |
Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | } // namespace nfd |
| 115 | |
| 116 | #endif // NFD_DAEMON_FACE_INTERNAL_CLIENT_FACE_HPP |