37 #ifdef __DEVELOPMENT_ASSERTIONS__
41 using namespace dtn::net;
42 using namespace dtn::core;
43 using namespace dtn::utils;
44 using namespace ibrcommon;
50 Configuration::NetConfig::NetConfig(std::string n,
NetType t,
const std::string &u)
51 : name(n), type(t), url(u), mtu(0), port(0)
56 : name(n), type(t), iface(i), mtu(1500), port(p)
61 : name(n), type(t), iface(), mtu(1500), port(p)
80 Configuration::Configuration()
81 : _filename(
"config.ini"), _doapi(true)
85 Configuration::~Configuration()
89 : _enabled(true), _timeout(5), _crosslayer(false) {}
92 : _enabled(false), _quiet(false), _level(0) {}
95 : _quiet(false), _options(0), _timestamps(false), _verbose(false) {}
98 : _routing(
"default"), _forwarding(true), _tcp_nodelay(true), _tcp_chunksize(4096), _tcp_idle_timeout(0), _default_net(
"lo"), _use_default_net(false), _auto_connect(0), _fragmentation(false), _scheduling(false)
102 : _enabled(false), _tlsEnabled(false), _tlsRequired(false), _tlsOptionalOnBadClock(false), _level(SECURITY_LEVEL_NONE), _disableEncryption(false)
106 : _daemonize(false), _kill(false), _threads(0)
110 : _reference(true), _sync(false), _discovery(false), _sigma(1.001f), _psi(0.8f), _sync_level(0.10f)
114 : _enabled(true), _port(0), _dnsbootstrapping(true), _ipv4(true), _ipv6(true), _blacklist(true), _selfannounce(true),
115 _minRating(1), _allowNeighbourToAnnounceMe(true), _allowNeighbourAnnouncement(true),
116 _ignoreDHTNeighbourInformations(false)
120 : _ctrl_path(
""), _enabled(false)
201 static struct option long_options[] =
204 {
"noapi", no_argument, &doapi, 0},
205 {
"nodiscovery", no_argument, &disco, 0},
206 {
"badclock", no_argument, &badclock, 1},
207 {
"timestamp", no_argument, ×tamp, 1},
208 {
"version", no_argument, &showversion, 1},
211 {
"help", no_argument, 0,
'h'},
212 #ifdef HAVE_LIBDAEMON
213 {
"daemon", no_argument, 0,
'D'},
214 {
"kill", no_argument, 0,
'k'},
215 {
"pidfile", required_argument, 0,
'p'},
218 {
"quiet", no_argument, 0,
'q'},
219 {
"interface", required_argument, 0,
'i'},
220 {
"configuration", required_argument, 0,
'c'},
221 {
"debug", required_argument, 0,
'd'},
226 int option_index = 0;
228 #ifdef HAVE_LIBDAEMON
229 c = getopt_long (argc, argv,
"qhDkp:vi:c:d:t:",
230 long_options, &option_index);
232 c = getopt_long (argc, argv,
"qhvi:c:d:t:",
233 long_options, &option_index);
244 if (long_options[option_index].flag != 0)
246 printf (
"option %s", long_options[option_index].name);
248 printf (
" with arg %s", optarg);
253 std::cout <<
"IBR-DTN version: " <<
version() << std::endl;
254 std::cout <<
"Syntax: dtnd [options]" << std::endl;
255 std::cout <<
" -h|--help display this text" << std::endl;
256 std::cout <<
" -c <file> set a configuration file" << std::endl;
257 #ifdef HAVE_LIBDAEMON
258 std::cout <<
" -D daemonize the process" << std::endl;
259 std::cout <<
" -k stop the running daemon" << std::endl;
260 std::cout <<
" -p <file> store the pid in this pidfile" << std::endl;
262 std::cout <<
" -i <interface> interface to bind on (e.g. eth0)" << std::endl;
263 std::cout <<
" -d <level> enable debugging and set a verbose level" << std::endl;
264 std::cout <<
" -q enables the quiet mode (no logging to the console)" << std::endl;
265 std::cout <<
" -t <threads> specify a number of threads for parallel event processing" << std::endl;
266 std::cout <<
" -v be verbose - show NOTICE log messages" << std::endl;
267 std::cout <<
" --version show version and exit" << std::endl;
268 std::cout <<
" --noapi disable API module" << std::endl;
269 std::cout <<
" --nodiscovery disable discovery module" << std::endl;
270 std::cout <<
" --badclock assume a bad clock on the system (use AgeBlock)" << std::endl;
271 std::cout <<
" --timestamp enables timestamps for logging instead of datetime values" << std::endl;
294 _debug._level = atoi(optarg);
298 _daemon._daemonize =
true;
303 _daemon._daemonize =
true;
304 _daemon._kill =
true;
308 _daemon._pidfile = std::string(optarg);
312 _daemon._threads = atoi(optarg);
325 if (showversion == 1) {
326 std::cout <<
"IBR-DTN version: " <<
version() << std::endl;
346 _filename = filename;
354 _conf.
add<std::string>(
"user",
"nobody");
361 _network.
load(_conf);
362 _security.
load(_conf);
363 _timesync.
load(_conf);
370 _timeout = conf.
read<
unsigned int>(
"discovery_timeout", 5);
371 _crosslayer = (conf.
read<std::string>(
"discovery_crosslayer",
"no") ==
"yes");
377 _logfile = conf.
read<std::string>(
"logfile");
393 _reference = (conf.
read<std::string>(
"time_reference") ==
"yes");
397 _sync = (conf.
read<std::string>(
"time_synchronize") ==
"yes");
401 _discovery = (conf.
read<std::string>(
"time_discovery_announcements") ==
"yes");
404 _sigma = conf.
read<
float>(
"time_sigma", 1.001f);
405 _psi = conf.
read<
float>(
"time_psi", 0.9f);
406 _sync_level = conf.
read<
float>(
"time_sync_level", 0.15f);
414 _enabled = (conf.
read<std::string> (
"dht_enabled",
"no") ==
"yes");
415 _port = conf.
read<
int> (
"dht_port", 9999);
416 _id = conf.
read<
string> (
"dht_id",
"");
417 _blacklist = (conf.
read<std::string> (
"dht_blacklist",
"yes") ==
"yes");
418 _selfannounce = (conf.
read<std::string> (
"dht_self_announce",
"yes") ==
"yes");
419 _dnsbootstrapping = (conf.
read<std::string> (
"dht_bootstrapping",
"yes") ==
"yes");
420 string list = conf.
read<
string> (
"dht_bootstrapping_domains",
"");
422 list = conf.
read<
string> (
"dht_bootstrapping_ips",
"");
424 _ipv4bind = conf.
read<
string> (
"dht_bind_ipv4",
"");
425 _ipv6bind = conf.
read<
string> (
"dht_bind_ipv6",
"");
426 _nodesFilePath = conf.
read<
string> (
"dht_nodes_file",
"");
427 _ipv4 = (conf.
read<std::string> (
"dht_enable_ipv4",
"yes") ==
"yes");
428 _ipv6 = (conf.
read<std::string> (
"dht_enable_ipv6",
"yes") ==
"yes");
429 _minRating = conf.
read<
int> (
"dht_min_rating", 1);
430 _allowNeighbourToAnnounceMe = (conf.
read<std::string> (
"dht_allow_neighbours_to_announce_me",
"yes") ==
"yes");
431 _allowNeighbourAnnouncement = (conf.
read<std::string> (
"dht_allow_neighbour_announcement",
"yes") ==
"yes");
432 _ignoreDHTNeighbourInformations = (conf.
read<std::string> (
"dht_ignore_neighbour_informations",
"no") ==
"yes");
434 if (_minRating < 0) _minRating = 0;
440 _ctrl_path = conf.
read<std::string>(
"p2p_ctrlpath");
466 return _conf.
read<
string>(
"local_uri");
468 std::vector<char> hostname_array(64);
469 if ( gethostname(&hostname_array[0], hostname_array.size()) != 0 )
475 return "dtn://" + std::string(&hostname_array[0]);
487 std::set<ibrcommon::vaddress> ret;
493 for (std::vector<std::string>::iterator iter = addresses.begin(); iter != addresses.end(); ++iter) {
497 throw ParameterNotFoundException();
520 int port = _conf.
read<
int>(
"api_port", 4550);
523 std::string interface_name = _conf.
read<std::string>(
"api_interface");
525 if (interface_name ==
"any")
549 return _conf.
read<std::string>(
"storage",
"default");
553 return (_conf.
read<std::string>(
"stats_traffic",
"no") ==
"yes");
561 _static_routes.clear();
563 string key =
"route1";
564 unsigned int keynumber = 1;
569 _static_routes.insert( pair<std::string, std::string>( route.front(), route.back() ) );
572 stringstream ss; ss <<
"route" << keynumber; ss >> key;
582 std::string prefix =
"static1_";
589 std::stringstream ss;
590 ss <<
"ip=" << conf.
read<std::string>(prefix +
"address",
"127.0.0.1") <<
";port=" << conf.
read<
unsigned int>(prefix +
"port", 4556) <<
";";
594 const std::string protocol = conf.
read<std::string>(prefix +
"proto",
"tcp");
595 if (protocol ==
"tcp") p = Node::CONN_TCPIP;
596 if (protocol ==
"udp") p = Node::CONN_UDPIP;
597 if (protocol ==
"lowpan") p = Node::CONN_LOWPAN;
598 if (protocol ==
"zigbee") p = Node::CONN_LOWPAN;
599 if (protocol ==
"bluetooth") p = Node::CONN_BLUETOOTH;
600 if (protocol ==
"http") p = Node::CONN_HTTP;
601 if (protocol ==
"file") p = Node::CONN_FILE;
602 if (protocol ==
"dgram:udp") p = Node::CONN_DGRAM_UDP;
603 if (protocol ==
"dgram:ethernet") p = Node::CONN_DGRAM_ETHERNET;
604 if (protocol ==
"dgram:lowpan") p = Node::CONN_DGRAM_LOWPAN;
606 bool node_exists =
false;
612 for (std::list<Node>::iterator iter = _nodes.begin(); iter != _nodes.end(); ++iter)
616 if (n.
getEID() == node_eid)
635 std::stringstream prefix_stream;
636 prefix_stream <<
"static" << count <<
"_";
637 prefix = prefix_stream.str();
643 _routing = conf.
read<
string>(
"routing",
"default");
645 if(_routing ==
"prophet"){
647 _prophet_config.p_encounter_max = conf.
read<
float>(
"prophet_p_encounter_max", 0.7f);
648 if(_prophet_config.p_encounter_max > 1 || _prophet_config.p_encounter_max <= 0)
649 _prophet_config.p_encounter_max = 0.7f;
650 _prophet_config.p_encounter_first = conf.
read<
float>(
"prophet_p_encounter_first", 0.5f);
651 if(_prophet_config.p_encounter_first > 1 || _prophet_config.p_encounter_first <= 0)
652 _prophet_config.p_encounter_first = 0.5f;
653 _prophet_config.p_first_threshold = conf.
read<
float>(
"prophet_p_first_threshold", 0.1f);
654 if(_prophet_config.p_first_threshold < 0 || _prophet_config.p_first_threshold >= _prophet_config.p_encounter_first)
655 _prophet_config.p_first_threshold = 0;
656 _prophet_config.beta = conf.
read<
float>(
"prophet_beta", 0.9f);
657 if(_prophet_config.beta < 0 || _prophet_config.beta > 1)
658 _prophet_config.beta = 0.9f;
659 _prophet_config.gamma = conf.
read<
float>(
"prophet_gamma", 0.999f);
660 if(_prophet_config.gamma <= 0 || _prophet_config.gamma > 1)
661 _prophet_config.gamma = 0.999f;
662 _prophet_config.delta = conf.
read<
float>(
"prophet_delta", 0.01f);
663 if(_prophet_config.delta < 0 || _prophet_config.delta > 1)
664 _prophet_config.delta = 0.01f;
666 if(_prophet_config.time_unit < 1)
667 _prophet_config.time_unit = 1;
669 if(_prophet_config.i_typ < 1)
670 _prophet_config.i_typ = 1;
672 _prophet_config.forwarding_strategy = conf.
read<std::string>(
"prophet_forwarding_strategy",
"GRTR");
673 _prophet_config.gtmx_nf_max = conf.
read<
unsigned int>(
"prophet_gtmx_nf_max", 30);
679 _forwarding = (conf.
read<std::string>(
"routing_forwarding",
"yes") ==
"yes");
686 if (_use_default_net)
693 for (vector<string>::const_iterator iter = nets.begin(); iter != nets.end(); ++iter)
695 std::string netname = (*iter);
697 std::string key_type =
"net_" + netname +
"_type";
698 std::string key_port =
"net_" + netname +
"_port";
699 std::string key_interface =
"net_" + netname +
"_interface";
700 std::string key_address =
"net_" + netname +
"_address";
701 std::string key_path =
"net_" + netname +
"_path";
702 std::string key_mtu =
"net_" + netname +
"_mtu";
704 std::string type_name = conf.
read<
string>(key_type,
"tcp");
721 conf.
read<std::string>(key_address,
"http://localhost/"));
723 _interfaces.push_back(nc);
730 conf.
read<std::string>(key_path,
""));
732 _interfaces.push_back(nc);
738 int port = conf.
read<
int>(key_port, 4556);
739 int mtu = conf.
read<
int>(key_mtu, 1280);
745 _interfaces.push_back(nc);
749 _interfaces.push_back(nc);
763 _tcp_nodelay = (conf.
read<std::string>(
"tcp_nodelay",
"yes") ==
"yes");
764 _tcp_chunksize = conf.
read<
unsigned int>(
"tcp_chunksize", 4096);
765 _tcp_idle_timeout = conf.
read<
unsigned int>(
"tcp_idle_timeout", 0);
775 _fragmentation = (conf.
read<std::string>(
"fragmentation",
"no") ==
"yes");
782 for (std::vector<string>::const_iterator iter = inets.begin(); iter != inets.end(); ++iter)
785 _internet_devices.insert(inet_dev);
792 _scheduling = (conf.
read<std::string>(
"scheduling",
"no") ==
"yes");
797 return _static_routes;
807 return _conf.
read<
int>(
"timezone", 0 );
813 ss << name <<
"_path";
814 string key; ss >> key;
865 return _fragmentation;
880 return _tcp_chunksize;
885 return _tcp_idle_timeout;
890 return _auto_connect;
895 return _prophet_config;
900 return _internet_devices;
905 std::string unparsed = _conf.
read<std::string>(
"limit_" + suffix,
"0");
907 std::stringstream ss(unparsed);
909 float value; ss >> value;
910 char multiplier = 0; ss >> multiplier;
936 bool withTLS =
false;
940 bool activateTLS =
true;
944 _cert = conf.
read<std::string>(
"security_certificate");
957 _key = conf.
read<std::string>(
"security_key");
970 _trustedCAPath = conf.
read<std::string>(
"security_trusted_ca_path");
971 if(!_trustedCAPath.isDirectory()){
980 _disableEncryption = (conf.
read<std::string>(
"security_tls_disable_encryption",
"no") ==
"yes");
987 _tlsRequired = (conf.
read<std::string>(
"security_tls_required",
"no") ==
"yes");
990 _tlsOptionalOnBadClock = (conf.
read<std::string>(
"security_tls_fallback_badclock",
"no") ==
"yes");
994 #ifdef WITH_BUNDLE_SECURITY
997 _path = conf.
read<std::string>(
"security_path");
1010 _level =
Level(conf.
read<
int>(
"security_level", 0));
1017 _cert = conf.
read<std::string>(
"security_certificate");
1019 if (!_cert.exists())
1027 _key = conf.
read<std::string>(
"security_key");
1038 _bab_default_key = conf.
read<std::string>(
"security_bab_default_key");
1040 if (!_bab_default_key.exists())
1065 return _tlsRequired;
1080 return _bab_default_key;
1095 return _trustedCAPath;
1100 return _disableEncryption;
1212 return _dnsbootstrapping;
1217 return _bootstrappingdomains;
1222 return !_bootstrappingips.empty();
1227 return _bootstrappingips;
1241 return _nodesFilePath;
1256 return _selfannounce;
1266 return _allowNeighbourAnnouncement;
1271 return _allowNeighbourToAnnounceMe;
1281 return _ignoreDHTNeighbourInformations;