hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Alexander Afanasyev | 9bcbc7c | 2014-04-06 19:37:37 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014 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 | * |
| 10 | * This file is part of NFD (Named Data Networking Forwarding Daemon). |
| 11 | * See AUTHORS.md for complete list of NFD authors and contributors. |
| 12 | * |
| 13 | * NFD is free software: you can redistribute it and/or modify it under the terms |
| 14 | * of the GNU General Public License as published by the Free Software Foundation, |
| 15 | * either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 18 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE. See the GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along with |
| 22 | * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 23 | **/ |
Davide Pesavento | 6fc750f | 2014-03-18 19:49:39 +0100 | [diff] [blame] | 24 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 25 | #include "version.hpp" |
| 26 | |
Alexander Afanasyev | 4a77136 | 2014-04-24 21:29:33 -0700 | [diff] [blame] | 27 | #include <ndn-cxx/face.hpp> |
| 28 | #include <ndn-cxx/management/nfd-controller.hpp> |
| 29 | #include <ndn-cxx/security/key-chain.hpp> |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 30 | |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 31 | #include <boost/lexical_cast.hpp> |
| 32 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 33 | #include <sys/types.h> |
| 34 | #include <netinet/in.h> |
| 35 | #include <arpa/nameser.h> |
| 36 | #include <resolv.h> |
| 37 | |
| 38 | #ifdef __APPLE__ |
| 39 | #include <arpa/nameser_compat.h> |
| 40 | #endif |
| 41 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 42 | namespace tools { |
| 43 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 44 | void |
| 45 | usage(const char* programName) |
| 46 | { |
| 47 | std::cout << "Usage:\n" << programName << " [-h] [-V]\n" |
| 48 | << " -h - print usage and exit\n" |
| 49 | << " -V - print version number and exit\n" |
| 50 | << std::endl; |
| 51 | } |
| 52 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 53 | class NdnAutoconfig |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 54 | { |
| 55 | public: |
| 56 | union QueryAnswer |
| 57 | { |
| 58 | HEADER header; |
| 59 | uint8_t buf[NS_PACKETSZ]; |
| 60 | }; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 61 | |
| 62 | class Error : public std::runtime_error |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 63 | { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 64 | public: |
| 65 | explicit |
| 66 | Error(const std::string& what) |
| 67 | : std::runtime_error(what) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 68 | { |
| 69 | } |
| 70 | }; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 71 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 72 | explicit |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 73 | NdnAutoconfig() |
| 74 | : m_controller(m_face) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 75 | { |
| 76 | } |
Davide Pesavento | 6fc750f | 2014-03-18 19:49:39 +0100 | [diff] [blame] | 77 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 78 | // Start to look for a hub (NDN hub discovery first stage) |
| 79 | void |
| 80 | discoverHubStage1() |
| 81 | { |
| 82 | ndn::Interest interest(ndn::Name("/localhop/ndn-autoconf/hub")); |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 83 | interest.setInterestLifetime(ndn::time::milliseconds(4000)); // 4 seconds |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 84 | interest.setMustBeFresh(true); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 85 | |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 86 | std::cerr << "Stage 1: Trying multicast discovery..." << std::endl; |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 87 | m_face.expressInterest(interest, |
| 88 | ndn::bind(&NdnAutoconfig::onDiscoverHubStage1Success, this, _1, _2), |
| 89 | ndn::bind(&NdnAutoconfig::discoverHubStage2, this, _1, "Timeout")); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 90 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 91 | m_face.processEvents(); |
| 92 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 93 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 94 | // First stage OnData Callback |
| 95 | void |
| 96 | onDiscoverHubStage1Success(const ndn::Interest& interest, ndn::Data& data) |
| 97 | { |
| 98 | const ndn::Block& content = data.getContent(); |
| 99 | content.parse(); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 100 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 101 | // Get Uri |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 102 | ndn::Block::element_const_iterator blockValue = content.find(ndn::tlv::nfd::Uri); |
| 103 | if (blockValue == content.elements_end()) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 104 | { |
| 105 | discoverHubStage2(interest, "Incorrect reply to stage1"); |
| 106 | return; |
| 107 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 108 | std::string faceMgmtUri(reinterpret_cast<const char*>(blockValue->value()), |
| 109 | blockValue->value_size()); |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 110 | connectToHub(faceMgmtUri); |
| 111 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 112 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 113 | // First stage OnTimeout callback - start 2nd stage |
| 114 | void |
| 115 | discoverHubStage2(const ndn::Interest& interest, const std::string& message) |
| 116 | { |
| 117 | std::cerr << message << std::endl; |
| 118 | std::cerr << "Stage 2: Trying DNS query with default suffix..." << std::endl; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 119 | |
| 120 | _res.retry = 2; |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 121 | _res.ndots = 10; |
| 122 | |
| 123 | QueryAnswer queryAnswer; |
| 124 | |
| 125 | int answerSize = res_search("_ndn._udp", |
| 126 | ns_c_in, |
| 127 | ns_t_srv, |
| 128 | queryAnswer.buf, |
| 129 | sizeof(queryAnswer)); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 130 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 131 | // 2nd stage failed - move on to the third stage |
| 132 | if (answerSize < 0) |
| 133 | { |
| 134 | discoverHubStage3("Failed to find NDN router using default suffix DNS query"); |
| 135 | } |
| 136 | else |
| 137 | { |
| 138 | bool isParsed = parseHostAndConnectToHub(queryAnswer, answerSize); |
| 139 | if (isParsed == false) |
| 140 | { |
| 141 | // Failed to parse DNS response, try stage 3 |
| 142 | discoverHubStage3("Failed to parse DNS response"); |
| 143 | } |
| 144 | } |
| 145 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 146 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 147 | // Second stage OnTimeout callback |
| 148 | void |
| 149 | discoverHubStage3(const std::string& message) |
| 150 | { |
| 151 | std::cerr << message << std::endl; |
| 152 | std::cerr << "Stage 3: Trying to find home router..." << std::endl; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 153 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 154 | ndn::KeyChain keyChain; |
| 155 | ndn::Name identity = keyChain.getDefaultIdentity(); |
| 156 | std::string serverName = "_ndn._udp."; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 157 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 158 | for (ndn::Name::const_reverse_iterator i = identity.rbegin(); i != identity.rend(); i++) |
| 159 | { |
Alexander Afanasyev | b3893c9 | 2014-05-15 01:49:54 -0700 | [diff] [blame] | 160 | serverName.append(i->toUri()); |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 161 | serverName.append("."); |
| 162 | } |
| 163 | serverName += "_homehub._autoconf.named-data.net"; |
| 164 | std::cerr << "Stage3: About to query for a home router: " << serverName << std::endl; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 165 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 166 | QueryAnswer queryAnswer; |
| 167 | |
| 168 | int answerSize = res_query(serverName.c_str(), |
| 169 | ns_c_in, |
| 170 | ns_t_srv, |
| 171 | queryAnswer.buf, |
| 172 | sizeof(queryAnswer)); |
| 173 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 174 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 175 | // 3rd stage failed - abort |
| 176 | if (answerSize < 0) |
| 177 | { |
| 178 | std::cerr << "Failed to find a home router" << std::endl; |
| 179 | std::cerr << "exit" << std::endl; |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | bool isParsed = parseHostAndConnectToHub(queryAnswer, answerSize); |
| 184 | if (isParsed == false) |
| 185 | { |
| 186 | // Failed to parse DNS response |
| 187 | throw Error("Failed to parse DNS response"); |
| 188 | } |
| 189 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 190 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 191 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 192 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 193 | void |
| 194 | connectToHub(const std::string& uri) |
| 195 | { |
| 196 | std::cerr << "about to connect to: " << uri << std::endl; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 197 | |
| 198 | m_controller.start<ndn::nfd::FaceCreateCommand>( |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 199 | ndn::nfd::ControlParameters() |
| 200 | .setUri(uri), |
| 201 | bind(&NdnAutoconfig::onHubConnectSuccess, this, _1), |
| 202 | bind(&NdnAutoconfig::onHubConnectError, this, _1, _2) |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 203 | ); |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 204 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 205 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 206 | void |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 207 | onHubConnectSuccess(const ndn::nfd::ControlParameters& resp) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 208 | { |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 209 | std::cerr << "Successfully created face: " << resp << std::endl; |
hilata | f4f8673 | 2014-05-03 19:06:34 -0500 | [diff] [blame] | 210 | |
| 211 | // Register a prefix in RIB |
| 212 | ndn::nfd::ControlParameters ribParameters; |
| 213 | ribParameters |
| 214 | .setName("/ndn") |
| 215 | .setFaceId(resp.getFaceId()); |
| 216 | |
| 217 | m_controller.start<ndn::nfd::RibRegisterCommand>( |
| 218 | ribParameters, |
| 219 | bind(&NdnAutoconfig::onPrefixRegistrationSuccess, this, _1), |
| 220 | bind(&NdnAutoconfig::onPrefixRegistrationError, this, _1, _2)); |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 221 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 222 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 223 | void |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 224 | onHubConnectError(uint32_t code, const std::string& error) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 225 | { |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 226 | std::ostringstream os; |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 227 | os << "Failed to create face: " << error << " (code: " << code << ")"; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 228 | throw Error(os.str()); |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 229 | } |
| 230 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 231 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 232 | bool parseHostAndConnectToHub(QueryAnswer& queryAnswer, int answerSize) |
| 233 | { |
| 234 | // The references of the next classes are: |
| 235 | // http://www.diablotin.com/librairie/networking/dnsbind/ch14_02.htm |
| 236 | // https://gist.github.com/mologie/6027597 |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 237 | |
| 238 | struct rechdr |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 239 | { |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 240 | uint16_t type; |
| 241 | uint16_t iclass; |
| 242 | uint32_t ttl; |
| 243 | uint16_t length; |
| 244 | }; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 245 | |
| 246 | struct srv_t |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 247 | { |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 248 | uint16_t priority; |
| 249 | uint16_t weight; |
| 250 | uint16_t port; |
| 251 | uint8_t* target; |
| 252 | }; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 253 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 254 | if (ntohs(queryAnswer.header.ancount) == 0) |
| 255 | { |
| 256 | std::cerr << "No records found\n" << std::endl; |
| 257 | return false; |
| 258 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 259 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 260 | uint8_t* blob = queryAnswer.buf + NS_HFIXEDSZ; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 261 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 262 | blob += dn_skipname(blob, queryAnswer.buf + answerSize) + NS_QFIXEDSZ; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 263 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 264 | for (int i = 0; i < ntohs(queryAnswer.header.ancount); i++) |
| 265 | { |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 266 | char srvName[NS_MAXDNAME]; |
| 267 | int serverNameSize = dn_expand(queryAnswer.buf, // message pointer |
| 268 | queryAnswer.buf + answerSize, // end of message |
| 269 | blob, // compressed server name |
| 270 | srvName, // expanded server name |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 271 | NS_MAXDNAME); |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 272 | if (serverNameSize < 0) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 273 | { |
| 274 | return false; |
| 275 | } |
Davide Pesavento | 6fc750f | 2014-03-18 19:49:39 +0100 | [diff] [blame] | 276 | |
| 277 | srv_t* server = reinterpret_cast<srv_t*>(&blob[sizeof(rechdr)]); |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 278 | uint16_t convertedPort = be16toh(server->port); |
hilata | 3a4eb5c | 2014-04-29 00:32:05 -0500 | [diff] [blame] | 279 | |
| 280 | blob += serverNameSize + NS_HFIXEDSZ + NS_QFIXEDSZ; |
| 281 | |
| 282 | char hostName[NS_MAXDNAME]; |
| 283 | int hostNameSize = dn_expand(queryAnswer.buf, // message pointer |
| 284 | queryAnswer.buf + answerSize, // end of message |
| 285 | blob, // compressed host name |
| 286 | hostName, // expanded host name |
| 287 | NS_MAXDNAME); |
| 288 | if (hostNameSize < 0) |
| 289 | { |
| 290 | return false; |
| 291 | } |
| 292 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 293 | std::string uri = "udp://"; |
| 294 | uri.append(hostName); |
| 295 | uri.append(":"); |
| 296 | uri.append(boost::lexical_cast<std::string>(convertedPort)); |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 297 | |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 298 | connectToHub(uri); |
| 299 | return true; |
| 300 | } |
Alexander Afanasyev | eb3197f | 2014-03-17 19:28:18 -0700 | [diff] [blame] | 301 | |
| 302 | return false; |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 303 | } |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 304 | |
hilata | f4f8673 | 2014-05-03 19:06:34 -0500 | [diff] [blame] | 305 | void |
| 306 | onPrefixRegistrationSuccess(const ndn::nfd::ControlParameters& commandSuccessResult) |
| 307 | { |
| 308 | std::cerr << "Successful in name registration: " << commandSuccessResult << std::endl; |
| 309 | } |
| 310 | |
| 311 | void |
| 312 | onPrefixRegistrationError(uint32_t code, const std::string& error) |
| 313 | { |
| 314 | std::ostringstream os; |
| 315 | os << "Failed in name registration, " << error << " (code: " << code << ")"; |
| 316 | throw Error(os.str()); |
| 317 | } |
| 318 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 319 | private: |
| 320 | ndn::Face m_face; |
| 321 | ndn::nfd::Controller m_controller; |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 322 | }; |
| 323 | |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 324 | } // namespace tools |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 325 | |
| 326 | int |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 327 | main(int argc, char** argv) |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 328 | { |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 329 | int opt; |
| 330 | const char* programName = argv[0]; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 331 | |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 332 | while ((opt = getopt(argc, argv, "hV")) != -1) { |
| 333 | switch (opt) { |
| 334 | case 'h': |
| 335 | tools::usage(programName); |
| 336 | return 0; |
| 337 | case 'V': |
| 338 | std::cout << NFD_VERSION_BUILD_STRING << std::endl; |
| 339 | return 0; |
Alexander Afanasyev | 352e14e | 2014-03-27 16:02:12 -0700 | [diff] [blame] | 340 | } |
Alexander Afanasyev | b47d538 | 2014-05-05 14:35:03 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | try { |
| 344 | tools::NdnAutoconfig autoConfigInstance; |
| 345 | |
| 346 | autoConfigInstance.discoverHubStage1(); |
| 347 | } |
| 348 | catch (const std::exception& error) { |
| 349 | std::cerr << "ERROR: " << error.what() << std::endl; |
| 350 | return 1; |
| 351 | } |
hilata | dd50ada | 2014-03-13 12:48:47 -0500 | [diff] [blame] | 352 | return 0; |
| 353 | } |