Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame^] | 2 | /* |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2017, Regents of the University of California, |
Junxiao Shi | fbf7834 | 2015-01-23 14:46:41 -0700 | [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. |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 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/>. |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 24 | */ |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame^] | 26 | #include "core/network.hpp" |
| 27 | #include "core/version.hpp" |
| 28 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 29 | #include <ndn-cxx/face.hpp> |
| 30 | #include <ndn-cxx/name.hpp> |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 31 | #include <ndn-cxx/encoding/buffer-stream.hpp> |
Junxiao Shi | 25c6ce4 | 2016-09-09 13:49:59 +0000 | [diff] [blame] | 32 | #include <ndn-cxx/mgmt/nfd/controller.hpp> |
| 33 | #include <ndn-cxx/mgmt/nfd/face-monitor.hpp> |
| 34 | #include <ndn-cxx/mgmt/nfd/face-status.hpp> |
Junxiao Shi | 83be1da | 2017-06-30 13:37:37 +0000 | [diff] [blame] | 35 | #include <ndn-cxx/net/face-uri.hpp> |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 36 | #include <ndn-cxx/security/key-chain.hpp> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 37 | |
| 38 | #include <boost/program_options/options_description.hpp> |
| 39 | #include <boost/program_options/variables_map.hpp> |
| 40 | #include <boost/program_options/parsers.hpp> |
| 41 | |
Davide Pesavento | a997d29 | 2017-08-24 20:16:59 -0400 | [diff] [blame^] | 42 | #include <iostream> |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 43 | |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 44 | namespace ndn { |
| 45 | namespace nfd_autoreg { |
| 46 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 47 | using ::nfd::Network; |
| 48 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 49 | class AutoregServer : boost::noncopyable |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 50 | { |
| 51 | public: |
| 52 | AutoregServer() |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame] | 53 | : m_controller(m_face, m_keyChain) |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 54 | , m_faceMonitor(m_face) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 55 | , m_cost(255) |
| 56 | { |
| 57 | } |
| 58 | |
| 59 | void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 60 | onRegisterCommandSuccess(uint64_t faceId, const Name& prefix) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 61 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 62 | std::cerr << "SUCCEED: register " << prefix << " on face " << faceId << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 66 | onRegisterCommandFailure(uint64_t faceId, const Name& prefix, |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 67 | const nfd::ControlResponse& response) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 68 | { |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 69 | std::cerr << "FAILED: register " << prefix << " on face " << faceId |
Junxiao Shi | 29b4128 | 2016-08-22 03:47:02 +0000 | [diff] [blame] | 70 | << " (code: " << response.getCode() << ", reason: " << response.getText() << ")" |
| 71 | << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 74 | /** |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 75 | * \return true if uri has schema allowed to do auto-registrations |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 76 | */ |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 77 | bool |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 78 | hasAllowedSchema(const FaceUri& uri) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 79 | { |
| 80 | const std::string& scheme = uri.getScheme(); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 81 | return (scheme == "udp4" || scheme == "tcp4" || |
| 82 | scheme == "udp6" || scheme == "tcp6"); |
| 83 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 84 | |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 85 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 86 | * \return true if address is blacklisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 87 | */ |
| 88 | bool |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 89 | isBlacklisted(const boost::asio::ip::address& address) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 90 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 91 | return std::any_of(m_blackList.begin(), m_blackList.end(), |
| 92 | bind(&Network::doesContain, _1, address)); |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /** |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 96 | * \return true if address is whitelisted |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 97 | */ |
| 98 | bool |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 99 | isWhitelisted(const boost::asio::ip::address& address) |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 100 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 101 | return std::any_of(m_whiteList.begin(), m_whiteList.end(), |
| 102 | bind(&Network::doesContain, _1, address)); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 106 | registerPrefixesForFace(uint64_t faceId, const std::vector<Name>& prefixes) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 107 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 108 | for (const Name& prefix : prefixes) { |
| 109 | m_controller.start<nfd::RibRegisterCommand>( |
| 110 | nfd::ControlParameters() |
| 111 | .setName(prefix) |
| 112 | .setFaceId(faceId) |
| 113 | .setOrigin(nfd::ROUTE_ORIGIN_AUTOREG) |
| 114 | .setCost(m_cost) |
| 115 | .setExpirationPeriod(time::milliseconds::max()), |
| 116 | bind(&AutoregServer::onRegisterCommandSuccess, this, faceId, prefix), |
| 117 | bind(&AutoregServer::onRegisterCommandFailure, this, faceId, prefix, _1)); |
| 118 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 122 | registerPrefixesIfNeeded(uint64_t faceId, const FaceUri& uri, nfd::FacePersistency facePersistency) |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 123 | { |
| 124 | if (hasAllowedSchema(uri)) { |
| 125 | boost::system::error_code ec; |
| 126 | boost::asio::ip::address address = boost::asio::ip::address::from_string(uri.getHost(), ec); |
| 127 | |
| 128 | if (!address.is_multicast()) { |
| 129 | // register all-face prefixes |
| 130 | registerPrefixesForFace(faceId, m_allFacesPrefixes); |
| 131 | |
| 132 | // register autoreg prefixes if new face is on-demand and not blacklisted and whitelisted |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 133 | if (facePersistency == nfd::FACE_PERSISTENCY_ON_DEMAND && |
Chengyu Fan | 9942cea | 2014-10-13 14:47:13 -0600 | [diff] [blame] | 134 | !isBlacklisted(address) && isWhitelisted(address)) { |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 135 | registerPrefixesForFace(faceId, m_autoregPrefixes); |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | void |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 142 | onNotification(const nfd::FaceEventNotification& notification) |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 143 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 144 | if (notification.getKind() == nfd::FACE_EVENT_CREATED && |
| 145 | notification.getFaceScope() != nfd::FACE_SCOPE_LOCAL) { |
| 146 | std::cerr << "PROCESSING: " << notification << std::endl; |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 147 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 148 | registerPrefixesIfNeeded(notification.getFaceId(), FaceUri(notification.getRemoteUri()), |
| 149 | notification.getFacePersistency()); |
| 150 | } |
| 151 | else { |
| 152 | std::cerr << "IGNORED: " << notification << std::endl; |
| 153 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | void |
| 157 | signalHandler() |
| 158 | { |
| 159 | m_face.shutdown(); |
| 160 | } |
| 161 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 162 | void |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 163 | usage(std::ostream& os, |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 164 | const boost::program_options::options_description& desc, |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 165 | const char* programName) |
| 166 | { |
Alexander Afanasyev | 60a7ba5 | 2014-03-23 11:23:06 -0700 | [diff] [blame] | 167 | os << "Usage:\n" |
| 168 | << " " << programName << " --prefix=</autoreg/prefix> [--prefix=/another/prefix] ...\n" |
| 169 | << "\n"; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 170 | os << desc; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | void |
| 174 | startProcessing() |
| 175 | { |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 176 | std::cerr << "AUTOREG prefixes: " << std::endl; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 177 | for (const Name& prefix : m_autoregPrefixes) { |
| 178 | std::cout << " " << prefix << std::endl; |
| 179 | } |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 180 | std::cerr << "ALL-FACES-AUTOREG prefixes: " << std::endl; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 181 | for (const Name& prefix : m_allFacesPrefixes) { |
| 182 | std::cout << " " << prefix << std::endl; |
| 183 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 184 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 185 | if (!m_blackList.empty()) { |
| 186 | std::cerr << "Blacklisted networks: " << std::endl; |
| 187 | for (const Network& network : m_blackList) { |
| 188 | std::cout << " " << network << std::endl; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 189 | } |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 190 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 191 | |
Junxiao Shi | dda0b46 | 2014-06-30 19:42:29 -0700 | [diff] [blame] | 192 | std::cerr << "Whitelisted networks: " << std::endl; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 193 | for (const Network& network : m_whiteList) { |
| 194 | std::cout << " " << network << std::endl; |
| 195 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 196 | |
Junxiao Shi | fbf7834 | 2015-01-23 14:46:41 -0700 | [diff] [blame] | 197 | m_faceMonitor.onNotification.connect(bind(&AutoregServer::onNotification, this, _1)); |
Junxiao Shi | 15b12e7 | 2014-08-09 19:56:24 -0700 | [diff] [blame] | 198 | m_faceMonitor.start(); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 199 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 200 | boost::asio::signal_set signalSet(m_face.getIoService(), SIGINT, SIGTERM); |
Alexander Afanasyev | f698028 | 2014-05-13 18:28:40 -0700 | [diff] [blame] | 201 | signalSet.async_wait(bind(&AutoregServer::signalHandler, this)); |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 202 | |
| 203 | m_face.processEvents(); |
| 204 | } |
| 205 | |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 206 | void |
| 207 | startFetchingFaceStatusDataset() |
| 208 | { |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 209 | m_controller.fetch<nfd::FaceDataset>( |
| 210 | [this] (const std::vector<nfd::FaceStatus>& faces) { |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 211 | for (const auto& faceStatus : faces) { |
Weiwei Liu | 7c79513 | 2016-10-07 14:22:54 -0700 | [diff] [blame] | 212 | registerPrefixesIfNeeded(faceStatus.getFaceId(), FaceUri(faceStatus.getRemoteUri()), |
| 213 | faceStatus.getFacePersistency()); |
| 214 | } |
| 215 | }, |
| 216 | [this] (uint32_t code, const std::string& reason) {}); |
Alexander Afanasyev | f056c11 | 2014-08-14 16:39:25 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 219 | int |
| 220 | main(int argc, char* argv[]) |
| 221 | { |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 222 | namespace po = boost::program_options; |
| 223 | |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 224 | po::options_description optionDesciption; |
| 225 | optionDesciption.add_options() |
| 226 | ("help,h", "produce help message") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 227 | ("prefix,i", po::value<std::vector<Name>>(&m_autoregPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 228 | "prefix that should be automatically registered when new a remote non-local face is " |
| 229 | "established") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 230 | ("all-faces-prefix,a", po::value<std::vector<Name>>(&m_allFacesPrefixes)->composing(), |
Alexander Afanasyev | 81c1a2a | 2014-08-14 16:07:47 -0700 | [diff] [blame] | 231 | "prefix that should be automatically registered for all TCP and UDP non-local faces " |
| 232 | "(blacklists and whitelists do not apply to this prefix)") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 233 | ("cost,c", po::value<uint64_t>(&m_cost)->default_value(255), |
| 234 | "FIB cost which should be assigned to autoreg nexthops") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 235 | ("whitelist,w", po::value<std::vector<Network>>(&m_whiteList)->composing(), |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 236 | "Whitelisted network, e.g., 192.168.2.0/24 or ::1/128") |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 237 | ("blacklist,b", po::value<std::vector<Network>>(&m_blackList)->composing(), |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 238 | "Blacklisted network, e.g., 192.168.2.32/30 or ::1/128") |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 239 | ("version,V", "show version and exit") |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 240 | ; |
| 241 | |
| 242 | po::variables_map options; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 243 | try { |
| 244 | po::store(po::command_line_parser(argc, argv).options(optionDesciption).run(), options); |
| 245 | po::notify(options); |
| 246 | } |
| 247 | catch (const std::exception& e) { |
| 248 | std::cerr << "ERROR: " << e.what() << std::endl << std::endl; |
| 249 | usage(std::cerr, optionDesciption, argv[0]); |
| 250 | return 1; |
| 251 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 252 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 253 | if (options.count("help")) { |
| 254 | usage(std::cout, optionDesciption, argv[0]); |
| 255 | return 0; |
| 256 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 257 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 258 | if (options.count("version")) { |
| 259 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 260 | return 0; |
| 261 | } |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 262 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 263 | if (m_autoregPrefixes.empty() && m_allFacesPrefixes.empty()) { |
| 264 | std::cerr << "ERROR: at least one --prefix or --all-faces-prefix must be specified" |
| 265 | << std::endl << std::endl; |
| 266 | usage(std::cerr, optionDesciption, argv[0]); |
| 267 | return 2; |
| 268 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 269 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 270 | if (m_whiteList.empty()) { |
| 271 | // Allow everything |
| 272 | m_whiteList.push_back(Network::getMaxRangeV4()); |
| 273 | m_whiteList.push_back(Network::getMaxRangeV6()); |
| 274 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 275 | |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 276 | try { |
| 277 | startFetchingFaceStatusDataset(); |
| 278 | startProcessing(); |
| 279 | } |
| 280 | catch (const std::exception& e) { |
| 281 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 282 | return 2; |
| 283 | } |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | private: |
| 289 | Face m_face; |
Junxiao Shi | 8e273ca | 2014-11-12 00:42:29 -0700 | [diff] [blame] | 290 | KeyChain m_keyChain; |
Junxiao Shi | 08e9631 | 2017-06-29 18:07:27 +0000 | [diff] [blame] | 291 | nfd::Controller m_controller; |
| 292 | nfd::FaceMonitor m_faceMonitor; |
Davide Pesavento | 22db539 | 2017-04-14 00:56:43 -0400 | [diff] [blame] | 293 | std::vector<Name> m_autoregPrefixes; |
| 294 | std::vector<Name> m_allFacesPrefixes; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 295 | uint64_t m_cost; |
| 296 | std::vector<Network> m_whiteList; |
| 297 | std::vector<Network> m_blackList; |
| 298 | }; |
| 299 | |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 300 | } // namespace nfd_autoreg |
| 301 | } // namespace ndn |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 302 | |
| 303 | int |
| 304 | main(int argc, char* argv[]) |
| 305 | { |
Junxiao Shi | a1937bf | 2014-11-06 11:43:40 -0700 | [diff] [blame] | 306 | ndn::nfd_autoreg::AutoregServer server; |
Alexander Afanasyev | 82afa1a | 2014-03-20 16:56:56 -0700 | [diff] [blame] | 307 | return server.main(argc, argv); |
| 308 | } |