forked from Zhiyi-Zhang/NDND
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnd-server.cpp
83 lines (70 loc) · 1.42 KB
/
nd-server.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// AUTHOR: Zhiyi Zhang
// EMAIL: zhiyi@cs.ucla.edu
// License: LGPL v3.0
#include "server-daemon.hpp"
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/parsers.hpp>
#include <iostream>
namespace po = boost::program_options;
static void
usage(std::ostream& os, const po::options_description& options)
{
os << "Usage: Named Data Neighbor Discovery (NDND) Server\n"
"\n"
<< options;
}
class Options
{
public:
Options()
: prefix("/ndn/nd")
{
}
public:
ndn::Name prefix;
};
namespace ndn {
namespace ndnd {
class Program
{
public:
explicit
Program(const Options& options)
: m_options(options)
, server()
{
}
void
run()
{
server.registerPrefix(m_options.prefix);
server.run();
}
private:
const Options m_options;
NDServer server;
};
} // namespace ndnd
} // namespace ndn
int
main(int argc, char** argv)
{
Options opt;
po::options_description options("Required options");
options.add_options()
("help,h", "print help message")
("prefix,P", po::value<ndn::Name>(&opt.prefix), "prefix to register");
po::variables_map vm;
try {
po::store(po::parse_command_line(argc, argv, options), vm);
po::notify(vm);
}
catch (boost::program_options::error&) {
usage(std::cerr, options);
return 2;
}
ndn::ndnd::Program program(opt);
program.run();
return 1;
}