blob: 8b8dafc02431ea7f7f4c4320f5ae37683ad59f1b [file] [log] [blame]
Ivan Yeodb0052d2015-02-08 17:27:04 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2015 Regents of the University of California
4 *
5 * This file is part of NFD (Named Data Networking Forwarding Daemon) Android.
6 * See AUTHORS.md for complete list of NFD Android authors and contributors.
7 *
8 * NFD Android is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NFD Android is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NFD Android, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "nfd-wrapper.hpp"
Ivan Yeodb0052d2015-02-08 17:27:04 -080021
Alexander Afanasyev216df012015-02-10 17:35:46 -080022#include "daemon/nfd.hpp"
23#include "rib/nrd.hpp"
Ivan Yeodb0052d2015-02-08 17:27:04 -080024
Alexander Afanasyev216df012015-02-10 17:35:46 -080025#include "core/global-io.hpp"
26#include "core/config-file.hpp"
27#include "core/logger.hpp"
28
29#include <boost/property_tree/info_parser.hpp>
30
31NFD_LOG_INIT("NfdWrapper");
32
33namespace nfd {
34
35class Runner
36{
37public:
38 Runner()
39 {
40 std::string initialConfig =
41 "general\n"
42 "{\n"
43 "}\n"
44 "\n"
45 "log\n"
46 "{\n"
47 " default_level INFO\n"
48 "}\n"
49 "tables\n"
50 "{\n"
51 " cs_max_packets 100\n"
52 "\n"
53 " strategy_choice\n"
54 " {\n"
55 " / /localhost/nfd/strategy/best-route\n"
56 " /localhost /localhost/nfd/strategy/broadcast\n"
57 " /localhost/nfd /localhost/nfd/strategy/best-route\n"
58 " /ndn/broadcast /localhost/nfd/strategy/broadcast\n"
59 " }\n"
60 "}\n"
61 "\n"
62 "face_system\n"
63 "{\n"
64 " tcp\n"
65 " {\n"
66 " port 6363\n"
67 " }\n"
68 "\n"
69 " udp\n"
70 " {\n"
71 " port 6363\n"
72 " idle_timeout 600\n"
73 " keep_alive_interval 25\n"
74 " mcast no\n"
75 " }\n"
76 "}\n"
77 "\n"
78 "authorizations\n"
79 "{\n"
80 " authorize\n"
81 " {\n"
82 " certfile any\n"
83 " privileges\n"
84 " {\n"
85 " faces\n"
86 " fib\n"
87 " strategy-choice\n"
88 " }\n"
89 " }\n"
90 "}\n"
91 "\n"
92 "rib\n"
93 "{\n"
94 " localhost_security\n"
95 " {\n"
96 " trust-anchor\n"
97 " {\n"
98 " type any\n"
99 " }\n"
100 " }\n"
101 "}\n"
102 " remote_register\n"
103 " {\n"
104 " cost 15\n"
105 " timeout 10000\n"
106 " retry 0\n"
107 " refresh_interval 300\n"
108 " }\n"
109 "\n";
110
111 std::istringstream input(initialConfig);
112 boost::property_tree::read_info(input, m_config);
113
114 m_nfd.reset(new Nfd(initialConfig, m_keyChain));
115 m_nrd.reset(new rib::Nrd(initialConfig, m_keyChain));
116
117 m_nfd->initialize();
118 m_nrd->initialize();
119 }
120
121 void
122 run()
123 {
124 }
125
126 void
127 stop()
128 {
129 }
130
131private:
132 ndn::KeyChain m_keyChain;
133 unique_ptr<Nfd> m_nfd; // will use globalIoService
134 unique_ptr<rib::Nrd> m_nrd; // will use globalIoService
135
136 nfd::ConfigSection m_config;
137};
138
139static unique_ptr<Runner> g_runner;
140
141} // namespace nfd
Ivan Yeodb0052d2015-02-08 17:27:04 -0800142
143JNIEXPORT void JNICALL
144Java_net_named_1data_nfd_wrappers_NfdWrapper_startNfd(JNIEnv *, jclass)
145{
Alexander Afanasyev216df012015-02-10 17:35:46 -0800146 if (nfd::g_runner.get() == nullptr) {
147 try {
148 nfd::g_runner.reset(new nfd::Runner());
149 nfd::g_runner.reset();
150 }
151 catch (const std::exception& e) {
152 NFD_LOG_FATAL(e.what());
153 }
154 }
Ivan Yeodb0052d2015-02-08 17:27:04 -0800155
Alexander Afanasyev216df012015-02-10 17:35:46 -0800156 if (nfd::g_runner.get() == nullptr) {
157 return;
158 }
159
160 nfd::g_runner->run();
Ivan Yeodb0052d2015-02-08 17:27:04 -0800161}
162
163JNIEXPORT void JNICALL
164Java_net_named_1data_nfd_wrappers_NfdWrapper_stopNfd(JNIEnv *, jclass)
165{
Alexander Afanasyev216df012015-02-10 17:35:46 -0800166 if (nfd::g_runner.get() == nullptr) {
167 return;
168 }
169 nfd::g_runner->stop();
170 nfd::g_runner.reset();
Ivan Yeodb0052d2015-02-08 17:27:04 -0800171}