IBR-DTN  1.0.0
Configuration.h
Go to the documentation of this file.
1 /*
2  * Configuration.h
3  *
4  * Copyright (C) 2011 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 #ifndef CONFIGURATION_H_
23 #define CONFIGURATION_H_
24 
25 #include "ibrcommon/data/ConfigFile.h"
26 #include "core/Node.h"
28 #include <ibrcommon/Exceptions.h>
29 #include <ibrcommon/net/vinterface.h>
30 #include <map>
31 #include <list>
32 #include <ibrcommon/thread/Timer.h>
33 
34 using namespace dtn::net;
35 using namespace dtn::core;
36 using namespace dtn::data;
37 
38 namespace dtn
39 {
40  namespace daemon
41  {
46  {
47  private:
48  Configuration();
49  virtual ~Configuration();
50 
51  public:
53  public:
54  virtual void onConfigurationChanged(const dtn::daemon::Configuration &conf) throw () = 0;
55  };
56 
57  class NetConfig
58  {
59  public:
60  enum NetType
61  {
62  NETWORK_UNKNOWN = 0,
63  NETWORK_TCP = 1,
64  NETWORK_UDP = 2,
65  NETWORK_HTTP = 3,
66  NETWORK_LOWPAN = 4,
67  NETWORK_FILE = 5,
68  NETWORK_DGRAM_UDP = 6,
69  NETWORK_DGRAM_LOWPAN = 7,
70  NETWORK_DGRAM_ETHERNET = 8,
71  NETWORK_EMAIL = 9
72  };
73 
74  NetConfig(const std::string &name, NetType type);
75  virtual ~NetConfig();
76 
77  std::string name;
79  std::string url;
80  ibrcommon::vinterface iface;
81  int mtu;
82  int port;
83  };
84 
85  class ParameterNotSetException : ibrcommon::Exception
86  {
87  };
88 
89  class ParameterNotFoundException : ibrcommon::Exception
90  {
91  };
92 
93  static Configuration &getInstance(bool reset = false);
94 
98  void load(bool quiet = false);
99  void load(const std::string &filename, bool quiet = false);
100 
101  void params(int argc, char *argv[]);
102 
106  std::string getNodename() const;
107 
114  ibrcommon::File getPath(string name) const;
115 
120  bool doAPI() const;
121 
122  Configuration::NetConfig getAPIInterface() const;
123  ibrcommon::File getAPISocket() const;
124 
129  std::string version() const;
130 
135  std::string getStorage() const;
136 
141  bool getUsePersistentBundleSets() const;
142 
144  {
145  DEFAULT_ROUTING = 0,
146  EPIDEMIC_ROUTING = 1,
147  FLOOD_ROUTING = 2,
148  PROPHET_ROUTING = 3,
149  NO_ROUTING = 4
150  };
151 
157  dtn::data::Size getLimit(const std::string&) const;
158 
159  class Extension
160  {
161  protected:
162  virtual void load(const ibrcommon::ConfigFile &conf) = 0;
163  };
164 
166  {
167  friend class Configuration;
168  protected:
169  Discovery();
170  virtual ~Discovery();
171  void load(const ibrcommon::ConfigFile &conf);
172 
173  bool _enabled;
174  unsigned int _interval;
175  bool _announce;
176  bool _short;
177  int _version;
179 
180  public:
181  bool enabled() const;
182  bool announce() const;
183  bool shortbeacon() const;
184  int version() const;
185  const std::set<ibrcommon::vaddress> address() const throw (ParameterNotFoundException);
186  int port() const;
187  unsigned int interval() const;
188  bool enableCrosslayer() const;
189  };
190 
191  class Debug : public Configuration::Extension
192  {
193  friend class Configuration;
194  protected:
195  Debug();
196  virtual ~Debug();
197  void load(const ibrcommon::ConfigFile &conf);
198 
199  bool _enabled;
200  bool _quiet;
201  int _level;
203 
204  public:
208  int level() const;
209 
213  bool enabled() const;
214 
219  bool quiet() const;
220 
225  bool profiling() const;
226  };
227 
229  {
230  friend class Configuration;
231  protected:
232  Logger();
233  virtual ~Logger();
234  void load(const ibrcommon::ConfigFile &conf);
235 
236  bool _quiet;
237  unsigned int _options;
239  ibrcommon::File _logfile;
240  bool _verbose;
241 
242  public:
247  bool quiet() const;
248 
253  const ibrcommon::File& getLogfile() const;
254 
264  unsigned int options() const;
265 
269  std::ostream &output() const;
270 
274  bool display_timestamps() const;
275 
279  bool verbose() const;
280  };
281 
283  {
284  friend class Configuration;
285  public:
286  /* prophet routing parameters */
288  public:
290  : p_encounter_max(0), p_encounter_first(0), p_first_threshold(0), beta(0), gamma(0), delta(0),
291  time_unit(0), i_typ(0), next_exchange_timeout(0), forwarding_strategy(), gtmx_nf_max(0)
292  { }
293 
295 
299  float beta;
300  float gamma;
301  float delta;
302  ibrcommon::Timer::time_t time_unit;
303  ibrcommon::Timer::time_t i_typ;
304  ibrcommon::Timer::time_t next_exchange_timeout;
305  std::string forwarding_strategy;
306  unsigned int gtmx_nf_max;
307  };
308  protected:
309  Network();
310  virtual ~Network();
311  void load(const ibrcommon::ConfigFile &conf);
312 
313  std::multimap<std::string, std::string> _static_routes;
314  std::list<Node> _nodes;
315  std::list<NetConfig> _interfaces;
316  std::string _routing;
323  ibrcommon::vinterface _default_net;
329  std::set<ibrcommon::vinterface> _internet_devices;
332 
333  public:
337  const std::list<NetConfig>& getInterfaces() const;
338 
342  const std::list<Node>& getStaticNodes() const;
343 
347  const std::multimap<std::string, std::string>& getStaticRoutes() const;
348 
352  RoutingExtension getRoutingExtension() const;
353 
358  bool doForwarding() const;
359 
365  bool doPreferDirect() const;
366 
370  bool getTCPOptionNoDelay() const;
371 
375  dtn::data::Length getTCPChunkSize() const;
376 
380  dtn::data::Timeout getTCPIdleTimeout() const;
381 
385  dtn::data::Timeout getKeepaliveInterval() const;
386 
390  dtn::data::Timeout getAutoConnect() const;
391 
395  bool doFragmentation() const;
396 
400  ProphetConfig getProphetConfig() const;
401 
405  bool doScheduling() const;
406 
410  std::set<ibrcommon::vinterface> getInternetDevices() const;
411 
415  size_t getLinkRequestInterval() const;
416  };
417 
419  {
420  friend class Configuration;
421  private:
422  bool _enabled;
423  bool _tlsEnabled;
424  bool _tlsRequired;
425  bool _tlsOptionalOnBadClock;
426  bool _generate_dh_params;
427 
428  protected:
429  Security();
430  virtual ~Security();
431  void load(const ibrcommon::ConfigFile &conf);
432 
433  public:
434  bool enabled() const;
435 
442  bool doTLS() const;
443 
449  bool TLSRequired() const;
450 
451  enum Level
452  {
453  SECURITY_LEVEL_NONE = 0,
454  SECURITY_LEVEL_AUTHENTICATED = 1,
455  SECURITY_LEVEL_ENCRYPTED = 2,
456  SECURITY_LEVEL_SIGNED = 4
457  };
458 
462  int getLevel() const;
463 
467  const ibrcommon::File& getPath() const;
468 
472  const ibrcommon::File& getBABDefaultKey() const;
473 
477  const ibrcommon::File& getCertificate() const;
478 
482  const ibrcommon::File& getKey() const;
483 
488  const ibrcommon::File& getTrustedCAPath() const;
489 
494  bool TLSEncryptionDisabled() const;
495 
500  bool isGenerateDHParamsEnabled() const;
501 
502  private:
503  // security related files
504  ibrcommon::File _path;
505 
506  // security level
507  int _level;
508 
509  // local BAB key
510  ibrcommon::File _bab_default_key;
511 
512  // TLS certificate
513  ibrcommon::File _cert;
514 
515  // TLS private key
516  ibrcommon::File _key;
517 
518  // TLS trusted CA path
519  ibrcommon::File _trustedCAPath;
520 
521  // TLS encryption disabled?
522  bool _disableEncryption;
523  };
524 
526  {
527  friend class Configuration;
528  private:
529  bool _daemonize;
530  ibrcommon::File _pidfile;
531  bool _kill;
532  dtn::data::Size _threads;
533 
534  protected:
535  Daemon();
536  virtual ~Daemon();
537  void load(const ibrcommon::ConfigFile &conf);
538 
539  public:
540  bool daemonize() const;
541  const ibrcommon::File& getPidFile() const;
542  bool kill_daemon() const;
543  dtn::data::Size getThreads() const;
544  };
545 
547  {
548  friend class Configuration;
549  protected:
550  TimeSync();
551  virtual ~TimeSync();
552  void load(const ibrcommon::ConfigFile &conf);
553 
555  bool _sync;
557  float _sigma;
558  float _psi;
559  float _sync_level;
560 
561  public:
562  bool hasReference() const;
563  bool doSync() const;
564  bool sendDiscoveryBeacons() const;
565 
566  float getSigma() const;
567  float getPsi() const;
568  float getSyncLevel() const;
569  };
570 
572  {
573  friend class Configuration;
574  protected:
575  DHT();
576  virtual ~DHT();
577  void load(const ibrcommon::ConfigFile &conf);
578 
579  private:
580  bool _enabled;
581  int _port;
582  string _id;
583  string _ipv4bind;
584  string _ipv6bind;
585  std::vector<string> _bootstrappingdomains;
586  bool _dnsbootstrapping;
587  std::vector<string> _bootstrappingips;
588  string _nodesFilePath;
589  bool _ipv4;
590  bool _ipv6;
591  bool _blacklist;
592  bool _selfannounce;
593  std::vector<int> _portFilter;
594  int _minRating;
595  bool _allowNeighbourToAnnounceMe;
596  bool _allowNeighbourAnnouncement;
597  bool _ignoreDHTNeighbourInformations;
598 
599  public:
603  bool enabled() const;
604 
608  bool randomPort() const;
609 
613  unsigned int getPort() const;
614 
618  string getID() const;
619 
623  bool randomID() const;
624 
628  bool isDNSBootstrappingEnabled() const;
629 
633  std::vector<string> getDNSBootstrappingNames() const;
634 
638  bool isIPBootstrappingEnabled() const;
639 
643  std::vector<string> getIPBootstrappingIPs() const;
644 
648  string getIPv4Binding() const;
649 
653  string getIPv6Binding() const;
654 
662  string getPathToNodeFiles() const;
663 
667  bool isIPv4Enabled() const;
668 
672  bool isIPv6Enabled() const;
673 
677  std::vector<int> getPortFilter() const;
678 
682  bool isBlacklistEnabled() const;
683 
687  bool isSelfAnnouncingEnabled() const;
688 
692  int getMinimumRating() const;
693 
697  bool isNeighbourAnnouncementEnabled() const;
698 
702  bool isNeighbourAllowedToAnnounceMe() const;
703 
713  bool ignoreDHTNeighbourInformations() const;
714  };
715 
717  {
718  friend class Configuration;
719  protected:
720  P2P();
721  virtual ~P2P();
722  void load(const ibrcommon::ConfigFile &conf);
723 
724  std::string _ctrl_path;
725  bool _enabled;
726 
727  public:
728  const std::string getCtrlPath() const;
729  bool enabled() const;
730  };
731 
733  {
734  friend class Configuration;
735  protected:
736  EMail();
737  virtual ~EMail();
738  void load(const ibrcommon::ConfigFile &conf);
739  private:
740  std::string _address;
741  std::string _smtpServer;
742  int _smtpPort;
743  std::string _smtpUsername;
744  std::string _smtpPassword;
745  bool _smtpUseTLS;
746  bool _smtpUseSSL;
747  bool _smtpNeedAuth;
748  size_t _smtpInterval;
749  size_t _smtpConnectionTimeout;
750  size_t _smtpKeepAliveTimeout;
751  std::string _imapServer;
752  int _imapPort;
753  std::string _imapUsername;
754  std::string _imapPassword;
755  bool _imapUseTLS;
756  bool _imapUseSSL;
757  std::vector<std::string> _imapFolder;
758  size_t _imapInterval;
759  size_t _imapConnectionTimeout;
760  bool _imapPurgeMail;
761  std::vector<std::string> _tlsCACerts;
762  std::vector<std::string> _tlsUserCerts;
763  size_t _availableTime;
764  size_t _returningMailsCheck;
765 
766  public:
773  std::string getOwnAddress() const;
774 
781  std::string getSmtpServer() const;
782 
789  int getSmtpPort() const;
790 
797  std::string getSmtpUsername() const;
798 
805  std::string getSmtpPassword() const;
806 
815  size_t getSmtpSubmitInterval() const;
816 
820  size_t getSmtpConnectionTimeout() const;
821 
830  size_t getSmtpKeepAliveTimeout() const;
831 
836  bool smtpAuthenticationNeeded() const;
837 
842  bool smtpUseTLS() const;
843 
848  bool smtpUseSSL() const;
849 
856  std::string getImapServer() const;
857 
864  int getImapPort() const;
865 
872  std::string getImapUsername() const;
873 
880  std::string getImapPassword() const;
881 
889  std::vector<std::string> getImapFolder() const;
890 
899  size_t getImapLookupInterval() const;
900 
904  size_t getImapConnectionTimeout() const;
905 
910  bool imapUseTLS() const;
911 
916  bool imapUseSSL() const;
917 
921  bool imapPurgeMail() const;
922 
927  std::vector<std::string> getTlsCACerts() const;
928 
933  std::vector<std::string> getTlsUserCerts() const;
934 
939  size_t getNodeAvailableTime() const;
940 
944  size_t getReturningMailChecks() const;
945  };
946 
947  const Configuration::Discovery& getDiscovery() const;
948  const Configuration::Debug& getDebug() const;
949  const Configuration::Logger& getLogger() const;
950  const Configuration::Network& getNetwork() const;
951  const Configuration::Security& getSecurity() const;
952  const Configuration::Daemon& getDaemon() const;
953  const Configuration::TimeSync& getTimeSync() const;
954  const Configuration::DHT& getDHT() const;
955  const Configuration::P2P& getP2P() const;
956  const Configuration::EMail& getEMail() const;
957 
958  private:
959  ibrcommon::ConfigFile _conf;
962  Configuration::Logger _logger;
963  Configuration::Network _network;
964  Configuration::Security _security;
965  Configuration::Daemon _daemon;
966  Configuration::TimeSync _timesync;
967  Configuration::DHT _dht;
968  Configuration::P2P _p2p;
969  Configuration::EMail _email;
970 
971  std::string _filename;
972  bool _doapi;
973  };
974  }
975 }
976 
977 #endif /*CONFIGURATION_H_*/
bool _debug
Definition: Main.cpp:67
ibrcommon::vinterface _default_net
size_t Length
Definition: Number.h:33
std::list< NetConfig > _interfaces
size_t Timeout
Definition: Number.h:35
size_t Size
Definition: Number.h:34
std::set< ibrcommon::vinterface > _internet_devices
std::multimap< std::string, std::string > _static_routes