44 #ifdef __DEVELOPMENT_ASSERTIONS__
48 using namespace dtn::net;
49 using namespace dtn::core;
50 using namespace dtn::utils;
51 using namespace ibrcommon;
57 Configuration::NetConfig::NetConfig(
const std::string &n,
NetType t)
58 : name(n), type(t), iface(ibrcommon::
vinterface::ANY), mtu(0), port(0)
77 Configuration::Configuration()
78 : _filename(
"config.ini"), _doapi(true)
82 Configuration::~Configuration()
86 : _enabled(true), _timeout(5), _crosslayer(false) {}
89 : _enabled(false), _quiet(false), _level(0) {}
92 : _quiet(false), _options(0), _timestamps(false), _verbose(false) {}
95 : _routing(
"default"), _forwarding(true), _prefer_direct(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), _link_request_interval(5000)
99 : _enabled(false), _tlsEnabled(false), _tlsRequired(false), _tlsOptionalOnBadClock(false), _level(SECURITY_LEVEL_NONE), _disableEncryption(false)
103 : _daemonize(false), _kill(false), _threads(0)
107 : _reference(true), _sync(false), _discovery(false), _sigma(1.001f), _psi(0.8f), _sync_level(0.10f)
111 : _enabled(true), _port(0), _dnsbootstrapping(true), _ipv4(true), _ipv6(true), _blacklist(true), _selfannounce(true),
112 _minRating(1), _allowNeighbourToAnnounceMe(true), _allowNeighbourAnnouncement(true),
113 _ignoreDHTNeighbourInformations(false)
117 : _ctrl_path(
""), _enabled(false)
121 : _smtpPort(25), _smtpUseTLS(false), _smtpUseSSL(false), _smtpNeedAuth(false), _smtpInterval(60), _smtpConnectionTimeout(-1), _smtpKeepAliveTimeout(30),
122 _imapPort(143), _imapUseTLS(false), _imapUseSSL(false), _imapInterval(60), _imapConnectionTimeout(-1), _imapPurgeMail(false),
123 _availableTime(1800), _returningMailsCheck(3)
209 static struct option long_options[] =
212 {
"noapi", no_argument, &doapi, 0},
213 {
"nodiscovery", no_argument, &disco, 0},
214 {
"timestamp", no_argument, ×tamp, 1},
215 {
"version", no_argument, &showversion, 1},
218 {
"help", no_argument, 0,
'h'},
219 #ifdef HAVE_LIBDAEMON
220 {
"daemon", no_argument, 0,
'D'},
221 {
"kill", no_argument, 0,
'k'},
222 {
"pidfile", required_argument, 0,
'p'},
225 {
"quiet", no_argument, 0,
'q'},
226 {
"interface", required_argument, 0,
'i'},
227 {
"configuration", required_argument, 0,
'c'},
228 {
"debug", required_argument, 0,
'd'},
230 {
"interfaces", no_argument, 0,
'I'},
236 int option_index = 0;
238 #ifdef HAVE_LIBDAEMON
239 c = getopt_long (argc, argv,
"qhDkp:vi:c:d:t:",
240 long_options, &option_index);
242 c = getopt_long (argc, argv,
"qhvi:c:d:t:",
243 long_options, &option_index);
254 if (long_options[option_index].flag != 0)
256 printf (
"option %s", long_options[option_index].name);
258 printf (
" with arg %s", optarg);
263 std::cout <<
"IBR-DTN version: " <<
version() << std::endl;
264 std::cout <<
"Syntax: dtnd [options]" << std::endl;
265 std::cout <<
" -h|--help display this text" << std::endl;
266 std::cout <<
" -c <file> set a configuration file" << std::endl;
267 #ifdef HAVE_LIBDAEMON
268 std::cout <<
" -D daemonize the process" << std::endl;
269 std::cout <<
" -k stop the running daemon" << std::endl;
270 std::cout <<
" -p <file> store the pid in this pidfile" << std::endl;
272 std::cout <<
" -i <interface> interface to bind on (e.g. eth0)" << std::endl;
273 std::cout <<
" -d <level> enable debugging and set a verbose level" << std::endl;
274 std::cout <<
" -q enables the quiet mode (no logging to the console)" << std::endl;
275 std::cout <<
" -t <threads> specify a number of threads for parallel event processing" << std::endl;
276 std::cout <<
" -v be verbose - show NOTICE log messages" << std::endl;
277 std::cout <<
" --version show version and exit" << std::endl;
278 std::cout <<
" --noapi disable API module" << std::endl;
279 std::cout <<
" --nodiscovery disable discovery module" << std::endl;
280 std::cout <<
" --timestamp enables timestamps for logging instead of datetime values" << std::endl;
282 std::cout <<
" --interfaces list all available interfaces" << std::endl;
306 _debug._level = atoi(optarg);
310 _daemon._daemonize =
true;
315 _daemon._daemonize =
true;
316 _daemon._kill =
true;
320 _daemon._pidfile = std::string(optarg);
324 _daemon._threads = atoi(optarg);
336 std::cout <<
"Available interfaces:" << std::endl;
338 for (std::set<ibrcommon::vinterface>::const_iterator it = ifs.begin(); it != ifs.end(); ++it)
341 std::cout << iface.
toString() <<
'\t';
342 std::wcout << iface.getFriendlyName() << std::endl;
344 }
catch (
const std::bad_cast&) {
361 if (showversion == 1) {
362 std::cout <<
"IBR-DTN version: " <<
version() << std::endl;
373 load(_filename, quiet);
381 _filename = filename;
389 _conf.
add<std::string>(
"user",
"nobody");
396 _network.
load(_conf);
397 _security.
load(_conf);
398 _timesync.
load(_conf);
406 _timeout = conf.
read<
unsigned int>(
"discovery_timeout", 5);
407 _crosslayer = (conf.
read<std::string>(
"discovery_crosslayer",
"no") ==
"yes");
413 _logfile = conf.
read<std::string>(
"logfile");
429 _reference = (conf.
read<std::string>(
"time_reference") ==
"yes");
433 _sync = (conf.
read<std::string>(
"time_synchronize") ==
"yes");
437 _discovery = (conf.
read<std::string>(
"time_discovery_announcements") ==
"yes");
440 _sigma = conf.
read<
float>(
"time_sigma", 1.001f);
441 _psi = conf.
read<
float>(
"time_psi", 0.9f);
442 _sync_level = conf.
read<
float>(
"time_sync_level", 0.15f);
450 _enabled = (conf.
read<std::string> (
"dht_enabled",
"no") ==
"yes");
451 _port = conf.
read<
int> (
"dht_port", 9999);
452 _id = conf.
read<
string> (
"dht_id",
"");
453 _blacklist = (conf.
read<std::string> (
"dht_blacklist",
"yes") ==
"yes");
454 _selfannounce = (conf.
read<std::string> (
"dht_self_announce",
"yes") ==
"yes");
455 _dnsbootstrapping = (conf.
read<std::string> (
"dht_bootstrapping",
"yes") ==
"yes");
456 string list = conf.
read<
string> (
"dht_bootstrapping_domains",
"");
458 list = conf.
read<
string> (
"dht_bootstrapping_ips",
"");
460 _ipv4bind = conf.
read<
string> (
"dht_bind_ipv4",
"");
461 _ipv6bind = conf.
read<
string> (
"dht_bind_ipv6",
"");
462 _nodesFilePath = conf.
read<
string> (
"dht_nodes_file",
"");
463 _ipv4 = (conf.
read<std::string> (
"dht_enable_ipv4",
"yes") ==
"yes");
464 _ipv6 = (conf.
read<std::string> (
"dht_enable_ipv6",
"yes") ==
"yes");
465 _minRating = conf.
read<
int> (
"dht_min_rating", 1);
466 _allowNeighbourToAnnounceMe = (conf.
read<std::string> (
"dht_allow_neighbours_to_announce_me",
"yes") ==
"yes");
467 _allowNeighbourAnnouncement = (conf.
read<std::string> (
"dht_allow_neighbour_announcement",
"yes") ==
"yes");
468 _ignoreDHTNeighbourInformations = (conf.
read<std::string> (
"dht_ignore_neighbour_informations",
"no") ==
"yes");
470 if (_minRating < 0) _minRating = 0;
476 _ctrl_path = conf.
read<std::string>(
"p2p_ctrlpath");
487 _address = conf.
read<std::string> (
"email_address",
"root@localhost");
488 _smtpServer = conf.
read<std::string> (
"email_smtp_server",
"localhost");
489 _smtpPort = conf.
read<
int> (
"email_smtp_port", 25);
490 _smtpUsername = conf.
read<std::string> (
"email_smtp_username",
"root");
491 _smtpPassword = conf.
read<std::string> (
"email_smtp_password",
"");
492 _smtpInterval = conf.
read<
size_t> (
"email_smtp_submit_interval", 60);
493 _smtpConnectionTimeout = conf.
read<
size_t> (
"email_smtp_connection_timeout", -1);
494 _smtpKeepAliveTimeout = conf.
read<
size_t> (
"email_smtp_keep_alive", 30);
495 _smtpNeedAuth = (conf.
read<std::string> (
"email_smtp_need_authentication",
"no") ==
"yes");
496 _smtpUseTLS = (conf.
read<std::string> (
"email_smtp_socket_type",
"") ==
"tls");
497 _smtpUseSSL = (conf.
read<std::string> (
"email_smtp_socket_type",
"") ==
"ssl");
498 _imapServer = conf.
read<std::string> (
"email_imap_server",
"localhost");
499 _imapPort = conf.
read<
int> (
"email_imap_port", 143);
500 _imapUsername = conf.
read<std::string> (
"email_imap_username", _smtpUsername);
501 _imapPassword = conf.
read<std::string> (
"email_imap_password", _smtpPassword);
502 tmp = conf.
read<
string> (
"email_imap_folder",
"");
504 _imapInterval = conf.
read<
size_t> (
"email_imap_lookup_interval", 60);
505 _imapConnectionTimeout = conf.
read<
size_t> (
"email_imap_connection_timeout", -1);
506 _imapUseTLS = (conf.
read<std::string> (
"email_imap_socket_type",
"") ==
"tls");
507 _imapUseSSL = (conf.
read<std::string> (
"email_imap_socket_type",
"") ==
"ssl");
508 _imapPurgeMail = (conf.
read<std::string> (
"email_imap_purge_mail",
"no") ==
"yes");
509 tmp = conf.
read<
string> (
"email_certs_ca",
"");
511 tmp = conf.
read<
string> (
"email_certs_user",
"");
513 _availableTime = conf.
read<
size_t> (
"email_node_available_time", 1800);
514 _returningMailsCheck = conf.
read<
size_t> (
"email_returning_mails_checks", 3);
535 return _conf.
read<
string>(
"local_uri");
537 std::vector<char> hostname_array(255);
538 if ( gethostname(&hostname_array[0], hostname_array.size()) != 0 )
542 bool success =
false;
544 DWORD dwType = REG_SZ;
545 DWORD dwBufSize = hostname_array.size();
547 const char* subkey =
"System\\CurrentControlSet\\Control\\ComputerName\\ActiveComputerName";
548 const char* win9x_subkey =
"System\\CurrentControlSet\\Control\\ComputerName\\ComputerName";
550 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, subkey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
552 if ( RegQueryValueEx(hKey,
"ComputerName", NULL, &dwType, (BYTE*)&hostname_array[0], &dwBufSize) == ERROR_SUCCESS )
561 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, win9x_subkey, 0, KEY_READ, &hKey) == ERROR_SUCCESS)
563 if ( RegQueryValueEx(hKey,
"ComputerName", NULL, &dwType, (BYTE*)&hostname_array[0], &dwBufSize) == ERROR_SUCCESS )
574 return "dtn://local";
579 return "dtn://" + std::string(&hostname_array[0]);
581 return "dtn://noname";
591 std::set<ibrcommon::vaddress> ret;
597 for (std::vector<std::string>::iterator iter = addresses.begin(); iter != addresses.end(); ++iter) {
601 throw ParameterNotFoundException();
626 nc.
port = _conf.
read<
int>(
"api_port", 4550);
629 const std::string interface_name = _conf.
read<std::string>(
"api_interface");
631 if (interface_name !=
"any")
655 return _conf.
read<std::string>(
"storage",
"default");
660 return _conf.
read<std::string>(
"use_persistent_bundlesets",
"no") ==
"yes";
668 _static_routes.clear();
670 string key =
"route1";
671 unsigned int keynumber = 1;
676 _static_routes.insert( pair<std::string, std::string>( route.front(), route.back() ) );
679 stringstream ss; ss <<
"route" << keynumber; ss >> key;
689 std::string prefix =
"static1_";
696 std::stringstream ss;
697 ss <<
"ip=" << conf.
read<std::string>(prefix +
"address",
"127.0.0.1") <<
";port=" << conf.
read<
unsigned int>(prefix +
"port", 4556) <<
";";
701 const std::string protocol = conf.
read<std::string>(prefix +
"proto",
"tcp");
702 if (protocol ==
"tcp") p = Node::CONN_TCPIP;
703 if (protocol ==
"udp") p = Node::CONN_UDPIP;
704 if (protocol ==
"lowpan") p = Node::CONN_LOWPAN;
705 if (protocol ==
"zigbee") p = Node::CONN_LOWPAN;
706 if (protocol ==
"bluetooth") p = Node::CONN_BLUETOOTH;
707 if (protocol ==
"http") p = Node::CONN_HTTP;
708 if (protocol ==
"file") p = Node::CONN_FILE;
709 if (protocol ==
"dgram:udp") p = Node::CONN_DGRAM_UDP;
710 if (protocol ==
"dgram:ethernet") p = Node::CONN_DGRAM_ETHERNET;
711 if (protocol ==
"dgram:lowpan") p = Node::CONN_DGRAM_LOWPAN;
712 if (protocol ==
"email") {
713 p = Node::CONN_EMAIL;
715 ss <<
"email=" << conf.
read<std::string>(prefix +
"email",
"root@localhost") <<
";";
718 bool node_exists =
false;
724 for (std::list<Node>::iterator iter = _nodes.begin(); iter != _nodes.end(); ++iter)
728 if (n.
getEID() == node_eid)
747 std::stringstream prefix_stream;
748 prefix_stream <<
"static" << count <<
"_";
749 prefix = prefix_stream.str();
755 _routing = conf.
read<
string>(
"routing",
"default");
757 if(_routing ==
"prophet"){
759 _prophet_config.p_encounter_max = conf.
read<
float>(
"prophet_p_encounter_max", 0.7f);
760 if(_prophet_config.p_encounter_max > 1 || _prophet_config.p_encounter_max <= 0)
761 _prophet_config.p_encounter_max = 0.7f;
762 _prophet_config.p_encounter_first = conf.
read<
float>(
"prophet_p_encounter_first", 0.5f);
763 if(_prophet_config.p_encounter_first > 1 || _prophet_config.p_encounter_first <= 0)
764 _prophet_config.p_encounter_first = 0.5f;
765 _prophet_config.p_first_threshold = conf.
read<
float>(
"prophet_p_first_threshold", 0.1f);
766 if(_prophet_config.p_first_threshold < 0 || _prophet_config.p_first_threshold >= _prophet_config.p_encounter_first)
767 _prophet_config.p_first_threshold = 0;
768 _prophet_config.beta = conf.
read<
float>(
"prophet_beta", 0.9f);
769 if(_prophet_config.beta < 0 || _prophet_config.beta > 1)
770 _prophet_config.beta = 0.9f;
771 _prophet_config.gamma = conf.
read<
float>(
"prophet_gamma", 0.999f);
772 if(_prophet_config.gamma <= 0 || _prophet_config.gamma > 1)
773 _prophet_config.gamma = 0.999f;
774 _prophet_config.delta = conf.
read<
float>(
"prophet_delta", 0.01f);
775 if(_prophet_config.delta < 0 || _prophet_config.delta > 1)
776 _prophet_config.delta = 0.01f;
778 if(_prophet_config.time_unit < 1)
779 _prophet_config.time_unit = 1;
781 if(_prophet_config.i_typ < 1)
782 _prophet_config.i_typ = 1;
784 _prophet_config.forwarding_strategy = conf.
read<std::string>(
"prophet_forwarding_strategy",
"GRTR");
785 _prophet_config.gtmx_nf_max = conf.
read<
unsigned int>(
"prophet_gtmx_nf_max", 30);
791 _forwarding = (conf.
read<std::string>(
"routing_forwarding",
"yes") ==
"yes");
796 _prefer_direct = (conf.
read<std::string>(
"routing_prefer_direct",
"yes") ==
"yes");
803 if (_use_default_net)
815 _interfaces.push_back( nc );
820 for (vector<string>::const_iterator iter = nets.begin(); iter != nets.end(); ++iter)
822 const std::string &netname = (*iter);
824 const std::string key_type =
"net_" + netname +
"_type";
825 const std::string key_port =
"net_" + netname +
"_port";
826 const std::string key_interface =
"net_" + netname +
"_interface";
827 const std::string key_address =
"net_" + netname +
"_address";
828 const std::string key_path =
"net_" + netname +
"_path";
829 const std::string key_mtu =
"net_" + netname +
"_mtu";
831 const std::string type_name = conf.
read<
string>(key_type,
"tcp");
851 nc.
url = conf.
read<std::string>(key_address,
"http://localhost/");
857 nc.
url = conf.
read<std::string>(key_path,
"");
863 nc.
port = conf.
read<
int>(key_port, 4556);
864 nc.
mtu = conf.
read<
int>(key_mtu, 1280);
877 _interfaces.push_back(nc);
886 _tcp_nodelay = (conf.
read<std::string>(
"tcp_nodelay",
"yes") ==
"yes");
887 _tcp_chunksize = conf.
read<
unsigned int>(
"tcp_chunksize", 4096);
888 _tcp_idle_timeout = conf.
read<
unsigned int>(
"tcp_idle_timeout", 0);
898 _fragmentation = (conf.
read<std::string>(
"fragmentation",
"yes") ==
"yes");
905 for (std::vector<string>::const_iterator iter = inets.begin(); iter != inets.end(); ++iter)
908 _internet_devices.insert(inet_dev);
915 _scheduling = (conf.
read<std::string>(
"scheduling",
"no") ==
"yes");
925 return _static_routes;
936 ss << name <<
"_path";
937 string key; ss >> key;
988 return _prefer_direct;
993 return _fragmentation;
1003 return _tcp_nodelay;
1008 return _tcp_chunksize;
1013 return _tcp_idle_timeout;
1018 return _auto_connect;
1023 return _prophet_config;
1028 return _internet_devices;
1033 return _link_request_interval;
1038 std::string unparsed = _conf.
read<std::string>(
"limit_" + suffix,
"0");
1040 std::stringstream ss(unparsed);
1042 float value; ss >> value;
1043 char multiplier = 0; ss >> multiplier;
1069 bool withTLS =
false;
1073 bool activateTLS =
true;
1077 _cert = conf.
read<std::string>(
"security_certificate");
1079 if (!_cert.exists())
1082 activateTLS =
false;
1085 activateTLS =
false;
1090 _key = conf.
read<std::string>(
"security_key");
1095 activateTLS =
false;
1098 activateTLS =
false;
1103 _trustedCAPath = conf.
read<std::string>(
"security_trusted_ca_path");
1104 if(!_trustedCAPath.isDirectory()){
1106 activateTLS =
false;
1109 activateTLS =
false;
1113 _disableEncryption = (conf.
read<std::string>(
"security_tls_disable_encryption",
"no") ==
"yes");
1120 _tlsRequired = (conf.
read<std::string>(
"security_tls_required",
"no") ==
"yes");
1123 _tlsOptionalOnBadClock = (conf.
read<std::string>(
"security_tls_fallback_badclock",
"no") ==
"yes");
1127 #ifdef WITH_BUNDLE_SECURITY
1130 _path = conf.
read<std::string>(
"security_path");
1132 if (!_path.exists())
1143 _level =
Level(conf.
read<
int>(
"security_level", 0));
1150 _cert = conf.
read<std::string>(
"security_certificate");
1152 if (!_cert.exists())
1160 _key = conf.
read<std::string>(
"security_key");
1171 _bab_default_key = conf.
read<std::string>(
"security_bab_default_key");
1173 if (!_bab_default_key.exists())
1198 return _tlsRequired;
1213 return _bab_default_key;
1228 return _trustedCAPath;
1233 return _disableEncryption;
1345 return _dnsbootstrapping;
1350 return _bootstrappingdomains;
1355 return !_bootstrappingips.empty();
1360 return _bootstrappingips;
1374 return _nodesFilePath;
1389 return _selfannounce;
1399 return _allowNeighbourAnnouncement;
1404 return _allowNeighbourToAnnounceMe;
1414 return _ignoreDHTNeighbourInformations;
1444 return _smtpUsername;
1449 return _smtpPassword;
1454 return _smtpInterval;
1459 return _smtpConnectionTimeout;
1463 return _smtpKeepAliveTimeout * 1000;
1468 return _smtpNeedAuth;
1493 return _imapUsername;
1498 return _imapPassword;
1508 return _imapInterval;
1513 return _imapConnectionTimeout;
1528 return _imapPurgeMail;
1538 return _tlsUserCerts;
1543 return _availableTime;
1548 return _returningMailsCheck;