IBR-DTN  1.0.0
NativeDaemon.cpp
Go to the documentation of this file.
1 /*
2  * NativeDaemon.cpp
3  *
4  * Copyright (C) 2013 IBR, TU Braunschweig
5  *
6  * Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21 
22 #include "config.h"
23 #include "NativeDaemon.h"
24 
25 #include <ibrcommon/data/BLOB.h>
26 #include <ibrcommon/data/File.h>
27 #include <ibrcommon/net/vinterface.h>
28 #include <ibrcommon/Logger.h>
29 #include <ibrcommon/link/LinkManager.h>
30 #include <ibrdtn/utils/Clock.h>
31 #include <ibrdtn/utils/Utils.h>
33 #include <list>
34 
35 #include "storage/BundleStorage.h"
36 #include "storage/BundleSeeker.h"
39 
40 #include "core/BundleCore.h"
41 #include "net/ConnectionManager.h"
42 #include "core/FragmentManager.h"
43 #include "core/Node.h"
44 #include "core/EventSwitch.h"
45 #include "core/EventDispatcher.h"
46 
47 #include "routing/BaseRouter.h"
54 
58 
62 
63 #ifdef HAVE_SYS_INOTIFY_H
64 #include "net/FileMonitor.h"
65 #endif
66 
68 #include "net/UDPDatagramService.h"
69 
70 #ifdef HAVE_SQLITE
72 #endif
73 
74 #ifdef HAVE_LIBCURL
76 #endif
77 
78 #include <ibrcommon/ibrcommon.h>
79 #ifdef IBRCOMMON_SUPPORT_LOWPAN
82 #endif
83 
84 #include "net/IPNDAgent.h"
85 
86 #include "api/ApiServer.h"
87 
88 #include "Configuration.h"
89 #include "EchoWorker.h"
90 #include "CapsuleWorker.h"
91 #include "DTNTPWorker.h"
92 #include "DevNull.h"
93 #include "Component.h"
94 
95 #ifdef WITH_WIFIP2P
96 #include "net/WifiP2PManager.h"
97 #endif
98 
99 #ifdef HAVE_VMIME
101 #endif
102 
103 #include <ibrdtn/ibrdtn.h>
104 #ifdef IBRDTN_SUPPORT_BSP
109 #endif
110 
111 #ifdef WITH_TLS
113 #endif
114 
115 #ifdef WITH_DHT_NAMESERVICE
116 #include "net/DHTNameService.h"
117 #endif
118 
119 #include "Debugger.h"
120 
122 #include "core/NodeEvent.h"
123 #include "core/GlobalEvent.h"
124 #include "core/CustodyEvent.h"
126 #include "net/BundleReceivedEvent.h"
129 #include "net/ConnectionEvent.h"
130 
131 #define UNIT_MB * 1048576
132 
133 namespace dtn
134 {
135  namespace daemon
136  {
138  {
139  }
140 
142  {
143  }
144 
145  const std::string NativeDaemon::TAG = "NativeDaemon";
146 
148  : _runlevel(RUNLEVEL_ZERO), _statecb(statecb), _eventcb(eventcb), _event_loop(NULL)
149  {
150 
151  }
152 
154  {
155  }
156 
157  std::vector<std::string> NativeDaemon::getVersion() const throw ()
158  {
159  std::vector<std::string> ret;
160  ret.push_back(VERSION);
161  ret.push_back(BUILD_NUMBER);
162  return ret;
163  }
164 
165  void NativeDaemon::clearStorage() const throw ()
166  {
168  }
169 
170  void NativeDaemon::setLeMode(bool low_energy) const throw ()
171  {
173  }
174 
175  void NativeDaemon::startDiscovery() const throw ()
176  {
178  }
179 
180  void NativeDaemon::stopDiscovery() const throw ()
181  {
183  }
184 
185  void NativeDaemon::bindEvents()
186  {
187  if (_eventcb != NULL) {
188  // bind to several events
197 
198 #ifdef IBRDTN_SUPPORT_BSP
200 #endif
201  }
202  }
203 
204  void NativeDaemon::unbindEvents()
205  {
206  if (_eventcb != NULL) {
207  // unbind to events
216 
217 #ifdef IBRDTN_SUPPORT_BSP
219 #endif
220  }
221  }
222 
223  void NativeDaemon::addEventData(const dtn::data::Bundle &b, std::vector<std::string> &data) const
224  {
225  // add the bundle data
226  data.push_back("Source: " + b.source.getString());
227  data.push_back("Timestamp: " + b.timestamp.toString());
228  data.push_back("Sequencenumber: " + b.sequencenumber.toString());
229  data.push_back("Lifetime: " + b.lifetime.toString());
230  data.push_back("Procflags: " + b.procflags.toString());
231 
232  // add the destination eid
233  data.push_back("Destination: " + b.destination.getString());
234 
236  {
237  // add fragmentation values
238  data.push_back("Appdatalength: " + b.appdatalength.toString());
239  data.push_back("Fragmentoffset: " + b.fragmentoffset.toString());
240  }
241  }
242 
243  void NativeDaemon::addEventData(const dtn::data::MetaBundle &b, std::vector<std::string> &data) const
244  {
245  // add the bundle data
246  data.push_back("Source: " + b.source.getString());
247  data.push_back("Timestamp: " + b.timestamp.toString());
248  data.push_back("Sequencenumber: " + b.sequencenumber.toString());
249  data.push_back("Lifetime: " + b.lifetime.toString());
250  data.push_back("Procflags: " + b.procflags.toString());
251 
252  // add the destination eid
253  data.push_back("Destination: " + b.destination.getString());
254 
256  {
257  // add fragmentation values
258  data.push_back("Appdatalength: " + b.appdatalength.toString());
259  data.push_back("Fragmentoffset: " + b.fragmentoffset.toString());
260  }
261  }
262 
263  void NativeDaemon::addEventData(const dtn::data::BundleID &b, std::vector<std::string> &data) const
264  {
265  // add the bundle data
266  data.push_back("Source: " + b.source.getString());
267  data.push_back("Timestamp: " + b.timestamp.toString());
268  data.push_back("Sequencenumber: " + b.sequencenumber.toString());
269 
270  if (b.isFragment())
271  {
272  // add fragmentation values
273  data.push_back("Fragmentoffset: " + b.fragmentoffset.toString());
274  std::stringstream fpll;
275  fpll << "Fragmentpayload: " << b.getPayloadLength();
276  data.push_back(fpll.str());
277  }
278  }
279 
281  {
282  const std::string event = node.getName();
283  std::string action;
284  std::vector<std::string> data;
285 
286  // set action
287  switch (node.getAction())
288  {
290  action = "available";
291  break;
293  action = "unavailable";
294  break;
296  action = "data_added";
297  break;
299  action = "data_removed";
300  break;
301  default:
302  break;
303  }
304 
305  // add the node eid
306  data.push_back("EID: " + node.getNode().getEID().getString());
307 
308  // signal event to the callback interface
309  _eventcb->eventRaised(event, action, data);
310  }
311 
313  {
314  const std::string event = global.getName();
315  std::string action;
316  std::vector<std::string> data;
317 
318  // set action
319  switch (global.getAction())
320  {
322  action = "busy";
323  break;
325  action = "idle";
326  break;
328  action = "normal";
329  break;
331  action = "reload";
332  break;
334  action = "shutdown";
335  break;
337  action = "low-energy";
338  break;
340  action = "internet available";
341  break;
343  action = "internet unavailable";
344  break;
346  action = "discovery start";
347  break;
349  action = "discovery stop";
350  break;
351  default:
352  break;
353  }
354 
355  // signal event to the callback interface
356  _eventcb->eventRaised(event, action, data);
357  }
358 
360  {
361  const std::string event = received.getName();
362  std::string action;
363  std::vector<std::string> data;
364 
365  // set action
366  action = "received";
367 
368  data.push_back("Peer: " + received.peer.getString());
369  data.push_back("Local: " + (received.fromlocal ? std::string("true") : std::string("false")));
370 
371  // add bundle data
372  addEventData(received.bundle, data);
373 
374  // signal event to the callback interface
375  _eventcb->eventRaised(event, action, data);
376  }
377 
378  void NativeDaemon::raiseEvent(const dtn::core::CustodyEvent &custody) throw ()
379  {
380  const std::string event = custody.getName();
381  std::string action;
382  std::vector<std::string> data;
383 
384  // set action
385  switch (custody.getAction())
386  {
388  action = "accept";
389  break;
391  action = "reject";
392  break;
393  default:
394  break;
395  }
396 
397  // add bundle data
398  addEventData(custody.getBundle(), data);
399 
400  // signal event to the callback interface
401  _eventcb->eventRaised(event, action, data);
402  }
403 
405  {
406  const std::string event = aborted.getName();
407  std::string action;
408  std::vector<std::string> data;
409 
410  // set action
411  action = "aborted";
412 
413  data.push_back("Peer: " + aborted.getPeer().getString());
414 
415  // add bundle data
416  addEventData(aborted.getBundleID(), data);
417 
418  // signal event to the callback interface
419  _eventcb->eventRaised(event, action, data);
420  }
421 
423  {
424  const std::string event = completed.getName();
425  std::string action;
426  std::vector<std::string> data;
427 
428  // set action
429  action = "completed";
430 
431  data.push_back("Peer: " + completed.getPeer().getString());
432 
433  // add bundle data
434  addEventData(completed.getBundle(), data);
435 
436  // signal event to the callback interface
437  _eventcb->eventRaised(event, action, data);
438  }
439 
440  void NativeDaemon::raiseEvent(const dtn::net::ConnectionEvent &connection) throw ()
441  {
442  const std::string event = connection.getName();
443  std::string action;
444  std::vector<std::string> data;
445 
446  // set action
447  switch (connection.getState())
448  {
450  action = "up";
451  break;
453  action = "down";
454  break;
456  action = "setup";
457  break;
459  action = "timeout";
460  break;
461  default:
462  break;
463  }
464 
465  // write the peer eid
466  data.push_back("Peer: " + connection.getNode().getEID().getString());
467 
468  // signal event to the callback interface
469  _eventcb->eventRaised(event, action, data);
470  }
471 
473  {
474  const std::string event = queued.getName();
475  std::string action;
476  std::vector<std::string> data;
477 
478  // set action
479  action = "queued";
480 
481  // add bundle data
482  addEventData(queued.bundle, data);
483 
484  // signal event to the callback interface
485  _eventcb->eventRaised(event, action, data);
486  }
487 
488 #ifdef IBRDTN_SUPPORT_BSP
489  void NativeDaemon::raiseEvent(const dtn::security::KeyExchangeEvent &keyExchange) throw ()
490  {
491  const std::string event = keyExchange.getName();
492  std::string action;
493  std::vector<std::string> data;
494 
495  // set action
496  switch (keyExchange.getData().getAction()) {
498  action = "COMPLETE";
499  break;
501  action = "PASSWORDREQUEST";
502  break;
504  action = "WRONGPASSWORD";
505  break;
507  action = "HASHCOMMIT";
508  data.push_back("data: " + keyExchange.getData().str());
509  break;
511  data.push_back("data: " + keyExchange.getData().str());
512  action = "NEWKEY";
513  break;
515  action = "ERROR";
516  break;
517  default:
518  return;
519  }
520 
521  std::stringstream sstm;
522  data.push_back("EID: " + keyExchange.getEID().getString());
523 
524  sstm << "session: " << keyExchange.getData().getSessionId();
525  data.push_back(sstm.str());
526 
527  sstm.str("");
528  sstm << "protocol: " << keyExchange.getData().getProtocol();
529  data.push_back(sstm.str());
530 
531  // signal event to the callback interface
532  _eventcb->eventRaised(event, action, data);
533  }
534 #endif
535 
536  std::string NativeDaemon::getLocalUri() const throw ()
537  {
539  }
540 
542  {
543  NativeStats ret;
544 
545  ret.uptime = dtn::utils::Clock::getUptime().get<size_t>();
546  ret.timestamp = dtn::utils::Clock::getTime().get<size_t>();
549 
553 
561 
564 
567 
568  for (dtn::net::ConvergenceLayer::stats_data::const_iterator iter = data.begin(); iter != data.end(); ++iter) {
569  const dtn::net::ConvergenceLayer::stats_pair &pair = (*iter);
570  ret.addData(pair.first, pair.second);
571  }
572 
573  return ret;
574  }
575 
576  NativeNode NativeDaemon::getInfo(const std::string &neighbor_eid) const throw (NativeDaemonException)
577  {
578  NativeNode nn(neighbor_eid);
579 
580  dtn::data::EID eid(neighbor_eid);
581  try {
583  dtn::core::Node::URI uri = n.getAll().front();
584  switch (uri.type) {
586  throw NativeDaemonException("Node is not available");
587  break;
588 
591  break;
592 
595  break;
596 
599  break;
600 
603  break;
604 
607  break;
608 
611  break;
612  }
613  } catch (const NodeNotAvailableException &ex) {
614  throw NativeDaemonException(ex.what());
615  }
616 
617  return nn;
618  }
619 
620  std::vector<std::string> NativeDaemon::getNeighbors() const throw ()
621  {
622  std::vector<std::string> ret;
623 
624  // get neighbors
625  const std::set<dtn::core::Node> nlist = dtn::core::BundleCore::getInstance().getConnectionManager().getNeighbors();
626  for (std::set<dtn::core::Node>::const_iterator iter = nlist.begin(); iter != nlist.end(); ++iter)
627  {
628  const dtn::core::Node &n = (*iter);
629  ret.push_back(n.getEID().getString());
630  }
631 
632  return ret;
633  }
634 
635  void NativeDaemon::addConnection(std::string eid, std::string protocol, std::string address, std::string service, bool local) const throw ()
636  {
637  dtn::core::Node n(eid);
639 
640  if (local) t = dtn::core::Node::NODE_STATIC_LOCAL;
641 
642  if (protocol == "tcp")
643  {
644  std::string uri = "ip=" + address + ";port=" + service + ";";
647  }
648  else if (protocol == "udp")
649  {
650  std::string uri = "ip=" + address + ";port=" + service + ";";
653  }
654  else if (protocol == "file")
655  {
658  }
659  }
660 
661  void NativeDaemon::removeConnection(std::string eid, std::string protocol, std::string address, std::string service, bool local) const throw ()
662  {
663  dtn::core::Node n(eid);
665 
666  if (local) t = dtn::core::Node::NODE_STATIC_LOCAL;
667 
668  if (protocol == "tcp")
669  {
670  std::string uri = "ip=" + address + ";port=" + service + ";";
673  }
674  else if (protocol == "udp")
675  {
676  std::string uri = "ip=" + address + ";port=" + service + ";";
679  }
680  else if (protocol == "file")
681  {
684  }
685  }
686 
687  void NativeDaemon::initiateConnection(std::string eid) const
688  {
689  dtn::data::EID neighbor(eid);
691 
692  try {
693  const dtn::core::Node n = cm.getNeighbor(neighbor);
694  cm.open(n);
695  } catch (const ibrcommon::Exception&) {
696  // ignore errors
697  }
698  }
699 
700  void NativeDaemon::setGloballyConnected(bool connected) const
701  {
703  }
704 
705  void NativeDaemon::onKeyExchangeBegin(std::string eid, int protocol, std::string password) const
706  {
707 #ifdef IBRDTN_SUPPORT_BSP
708  const dtn::data::EID peer(eid);
710 
711  if (!password.empty()) {
712  ked.str(password);
713  }
714 
716 #endif
717  }
718 
719  void NativeDaemon::onKeyExchangeResponse(std::string eid, int protocol, int session, int step, std::string data) const
720  {
721 #ifdef IBRDTN_SUPPORT_BSP
723  ked.setStep(step);
724  ked.setSessionId(session);
725 
726  if (!data.empty()) {
727  ked.str(data);
728  }
729 
731 #endif
732  }
733 
735  {
736 #ifdef IBRDTN_SUPPORT_BSP
737  try {
738  // convert address into an EID
739  const dtn::data::EID endpoint(eid);
740 
741  // get public key
743 
744  NativeKeyInfo info;
745  info.endpoint = key.reference.getString();
746  info.data = key.getData();
747  info.fingerprint = key.getFingerprint();
748  info.trustlevel = key.trustlevel;
749  info.flags = key.flags.get<unsigned int>();
750 
751  return info;
752  } catch (ibrcommon::Exception &e) {
753  throw NativeDaemonException(e.what());
754  }
755 #else
756  throw NativeDaemonException("not supported");
757 #endif
758  }
759 
760  void NativeDaemon::removeKey(std::string eid) const throw (NativeDaemonException)
761  {
762 #ifdef IBRDTN_SUPPORT_BSP
763  try {
764  // convert address into an EID
765  const dtn::data::EID endpoint(eid);
766 
767  // get public key
770  } catch (ibrcommon::Exception &e) {
771  throw NativeDaemonException(e.what());
772  }
773 #else
774  throw NativeDaemonException("not supported");
775 #endif
776  }
777 
778  void NativeDaemon::setLogging(const std::string &defaultTag, int logLevel) const throw ()
779  {
784  // set default logging
785  unsigned char logsys = ibrcommon::Logger::LOGGER_EMERG | ibrcommon::Logger::LOGGER_ALERT | ibrcommon::Logger::LOGGER_CRIT | ibrcommon::Logger::LOGGER_ERR;
786 
787  // activate info messages and warnings
788  if (logLevel > 0) {
789  logsys |= ibrcommon::Logger::LOGGER_WARNING;
790  logsys |= ibrcommon::Logger::LOGGER_INFO;
791  }
792 
793  // activate frequent notice messages
794  if (logLevel > 1) {
795  logsys |= ibrcommon::Logger::LOGGER_NOTICE;
796  }
797 
798  // activate debugging
799  if (logLevel > 2) {
800  logsys |= ibrcommon::Logger::LOGGER_DEBUG;
801  }
802 
803  // set default logging tag
804  ibrcommon::Logger::setDefaultTag(defaultTag);
805 
806  // enable logging to Android's logcat
807  ibrcommon::Logger::enableSyslog("ibrdtn-daemon", 0, 0, logsys);
808  }
809 
810  void NativeDaemon::setConfigFile(const std::string &path)
811  {
812  _config_file = ibrcommon::File(path);
813 
814  // load the configuration file
816  conf.load(_config_file.getPath());
817 
818  // reload bundle core configuration
820 
821 #ifdef IBRDTN_SUPPORT_BSP
822  // initialize the key manager for the security extensions
824 #endif
825  }
826 
830  void NativeDaemon::setLogFile(const std::string &path, int logLevel) const throw ()
831  {
832  // logging options
833  unsigned char logopts = ibrcommon::Logger::LOG_DATETIME | ibrcommon::Logger::LOG_LEVEL | ibrcommon::Logger::LOG_TAG;
834 
835  // set default logging
836  unsigned char logsys = ibrcommon::Logger::LOGGER_EMERG | ibrcommon::Logger::LOGGER_ALERT | ibrcommon::Logger::LOGGER_CRIT | ibrcommon::Logger::LOGGER_ERR;
837 
838  // deactivate logging if logLevel is below zero
839  if (logLevel < 0) {
840  logsys = 0;
841  }
842 
843  // activate info messages and warnings
844  if (logLevel > 0) {
845  logsys |= ibrcommon::Logger::LOGGER_WARNING;
846  logsys |= ibrcommon::Logger::LOGGER_INFO;
847  }
848 
849  // activate frequent notice messages
850  if (logLevel > 1) {
851  logsys |= ibrcommon::Logger::LOGGER_NOTICE;
852  }
853 
854  // activate debugging
855  if (logLevel > 2) {
856  logsys |= ibrcommon::Logger::LOGGER_DEBUG;
857  }
858 
859  const ibrcommon::File lf(path);
860  ibrcommon::Logger::setLogfile(lf, logsys, logopts);
861  }
862 
864  {
865  return _runlevel;
866  }
867 
869  {
870  ibrcommon::MutexLock l(_runlevel_cond);
871  if (_runlevel < rl) {
872  for (; _runlevel < rl; _runlevel = DaemonRunLevel(_runlevel + 1)) {
873  init_up(DaemonRunLevel(_runlevel + 1));
874  _runlevel_cond.signal(true);
875  }
876  } else if (_runlevel > rl) {
877  for (; _runlevel > rl; _runlevel = DaemonRunLevel(_runlevel - 1)) {
878  init_down(_runlevel);
879  _runlevel_cond.signal(true);
880  }
881  }
882  }
883 
884  void NativeDaemon::init_up(DaemonRunLevel rl) throw (NativeDaemonException)
885  {
886  switch (rl) {
887  case RUNLEVEL_ZERO:
888  // nothing to do here
889  break;
890 
891  case RUNLEVEL_CORE:
892  init_core();
893  break;
894 
895  case RUNLEVEL_STORAGE:
896  init_storage();
897  break;
898 
899  case RUNLEVEL_ROUTING:
900  init_routing();
901  break;
902 
903  case RUNLEVEL_API:
904  init_api();
905  break;
906 
907  case RUNLEVEL_NETWORK:
908  init_network();
909  break;
910 
912  init_routing_extensions();
913  break;
914  }
915 
919  component_list &components = _components[rl];
920  for (component_list::iterator it = components.begin(); it != components.end(); ++it)
921  {
922  (*it)->initialize();
923  }
924 
928  for (component_list::iterator it = components.begin(); it != components.end(); ++it)
929  {
930  (*it)->startup();
931  }
932 
933  if (_statecb != NULL) {
934  _statecb->levelChanged(rl);
935  }
936 
937  IBRCOMMON_LOGGER_DEBUG_TAG(NativeDaemon::TAG, 5) << "runlevel " << rl << " reached" << IBRCOMMON_LOGGER_ENDL;
938  }
939 
940  void NativeDaemon::init_down(DaemonRunLevel rl) throw (NativeDaemonException)
941  {
945  component_list &components = _components[rl];
946  for (component_list::iterator it = components.begin(); it != components.end(); ++it)
947  {
948  (*it)->terminate();
949  }
950 
951  switch (rl) {
952  case RUNLEVEL_ZERO:
953  // nothing to do here
954  break;
955 
956  case RUNLEVEL_CORE:
957  shutdown_core();
958  break;
959 
960  case RUNLEVEL_STORAGE:
961  shutdown_storage();
962  break;
963 
964  case RUNLEVEL_ROUTING:
965  shutdown_routing();
966  break;
967 
968  case RUNLEVEL_API:
969  shutdown_api();
970  break;
971 
972  case RUNLEVEL_NETWORK:
973  shutdown_network();
974  break;
975 
977  shutdown_routing_extensions();
978  break;
979  }
980 
984  for (component_list::iterator it = components.begin(); it != components.end(); ++it)
985  {
986  delete (*it);
987  }
988  components.clear();
989 
990  if (_statecb != NULL) {
991  _statecb->levelChanged(DaemonRunLevel(rl-1));
992  }
993 
994  IBRCOMMON_LOGGER_DEBUG_TAG(NativeDaemon::TAG, 5) << "runlevel " << (rl-1) << " reached" << IBRCOMMON_LOGGER_ENDL;
995  }
996 
998  {
999  try {
1000  ibrcommon::MutexLock l(_runlevel_cond);
1001  while (_runlevel != rl) _runlevel_cond.wait();
1002  } catch (const ibrcommon::Conditional::ConditionalAbortException&) {
1003  // wait aborted
1004  }
1005  }
1006 
1007  void NativeDaemon::init_core() throw (NativeDaemonException)
1008  {
1009  // enable link manager
1010  ibrcommon::LinkManager::initialize();
1011 
1012  // get the core
1014 
1015  // reset and get configuration
1017 
1018  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "IBR-DTN daemon " << conf.version() << IBRCOMMON_LOGGER_ENDL;
1019 
1020  // load configuration
1021  if (_config_file.exists()) {
1022  conf.load(_config_file.getPath());
1023  } else {
1024  conf.load();
1025  }
1026 
1027  //configure link manager
1028  size_t interval = conf.getNetwork().getLinkRequestInterval();
1029  ibrcommon::LinkManager::setLinkRequestInterval(interval);
1030 
1031  // greeting
1032  if (conf.getDebug().enabled())
1033  {
1034  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "debug level set to " << conf.getDebug().level() << IBRCOMMON_LOGGER_ENDL;
1035  }
1036 
1037  try {
1038  const ibrcommon::File &lf = conf.getLogger().getLogfile();
1039  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "use logfile for output: " << lf.getPath() << IBRCOMMON_LOGGER_ENDL;
1041 
1042  if (conf.getDaemon().getThreads() > 1)
1043  {
1044  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Parallel event processing enabled using " << conf.getDaemon().getThreads() << " processes." << IBRCOMMON_LOGGER_ENDL;
1045  }
1046 
1047  // initialize the event switch
1049 
1050  // listen to events
1051  bindEvents();
1052 
1053  // create a thread for the main loop
1054  _event_loop = new NativeEventLoop(*this);
1055 
1056  // start the event switch
1057  _event_loop->start();
1058 
1059 #ifdef WITH_TLS
1060  /* enable TLS support */
1061  if ( conf.getSecurity().doTLS() )
1062  {
1063  _components[RUNLEVEL_CORE].push_back(new dtn::security::SecurityCertificateManager());
1064  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "TLS security enabled" << IBRCOMMON_LOGGER_ENDL;
1065  }
1066 #endif
1067 
1068  // initialize core component
1069  core.initialize();
1070 
1071 #ifdef IBRDTN_SUPPORT_BSP
1072  // initialize the key manager for the security extensions
1074 #endif
1075  }
1076 
1077  void NativeDaemon::shutdown_core() throw (NativeDaemonException)
1078  {
1079  // shutdown the event switch
1080  _event_loop->stop();
1081  _event_loop->join();
1082 
1083  delete _event_loop;
1084  _event_loop = NULL;
1085 
1086  // unlisten to events
1087  unbindEvents();
1088 
1089  // get the core
1091 
1092  // shutdown the core component
1093  core.terminate();
1094 
1095 #ifdef IBRDTN_SUPPORT_BSP
1096  // reset configuration
1098 
1099  // initialize the key manager for the security extensions
1101 #endif
1102  }
1103 
1104  void NativeDaemon::init_storage() throw (NativeDaemonException)
1105  {
1107 
1108  // create a storage for bundles
1109  dtn::storage::BundleStorage *storage = NULL;
1110 
1111 #ifdef HAVE_SQLITE
1112  if (conf.getStorage() == "sqlite")
1113  {
1114  try {
1115  // new methods for blobs
1116  ibrcommon::File path = conf.getPath("storage");
1117 
1118  // create workdir if needed
1119  if (!path.exists())
1120  {
1121  ibrcommon::File::createDirectory(path);
1122  }
1123 
1124  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "using sqlite bundle storage in " << path.getPath() << IBRCOMMON_LOGGER_ENDL;
1125 
1126 
1128  if (conf.getUsePersistentBundleSets())
1129  {
1130  sbs = new dtn::storage::SQLiteBundleStorage(path, conf.getLimit("storage"), true);
1131  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "using persistent bundle-sets" << IBRCOMMON_LOGGER_ENDL;
1132  }
1133  else
1134  {
1135  sbs = new dtn::storage::SQLiteBundleStorage(path, conf.getLimit("storage"), false);
1136  }
1137 
1138  _components[RUNLEVEL_STORAGE].push_back(sbs);
1139  storage = sbs;
1141  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "storage for bundles" << IBRCOMMON_LOGGER_ENDL;
1142  throw NativeDaemonException("initialization of the bundle storage failed");
1143  }
1144  }
1145 
1146 
1147 #endif
1148 
1149  if ((conf.getStorage() == "simple") || (conf.getStorage() == "default"))
1150  {
1151  // default behavior if no bundle storage is set
1152  try {
1153  // new methods for blobs
1154  ibrcommon::File path = conf.getPath("storage");
1155 
1156  // create workdir if needed
1157  if (!path.exists()) ibrcommon::File::createDirectory(path);
1158 
1159  if (conf.getUsePersistentBundleSets())
1160  {
1161  dtn::data::MemoryBundleSet::setPath(path.get("bundle-set"));
1162  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "using persistent bundle-sets" << IBRCOMMON_LOGGER_ENDL;
1163  }
1164 
1165  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "using simple bundle storage in " << path.getPath() << IBRCOMMON_LOGGER_ENDL;
1166  dtn::storage::SimpleBundleStorage *sbs = new dtn::storage::SimpleBundleStorage(path, conf.getLimit("storage"), static_cast<unsigned int>(conf.getLimit("storage_buffer")));
1167  _components[RUNLEVEL_STORAGE].push_back(sbs);
1168  storage = sbs;
1170  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "using bundle storage in memory-only mode" << IBRCOMMON_LOGGER_ENDL;
1172  _components[RUNLEVEL_STORAGE].push_back(sbs);
1173  storage = sbs;
1174  }
1175  }
1176 
1177  if (storage == NULL)
1178  {
1179  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "bundle storage module \"" << conf.getStorage() << "\" do not exists!" << IBRCOMMON_LOGGER_ENDL;
1180  throw NativeDaemonException("bundle storage not available");
1181  }
1182 
1183  // set the storage in the core
1185 
1186  // use scheduling?
1187  if (dtn::daemon::Configuration::getInstance().getNetwork().doScheduling())
1188  {
1189  // create a new bundle index
1191 
1192  // attach index to the storage
1193  storage->attach(bundle_index);
1194 
1195  // set this bundle index as default bundle seeker which is used to find bundles to transfer
1197 
1198  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Enable extended bundle index for scheduling" << IBRCOMMON_LOGGER_ENDL;
1199  } else {
1200  // set the storage as default seeker
1202  }
1203 
1207  try {
1208  // the configured BLOB path
1209  ibrcommon::File blob_path = conf.getPath("blob");
1210 
1211  // check if the BLOB path exists
1212  if (!blob_path.exists()) {
1213  // try to create the BLOB path
1214  ibrcommon::File::createDirectory(blob_path);
1215  }
1216 
1217  if (blob_path.exists() && blob_path.isDirectory())
1218  {
1219  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "using BLOB path: " << blob_path.getPath() << IBRCOMMON_LOGGER_ENDL;
1220  ibrcommon::BLOB::changeProvider(new ibrcommon::FileBLOBProvider(blob_path), true);
1221  }
1222  else
1223  {
1224  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, warning) << "BLOB path exists, but is not a directory! Fallback to memory based mode." << IBRCOMMON_LOGGER_ENDL;
1225  ibrcommon::BLOB::changeProvider(new ibrcommon::MemoryBLOBProvider(), true);
1226  }
1228  }
1229 
1230  void NativeDaemon::shutdown_storage() const throw (NativeDaemonException)
1231  {
1232  // reset BLOB provider to memory based
1233  ibrcommon::BLOB::changeProvider(new ibrcommon::MemoryBLOBProvider(), true);
1234 
1235  // set the seeker in the core to NULL
1237 
1238  // set the storage in the core to NULL
1240  }
1241 
1242  void NativeDaemon::init_routing() throw (NativeDaemonException)
1243  {
1244  // create the base router
1246 
1247  // add the router to the components list
1248  _components[RUNLEVEL_ROUTING].push_back(router);
1249  }
1250 
1251  void NativeDaemon::shutdown_routing() const throw (NativeDaemonException)
1252  {
1253  }
1254 
1255  void NativeDaemon::init_api() throw (NativeDaemonException)
1256  {
1258 
1259  // Debugger
1260  _apps.push_back( new dtn::daemon::Debugger() );
1261 
1262  // add echo module
1263  _apps.push_back( new dtn::daemon::EchoWorker() );
1264 
1265  // add bundle-in-bundle endpoint
1266  _apps.push_back( new dtn::daemon::CapsuleWorker() );
1267 
1268  // add DT-NTP worker
1269  _apps.push_back( new dtn::daemon::DTNTPWorker() );
1270 
1271  // add DevNull module
1272  _apps.push_back( new dtn::daemon::DevNull() );
1273 
1274 #ifdef IBRDTN_SUPPORT_BSP
1275  if (conf.getSecurity().enabled())
1276  {
1277  // add key-exchanger component
1278  _components[RUNLEVEL_API].push_back(new dtn::security::KeyExchanger());
1279  }
1280 #endif
1281 
1282  if (conf.getNetwork().doFragmentation())
1283  {
1284  // manager class for fragmentations
1285  _components[RUNLEVEL_API].push_back( new dtn::core::FragmentManager() );
1286  }
1287 
1288 #ifndef ANDROID
1289  if (conf.doAPI())
1290  {
1291  try {
1292  ibrcommon::File socket = conf.getAPISocket();
1293 
1294  try {
1295  // use unix domain sockets for API
1296  _components[RUNLEVEL_API].push_back(new dtn::api::ApiServer(socket));
1297  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "API initialized using unix domain socket: " << socket.getPath() << IBRCOMMON_LOGGER_ENDL;
1298  } catch (const ibrcommon::socket_exception&) {
1299  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Unable to bind to unix domain socket " << socket.getPath() << ". API not initialized!" << IBRCOMMON_LOGGER_ENDL;
1300  exit(-1);
1301  }
1304 
1305  try {
1306  // instance a API server, first create a socket
1307  _components[RUNLEVEL_API].push_back(new dtn::api::ApiServer(apiconf.iface, apiconf.port));
1308  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "API initialized using tcp socket: " << apiconf.iface.toString() << ":" << apiconf.port << IBRCOMMON_LOGGER_ENDL;
1309  } catch (const ibrcommon::socket_exception&) {
1310  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Unable to bind to " << apiconf.iface.toString() << ":" << apiconf.port << ". API not initialized!" << IBRCOMMON_LOGGER_ENDL;
1311  exit(-1);
1312  }
1313  };
1314  }
1315  else
1316  {
1317  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "API disabled" << IBRCOMMON_LOGGER_ENDL;
1318  }
1319 #endif
1320  }
1321 
1322  void NativeDaemon::shutdown_api() throw (NativeDaemonException)
1323  {
1324  for (app_list::iterator it = _apps.begin(); it != _apps.end(); ++it)
1325  {
1326  delete (*it);
1327  }
1328  _apps.clear();
1329  }
1330 
1331  void NativeDaemon::init_network() throw (NativeDaemonException)
1332  {
1335 
1336  // get the configuration of the convergence layers
1337  const std::list<dtn::daemon::Configuration::NetConfig> &nets = conf.getNetwork().getInterfaces();
1338 
1339  // local cl map
1340  std::map<dtn::daemon::Configuration::NetConfig::NetType, dtn::net::ConvergenceLayer*> _cl_map;
1341 
1342  // holder for file convergence layer
1343  FileConvergenceLayer *filecl = NULL;
1344 
1345  // add file monitor
1346 #ifdef HAVE_SYS_INOTIFY_H
1347  FileMonitor *fm = NULL;
1348 #endif
1349 
1350  // create the convergence layers
1351  for (std::list<dtn::daemon::Configuration::NetConfig>::const_iterator iter = nets.begin(); iter != nets.end(); ++iter)
1352  {
1353  const dtn::daemon::Configuration::NetConfig &net = (*iter);
1354 
1355  try {
1356  switch (net.type)
1357  {
1359  {
1360  try {
1361  if (filecl == NULL)
1362  {
1363  filecl = new FileConvergenceLayer();
1364  _components[RUNLEVEL_NETWORK].push_back(filecl);
1365  }
1366 
1367 #ifdef HAVE_SYS_INOTIFY_H
1368  if (net.url.size() > 0)
1369  {
1370  ibrcommon::File path(net.url);
1371 
1372  if (path.exists())
1373  {
1374  if (fm == NULL)
1375  {
1376  fm = new FileMonitor();
1377  _components[RUNLEVEL_NETWORK].push_back(fm);
1378  }
1379  ibrcommon::File path(net.url);
1380  fm->watch(path);
1381  }
1382  }
1383 #endif
1384  } catch (const ibrcommon::Exception &ex) {
1385  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add FileConvergenceLayer: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1386  }
1387  break;
1388  }
1389 
1391  {
1392  try {
1393  _components[RUNLEVEL_NETWORK].push_back( new dtn::net::UDPConvergenceLayer( net.iface, net.port, net.mtu ) );
1394  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "UDP ConvergenceLayer added on " << net.iface.toString() << ":" << net.port << IBRCOMMON_LOGGER_ENDL;
1395  } catch (const ibrcommon::Exception &ex) {
1396  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add UDP ConvergenceLayer on " << net.iface.toString() << ": " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1397  }
1398 
1399  break;
1400  }
1401 
1403  {
1404  // look for an earlier instance of
1405  std::map<dtn::daemon::Configuration::NetConfig::NetType, dtn::net::ConvergenceLayer*>::iterator it = _cl_map.find(net.type);
1406 
1407  TCPConvergenceLayer *tcpcl = NULL;
1408 
1409  if (it == _cl_map.end()) {
1410  tcpcl = new TCPConvergenceLayer();
1411  } else {
1412  tcpcl = dynamic_cast<TCPConvergenceLayer*>(it->second);
1413  }
1414 
1415  try {
1416  tcpcl->add(net.iface, net.port);
1417 
1418  if (it == _cl_map.end()) {
1419  _components[RUNLEVEL_NETWORK].push_back(tcpcl);
1420  _cl_map[net.type] = tcpcl;
1421  }
1422 
1423  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "TCP ConvergenceLayer added on " << net.iface.toString() << ":" << net.port << IBRCOMMON_LOGGER_ENDL;
1424  } catch (const ibrcommon::Exception &ex) {
1425  if (it == _cl_map.end()) {
1426  delete tcpcl;
1427  }
1428 
1429  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add TCP ConvergenceLayer on " << net.iface.toString() << ": " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1430  }
1431 
1432  break;
1433  }
1434 
1435 #ifdef HAVE_LIBCURL
1437  {
1438  try {
1439  _components[RUNLEVEL_NETWORK].push_back( new HTTPConvergenceLayer( net.url ) );
1440  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "HTTP ConvergenceLayer added, Server: " << net.url << IBRCOMMON_LOGGER_ENDL;
1441  } catch (const ibrcommon::Exception &ex) {
1442  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add HTTP ConvergenceLayer, Server: " << net.url << ": " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1443  }
1444  break;
1445  }
1446 #endif
1447 
1448 #ifdef IBRCOMMON_SUPPORT_LOWPAN
1450  {
1451  try {
1452  _components[RUNLEVEL_NETWORK].push_back( new LOWPANConvergenceLayer( net.iface, static_cast<uint16_t>(net.port) ) );
1453  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "LOWPAN ConvergenceLayer added on " << net.iface.toString() << ":" << net.port << IBRCOMMON_LOGGER_ENDL;
1454  } catch (const ibrcommon::Exception &ex) {
1455  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add LOWPAN ConvergenceLayer on " << net.iface.toString() << ": " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1456  }
1457 
1458  break;
1459  }
1460 
1462  {
1463  try {
1464  LOWPANDatagramService *lowpan_service = new LOWPANDatagramService( net.iface, static_cast<uint16_t>(net.port) );
1465  _components[RUNLEVEL_NETWORK].push_back( new DatagramConvergenceLayer(lowpan_service) );
1466  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Datagram ConvergenceLayer (LowPAN) added on " << net.iface.toString() << ":" << net.port << IBRCOMMON_LOGGER_ENDL;
1467  } catch (const ibrcommon::Exception &ex) {
1468  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add Datagram ConvergenceLayer (LowPAN) on " << net.iface.toString() << ": " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1469  }
1470  break;
1471  }
1472 #endif
1473 
1475  {
1476  try {
1477  UDPDatagramService *dgram_service = new UDPDatagramService( net.iface, net.port, net.mtu );
1478  _components[RUNLEVEL_NETWORK].push_back( new DatagramConvergenceLayer(dgram_service) );
1479  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Datagram ConvergenceLayer (UDP) added on " << net.iface.toString() << ":" << net.port << IBRCOMMON_LOGGER_ENDL;
1480  } catch (const ibrcommon::Exception &ex) {
1481  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add Datagram ConvergenceLayer (UDP) on " << net.iface.toString() << ": " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1482  }
1483  break;
1484  }
1485 
1486 #ifdef HAVE_VMIME
1488  {
1489  try {
1490  _components[RUNLEVEL_NETWORK].push_back( new EMailConvergenceLayer() );
1491  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "EMail Convergence Layer (MCL) added" << IBRCOMMON_LOGGER_ENDL;
1492  }catch(const ibrcommon::Exception &ex) {
1493  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Failed to add EMail Convergence Layer (MCL): " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1494  }
1495  break;
1496  }
1497 #endif
1498 
1499  default:
1500  break;
1501  }
1502  } catch (const std::exception &ex) {
1503  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Error: " << ex.what() << IBRCOMMON_LOGGER_ENDL;
1504  }
1505  }
1506 
1507  /****
1508  * Init DHT
1509  */
1510 
1511 #ifdef WITH_DHT_NAMESERVICE
1512  // create dht naming service if configured
1513  if (conf.getDHT().enabled()) {
1514  IBRCOMMON_LOGGER_DEBUG_TAG(NativeDaemon::TAG, 50) << "DHT: is enabled!" << IBRCOMMON_LOGGER_ENDL;
1515  _components[RUNLEVEL_NETWORK].push_back( new dtn::dht::DHTNameService() );
1516  }
1517 #endif
1518 
1519 #ifdef WITH_WIFIP2P
1520  if (conf.getP2P().enabled())
1521  {
1522  const std::string wifip2p_ctrlpath = conf.getP2P().getCtrlPath();
1523 
1524  // create a wifi-p2p manager
1525  _components[RUNLEVEL_NETWORK].push_back( new dtn::net::WifiP2PManager(wifip2p_ctrlpath) );
1526  }
1527 #endif
1528 
1529  /***
1530  * Init Discovery
1531  */
1532  if (conf.getDiscovery().enabled())
1533  {
1534  // get the discovery port
1535  int disco_port = conf.getDiscovery().port();
1536 
1537  // create the IPND agent
1538  dtn::net::IPNDAgent *ipnd = new dtn::net::IPNDAgent( disco_port );
1539 
1540  try {
1541  const std::set<ibrcommon::vaddress> addr = conf.getDiscovery().address();
1542  for (std::set<ibrcommon::vaddress>::const_iterator iter = addr.begin(); iter != addr.end(); ++iter) {
1543  ipnd->add(*iter);
1544  }
1546  // by default set multicast equivalent of broadcast
1547  if (ibrcommon::basesocket::hasSupport(AF_INET6))
1548  ipnd->add(ibrcommon::vaddress("ff02::142", disco_port, AF_INET6));
1549 
1550  if (ibrcommon::basesocket::hasSupport(AF_INET))
1551  ipnd->add(ibrcommon::vaddress("224.0.0.142", disco_port, AF_INET));
1552  }
1553 
1554  // add all CL interfaces to discovery
1555  for (std::list<dtn::daemon::Configuration::NetConfig>::const_iterator iter = nets.begin(); iter != nets.end(); ++iter)
1556  {
1557  const dtn::daemon::Configuration::NetConfig &net = (*iter);
1558  if (!net.iface.empty())
1559  ipnd->bind(net.iface);
1560  }
1561 
1562  _components[RUNLEVEL_NETWORK].push_back(ipnd);
1563  }
1564  else
1565  {
1566  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Discovery disabled" << IBRCOMMON_LOGGER_ENDL;
1567  }
1568 
1572  component_list &clist = _components[RUNLEVEL_NETWORK];
1573  for (component_list::iterator it = clist.begin(); it != clist.end(); ++it)
1574  {
1575  try {
1576  ConvergenceLayer *cl = dynamic_cast<ConvergenceLayer*>(*it);
1577  if (cl != NULL) {
1578  core.getConnectionManager().add(cl);
1579  }
1580  } catch (const std::bad_cast&) { }
1581  }
1582 
1583  // announce static nodes, create a list of static nodes
1584  const std::list<Node> &static_nodes = conf.getNetwork().getStaticNodes();
1585 
1586  for (list<Node>::const_iterator iter = static_nodes.begin(); iter != static_nodes.end(); ++iter)
1587  {
1588  core.getConnectionManager().add(*iter);
1589  }
1590  }
1591 
1592  void NativeDaemon::shutdown_network() throw (NativeDaemonException)
1593  {
1596 
1597  // announce static nodes, create a list of static nodes
1598  const std::list<Node> &static_nodes = conf.getNetwork().getStaticNodes();
1599 
1600  for (list<Node>::const_iterator iter = static_nodes.begin(); iter != static_nodes.end(); ++iter)
1601  {
1602  core.getConnectionManager().remove(*iter);
1603  }
1604 
1608  component_list &clist = _components[RUNLEVEL_NETWORK];
1609  for (component_list::iterator it = clist.begin(); it != clist.end(); ++it)
1610  {
1611  try {
1612  ConvergenceLayer *cl = dynamic_cast<ConvergenceLayer*>(*it);
1613  if (cl != NULL) {
1614  core.getConnectionManager().remove(cl);
1615  }
1616  } catch (const std::bad_cast&) { }
1617  }
1618  }
1619 
1620  void NativeDaemon::init_routing_extensions() throw (NativeDaemonException)
1621  {
1624 
1625  // add static routing extension
1626  router.add( new dtn::routing::StaticRoutingExtension() );
1627 
1628  // add other routing extensions depending on the configuration
1629  switch (conf.getNetwork().getRoutingExtension())
1630  {
1632  {
1633  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Using flooding routing extensions" << IBRCOMMON_LOGGER_ENDL;
1634  router.add( new dtn::routing::FloodRoutingExtension() );
1635 
1636  // add neighbor routing (direct-delivery) extension
1638  break;
1639  }
1640 
1642  {
1643  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Using epidemic routing extensions" << IBRCOMMON_LOGGER_ENDL;
1645 
1646  // add neighbor routing (direct-delivery) extension
1648  break;
1649  }
1650 
1652  {
1654  std::string strategy_name = prophet_config.forwarding_strategy;
1655  dtn::routing::ForwardingStrategy *forwarding_strategy;
1656  if(strategy_name == "GRTR"){
1657  forwarding_strategy = new dtn::routing::ProphetRoutingExtension::GRTR_Strategy();
1658  }
1659  else if(strategy_name == "GTMX"){
1660  forwarding_strategy = new dtn::routing::ProphetRoutingExtension::GTMX_Strategy(prophet_config.gtmx_nf_max);
1661  }
1662  else{
1663  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, error) << "Prophet forwarding strategy " << strategy_name << " not found. Using GRTR as fallback." << IBRCOMMON_LOGGER_ENDL;
1664  forwarding_strategy = new dtn::routing::ProphetRoutingExtension::GRTR_Strategy();
1665  }
1666  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Using prophet routing extensions with " << strategy_name << " as forwarding strategy." << IBRCOMMON_LOGGER_ENDL;
1667  router.add( new dtn::routing::ProphetRoutingExtension(forwarding_strategy, prophet_config.p_encounter_max,
1668  prophet_config.p_encounter_first, prophet_config.p_first_threshold,
1669  prophet_config.beta, prophet_config.gamma, prophet_config.delta,
1670  prophet_config.time_unit, prophet_config.i_typ,
1671  prophet_config.next_exchange_timeout));
1672 
1673  // add neighbor routing (direct-delivery) extension
1675  break;
1676  }
1677 
1679  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Dynamic routing extensions disabled" << IBRCOMMON_LOGGER_ENDL;
1680  break;
1681 
1682  default:
1683  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "Using default routing extensions" << IBRCOMMON_LOGGER_ENDL;
1684 
1685  // add neighbor routing (direct-delivery) extension
1687  break;
1688  }
1689 
1690  // initialize all routing extensions
1691  router.extensionsUp();
1692  }
1693 
1694  void NativeDaemon::shutdown_routing_extensions() const throw (NativeDaemonException)
1695  {
1697 
1698  // disable all routing extensions
1699  router.extensionsDown();
1700 
1701  // delete all routing extensions
1702  router.clearExtensions();
1703  }
1704 
1708  void NativeDaemon::reload() throw ()
1709  {
1710  // reload logger
1711  ibrcommon::Logger::reload();
1712 
1713  // send reload signal to all modules
1715  }
1716 
1720  void NativeDaemon::setDebug(int level) throw ()
1721  {
1722  // activate debugging
1723  ibrcommon::Logger::setVerbosity(level);
1724  IBRCOMMON_LOGGER_TAG(NativeDaemon::TAG, info) << "debug level set to " << level << IBRCOMMON_LOGGER_ENDL;
1725  }
1726 
1728  : _daemon(daemon)
1729  {
1730  }
1731 
1733  {
1734  }
1735 
1736  void NativeEventLoop::run(void) throw ()
1737  {
1739 
1740  // create the event switch object
1742 
1743  // run the event switch loop forever
1744  if (conf.getDaemon().getThreads() > 1)
1745  {
1746  esw.loop( conf.getDaemon().getThreads(), conf.getDebug().profiling() );
1747  }
1748  else
1749  {
1750  esw.loop(0, conf.getDebug().profiling());
1751  }
1752 
1753  // terminate event switch component
1754  esw.terminate();
1755  }
1756 
1758  {
1761  }
1762  } /* namespace daemon */
1763 } /* namespace dtn */
void add(RoutingExtension *extension)
Definition: BaseRouter.cpp:73
void initiateConnection(std::string eid) const
static Configuration & getInstance(bool reset=false)
static SecurityKeyManager & getInstance()
static EventSwitch & getInstance()
const std::set< dtn::core::Node > getNeighbors()
NativeEventLoop(NativeDaemon &daemon)
void onKeyExchangeBegin(std::string eid, int protocol, std::string password) const
const unsigned char logsys
Definition: Main.cpp:64
const std::list< NetConfig > & getInterfaces() const
Bitset< FLAGS > procflags
Definition: PrimaryBlock.h:118
void wait(DaemonRunLevel rl)
static dtn::data::EID local
Definition: BundleCore.h:79
const Configuration::Security & getSecurity() const
const Configuration::Discovery & getDiscovery() const
dtn::data::Size getThreads() const
bool get(dtn::data::PrimaryBlock::FLAGS flag) const
Definition: MetaBundle.cpp:160
static void add(EventReceiver< E > *receiver)
The GRTR forwarding strategy. Using this strategy, packets are forwarding, if the neighbor has a high...
dtn::data::Length size() const
This class is a manager to handle certificates.
void setLogging(const std::string &defaultTag, int logLevel) const
const Configuration::Logger & getLogger() const
void attach(dtn::storage::BundleIndex *index)
dtn::routing::BaseRouter & getRouter() const
Definition: BundleCore.cpp:227
std::vector< std::string > getVersion() const
void setConfigFile(const std::string &config_file)
void setSeeker(dtn::storage::BundleSeeker *seeker)
Definition: BundleCore.cpp:217
void setGloballyConnected(bool val)
Definition: BundleCore.cpp:790
std::pair< string, string > stats_pair
void remove(const dtn::core::Node &n)
dtn::data::Timestamp timestamp
Definition: BundleID.h:54
virtual dtn::data::Size count()
void add(const ibrcommon::vaddress &address)
Definition: IPNDAgent.cpp:68
void removeConnection(std::string eid, std::string protocol, std::string address, std::string service, bool local=false) const
Configuration::NetConfig getAPIInterface() const
void addData(const std::string &tag, const std::string &data)
Definition: NativeDaemon.h:145
void setSessionId(unsigned int sessionId)
void addConnection(std::string eid, std::string protocol, std::string address, std::string service, bool local=false) const
static void remove(const EventReceiver< E > *receiver)
void getStats(dtn::net::ConvergenceLayer::stats_data &data)
DaemonRunLevel getRunLevel() const
void removeKey(std::string eid) const
#define VERSION
Definition: config.h:121
const std::string getCtrlPath() const
NativeNode getInfo(const std::string &neighbor_eid) const
virtual void raiseEvent(const dtn::core::NodeEvent &evt)
dtn::net::ConnectionManager & getConnectionManager()
Definition: BundleCore.cpp:260
const ibrcommon::File & getLogfile() const
NativeDaemon(NativeDaemonCallback *statecb=NULL, NativeEventCallback *eventcb=NULL)
virtual dtn::data::Length getPayloadLength() const
Definition: BundleID.cpp:112
RoutingExtension getRoutingExtension() const
void watch(const ibrcommon::File &watch)
This class is a abstract base class for all prophet forwarding strategies.
const Configuration::P2P & getP2P() const
const Configuration::Network & getNetwork() const
dtn::data::Number sequencenumber
Definition: BundleID.h:55
bool get(FLAGS flag) const
void add(const dtn::core::Node &n)
dtn::data::Size getLimit(const std::string &) const
const Configuration::DHT & getDHT() const
void load(bool quiet=false)
ibrcommon::File getPath(string name) const
std::string getLocalUri() const
std::string toString() const
Definition: SDNV.h:414
static void raise(const Action a)
Definition: GlobalEvent.cpp:79
virtual const std::string getData() const
Definition: SecurityKey.cpp:64
const Configuration::Debug & getDebug() const
void setLogFile(const std::string &path, int logLevel) const
void onKeyExchangeResponse(std::string eid, int protocol, int session, int step, std::string data) const
T get() const
Definition: SDNV.h:113
void add(const ibrcommon::vinterface &net, int port)
static dtn::data::Timestamp getUptime()
Definition: Clock.cpp:284
static double toDouble(const timeval &val)
Definition: Clock.cpp:280
unsigned char logopts
Definition: Main.cpp:55
The GTMX forwarding strategy. Using this strategy, packets are forwarding, if the neighbor has a high...
std::map< string, string > stats_data
void setGloballyConnected(bool connected) const
void remove(const SecurityKey &key)
std::string version() const
static dtn::data::Timestamp getTime()
Definition: Clock.cpp:167
const std::list< Node > & getStaticNodes() const
dtn::data::EID destination
Definition: MetaBundle.h:60
void add(const URI &u)
Definition: Node.cpp:280
void loop(size_t threads, bool profiling=false)
ProphetConfig getProphetConfig() const
#define BUILD_NUMBER
Definition: config.h:8
dtn::security::SecurityKey get(const dtn::data::EID &ref, const dtn::security::SecurityKey::KeyType type=dtn::security::SecurityKey::KEY_UNSPEC) const
void setStorage(dtn::storage::BundleStorage *storage)
Definition: BundleCore.cpp:212
ibrcommon::File blob_path("/tmp")
static const struct timeval & getOffset()
Definition: Clock.cpp:182
dtn::data::EID reference
Definition: SecurityKey.h:74
dtn::data::SDNV< unsigned int > flags
Definition: SecurityKey.h:86
std::string getStorage() const
virtual const std::string getFingerprint() const
Bitset< dtn::data::PrimaryBlock::FLAGS > procflags
Definition: MetaBundle.h:64
virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf)
Definition: BundleCore.cpp:140
static double getRating()
Definition: Clock.cpp:59
std::string getString() const
Definition: EID.cpp:374
bool getUsePersistentBundleSets() const
const dtn::data::EID & getEID() const
Definition: Node.cpp:406
dtn::storage::BundleStorage & getStorage()
Definition: BundleCore.cpp:237
void init(DaemonRunLevel rl)
const Configuration::Daemon & getDaemon() const
ibrcommon::File getAPISocket() const
std::list< Node::URI > getAll() const
Definition: Node.cpp:372
dtn::data::Number fragmentoffset
Definition: BundleID.h:57
static void setPath(const ibrcommon::File &path)
Routing extension for PRoPHET routing.
virtual bool isFragment() const
Definition: BundleID.cpp:122
const dtn::core::Node getNeighbor(const dtn::data::EID &eid)
void open(const dtn::core::Node &node)
bool doTLS() const
checks if TLS shall be activated
dtn::data::EID source
Definition: BundleID.h:53
void setLeMode(bool low_energy) const
const std::set< ibrcommon::vaddress > address() const
std::vector< std::string > getNeighbors() const
void bind(const ibrcommon::vinterface &net)
Definition: IPNDAgent.cpp:73
NativeKeyInfo getKeyInfo(std::string eid) const
static BundleCore & getInstance()
Definition: BundleCore.cpp:82
virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf)
static void raise(const dtn::data::EID &eid, const dtn::security::KeyExchangeData &data)