Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 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_FACE_SYSTEM_HPP |
| 27 | #define NFD_DAEMON_FACE_FACE_SYSTEM_HPP |
| 28 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 29 | #include "channel.hpp" |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 30 | #include "core/config-file.hpp" |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 31 | #include "core/network-interface.hpp" |
| 32 | #include "core/network-interface-predicate.hpp" |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 33 | |
| 34 | namespace nfd { |
| 35 | |
| 36 | class FaceTable; |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 37 | |
| 38 | namespace face { |
| 39 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 40 | class ProtocolFactory; |
| 41 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 42 | /** \brief entry point of the face system |
| 43 | * |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 44 | * NFD's face system is organized as a FaceSystem-ProtocolFactory-Channel-Face hierarchy. |
| 45 | * FaceSystem class is the entry point of NFD's face system and owns ProtocolFactory objects. |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 46 | */ |
| 47 | class FaceSystem : noncopyable |
| 48 | { |
| 49 | public: |
| 50 | explicit |
| 51 | FaceSystem(FaceTable& faceTable); |
| 52 | |
| 53 | /** \return ProtocolFactory objects owned by the FaceSystem |
| 54 | */ |
| 55 | std::set<const ProtocolFactory*> |
| 56 | listProtocolFactories() const; |
| 57 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 58 | /** \return ProtocolFactory for the specified registered factory id or nullptr if not found |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 59 | */ |
| 60 | ProtocolFactory* |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 61 | getFactoryById(const std::string& id); |
| 62 | |
| 63 | /** \return ProtocolFactory for the specified FaceUri scheme or nullptr if not found |
| 64 | */ |
| 65 | ProtocolFactory* |
| 66 | getFactoryByScheme(const std::string& scheme); |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 67 | |
| 68 | /** \brief register handler for face_system section of NFD configuration file |
| 69 | */ |
| 70 | void |
| 71 | setConfigFile(ConfigFile& configFile); |
| 72 | |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 73 | /** \brief context for processing a config section in ProtocolFactory |
| 74 | */ |
| 75 | class ConfigContext : noncopyable |
| 76 | { |
| 77 | public: |
| 78 | const std::vector<NetworkInterfaceInfo>& |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame^] | 79 | listNetifs() const |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 80 | { |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame^] | 81 | ///\todo get netifs from NetworkMonitor |
| 82 | return m_netifs; |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | public: |
| 86 | bool isDryRun; |
| 87 | FaceCreatedCallback addFace; |
| 88 | ///\todo add NetworkMonitor |
| 89 | |
| 90 | private: |
Junxiao Shi | 7003c60 | 2017-01-10 13:35:28 +0000 | [diff] [blame^] | 91 | std::vector<NetworkInterfaceInfo> m_netifs; |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 92 | |
| 93 | friend class FaceSystem; |
| 94 | }; |
| 95 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 96 | private: |
| 97 | void |
| 98 | processConfig(const ConfigSection& configSection, bool isDryRun, |
| 99 | const std::string& filename); |
| 100 | |
| 101 | void |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 102 | processSectionUdp(const ConfigSection& configSection, bool isDryRun, |
| 103 | const std::vector<NetworkInterfaceInfo>& nicList); |
| 104 | |
| 105 | void |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 106 | processSectionWebSocket(const ConfigSection& configSection, bool isDryRun); |
| 107 | |
| 108 | PUBLIC_WITH_TESTS_ELSE_PRIVATE: |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 109 | /** \brief config section name => protocol factory |
| 110 | * |
| 111 | * \todo #3904 store unique_ptr<ProtocolFactory> here, and reference_wrapper<ProtocolFactory> |
| 112 | * in m_factoryByScheme |
| 113 | */ |
| 114 | std::map<std::string, shared_ptr<ProtocolFactory>> m_factories; |
| 115 | |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 116 | /** \brief scheme => protocol factory |
| 117 | * |
| 118 | * The same protocol factory may be available under multiple schemes. |
| 119 | */ |
Junxiao Shi | 38b24c7 | 2017-01-05 02:59:31 +0000 | [diff] [blame] | 120 | std::map<std::string, shared_ptr<ProtocolFactory>> m_factoryByScheme; |
Junxiao Shi | b859031 | 2016-12-29 21:22:25 +0000 | [diff] [blame] | 121 | |
| 122 | FaceTable& m_faceTable; |
| 123 | }; |
| 124 | |
| 125 | } // namespace face |
| 126 | |
| 127 | using face::FaceSystem; |
| 128 | |
| 129 | } // namespace nfd |
| 130 | |
| 131 | #endif // NFD_DAEMON_FACE_FACE_SYSTEM_HPP |