IBR-DTNSuite  0.12
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 
26 #include "core/Node.h"
28 #include <ibrcommon/Exceptions.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;
81  int mtu;
82  int port;
83  };
84 
86  {
87  };
88 
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 _timeout;
176 
177  public:
178  bool enabled() const;
179  bool announce() const;
180  bool shortbeacon() const;
181  int version() const;
182  const std::set<ibrcommon::vaddress> address() const throw (ParameterNotFoundException);
183  int port() const;
184  unsigned int timeout() const;
185  bool enableCrosslayer() const;
186  };
187 
188  class Debug : public Configuration::Extension
189  {
190  friend class Configuration;
191  protected:
192  Debug();
193  virtual ~Debug();
194  void load(const ibrcommon::ConfigFile &conf);
195 
196  bool _enabled;
197  bool _quiet;
198  int _level;
199 
200  public:
204  int level() const;
205 
209  bool enabled() const;
210 
215  bool quiet() const;
216  };
217 
219  {
220  friend class Configuration;
221  protected:
222  Logger();
223  virtual ~Logger();
224  void load(const ibrcommon::ConfigFile &conf);
225 
226  bool _quiet;
227  unsigned int _options;
230  bool _verbose;
231 
232  public:
237  bool quiet() const;
238 
243  const ibrcommon::File& getLogfile() const;
244 
254  unsigned int options() const;
255 
259  std::ostream &output() const;
260 
264  bool display_timestamps() const;
265 
269  bool verbose() const;
270  };
271 
273  {
274  friend class Configuration;
275  public:
276  /* prophet routing parameters */
278  public:
280  : p_encounter_max(0), p_encounter_first(0), p_first_threshold(0), beta(0), gamma(0), delta(0),
281  time_unit(0), i_typ(0), next_exchange_timeout(0), forwarding_strategy(), gtmx_nf_max(0)
282  { }
283 
285 
289  float beta;
290  float gamma;
291  float delta;
295  std::string forwarding_strategy;
296  unsigned int gtmx_nf_max;
297  };
298  protected:
299  Network();
300  virtual ~Network();
301  void load(const ibrcommon::ConfigFile &conf);
302 
303  std::multimap<std::string, std::string> _static_routes;
304  std::list<Node> _nodes;
305  std::list<NetConfig> _interfaces;
306  std::string _routing;
318  std::set<ibrcommon::vinterface> _internet_devices;
320 
321  public:
325  const std::list<NetConfig>& getInterfaces() const;
326 
330  const std::list<Node>& getStaticNodes() const;
331 
335  const std::multimap<std::string, std::string>& getStaticRoutes() const;
336 
340  RoutingExtension getRoutingExtension() const;
341 
346  bool doForwarding() const;
347 
353  bool doPreferDirect() const;
354 
358  bool getTCPOptionNoDelay() const;
359 
363  dtn::data::Length getTCPChunkSize() const;
364 
368  dtn::data::Timeout getTCPIdleTimeout() const;
369 
373  dtn::data::Timeout getAutoConnect() const;
374 
378  bool doFragmentation() const;
379 
383  ProphetConfig getProphetConfig() const;
384 
388  bool doScheduling() const;
389 
393  std::set<ibrcommon::vinterface> getInternetDevices() const;
394 
398  size_t getLinkRequestInterval() const;
399  };
400 
402  {
403  friend class Configuration;
404  private:
405  bool _enabled;
406  bool _tlsEnabled;
407  bool _tlsRequired;
408  bool _tlsOptionalOnBadClock;
409 
410  protected:
411  Security();
412  virtual ~Security();
413  void load(const ibrcommon::ConfigFile &conf);
414 
415  public:
416  bool enabled() const;
417 
424  bool doTLS() const;
425 
431  bool TLSRequired() const;
432 
433  enum Level
434  {
435  SECURITY_LEVEL_NONE = 0,
436  SECURITY_LEVEL_AUTHENTICATED = 1,
437  SECURITY_LEVEL_ENCRYPTED = 2,
438  SECURITY_LEVEL_SIGNED = 4
439  };
440 
444  int getLevel() const;
445 
449  const ibrcommon::File& getPath() const;
450 
454  const ibrcommon::File& getBABDefaultKey() const;
455 
459  const ibrcommon::File& getCertificate() const;
460 
464  const ibrcommon::File& getKey() const;
465 
470  const ibrcommon::File& getTrustedCAPath() const;
471 
476  bool TLSEncryptionDisabled() const;
477 
478  private:
479  // security related files
480  ibrcommon::File _path;
481 
482  // security level
483  int _level;
484 
485  // local BAB key
486  ibrcommon::File _bab_default_key;
487 
488  // TLS certificate
489  ibrcommon::File _cert;
490 
491  // TLS private key
492  ibrcommon::File _key;
493 
494  // TLS trusted CA path
495  ibrcommon::File _trustedCAPath;
496 
497  // TLS encryption disabled?
498  bool _disableEncryption;
499  };
500 
502  {
503  friend class Configuration;
504  private:
505  bool _daemonize;
506  ibrcommon::File _pidfile;
507  bool _kill;
508  dtn::data::Size _threads;
509 
510  protected:
511  Daemon();
512  virtual ~Daemon();
513  void load(const ibrcommon::ConfigFile &conf);
514 
515  public:
516  bool daemonize() const;
517  const ibrcommon::File& getPidFile() const;
518  bool kill_daemon() const;
519  dtn::data::Size getThreads() const;
520  };
521 
523  {
524  friend class Configuration;
525  protected:
526  TimeSync();
527  virtual ~TimeSync();
528  void load(const ibrcommon::ConfigFile &conf);
529 
531  bool _sync;
533  float _sigma;
534  float _psi;
535  float _sync_level;
536 
537  public:
538  bool hasReference() const;
539  bool doSync() const;
540  bool sendDiscoveryBeacons() const;
541 
542  float getSigma() const;
543  float getPsi() const;
544  float getSyncLevel() const;
545  };
546 
548  {
549  friend class Configuration;
550  protected:
551  DHT();
552  virtual ~DHT();
553  void load(const ibrcommon::ConfigFile &conf);
554 
555  private:
556  bool _enabled;
557  int _port;
558  string _id;
559  string _ipv4bind;
560  string _ipv6bind;
561  std::vector<string> _bootstrappingdomains;
562  bool _dnsbootstrapping;
563  std::vector<string> _bootstrappingips;
564  string _nodesFilePath;
565  bool _ipv4;
566  bool _ipv6;
567  bool _blacklist;
568  bool _selfannounce;
569  std::vector<int> _portFilter;
570  int _minRating;
571  bool _allowNeighbourToAnnounceMe;
572  bool _allowNeighbourAnnouncement;
573  bool _ignoreDHTNeighbourInformations;
574 
575  public:
579  bool enabled() const;
580 
584  bool randomPort() const;
585 
589  unsigned int getPort() const;
590 
594  string getID() const;
595 
599  bool randomID() const;
600 
604  bool isDNSBootstrappingEnabled() const;
605 
609  std::vector<string> getDNSBootstrappingNames() const;
610 
614  bool isIPBootstrappingEnabled() const;
615 
619  std::vector<string> getIPBootstrappingIPs() const;
620 
624  string getIPv4Binding() const;
625 
629  string getIPv6Binding() const;
630 
638  string getPathToNodeFiles() const;
639 
643  bool isIPv4Enabled() const;
644 
648  bool isIPv6Enabled() const;
649 
653  std::vector<int> getPortFilter() const;
654 
658  bool isBlacklistEnabled() const;
659 
663  bool isSelfAnnouncingEnabled() const;
664 
668  int getMinimumRating() const;
669 
673  bool isNeighbourAnnouncementEnabled() const;
674 
678  bool isNeighbourAllowedToAnnounceMe() const;
679 
689  bool ignoreDHTNeighbourInformations() const;
690  };
691 
693  {
694  friend class Configuration;
695  protected:
696  P2P();
697  virtual ~P2P();
698  void load(const ibrcommon::ConfigFile &conf);
699 
700  std::string _ctrl_path;
701  bool _enabled;
702 
703  public:
704  const std::string getCtrlPath() const;
705  bool enabled() const;
706  };
707 
709  {
710  friend class Configuration;
711  protected:
712  EMail();
713  virtual ~EMail();
714  void load(const ibrcommon::ConfigFile &conf);
715  private:
716  std::string _address;
717  std::string _smtpServer;
718  int _smtpPort;
719  std::string _smtpUsername;
720  std::string _smtpPassword;
721  bool _smtpUseTLS;
722  bool _smtpUseSSL;
723  bool _smtpNeedAuth;
724  size_t _smtpInterval;
725  size_t _smtpConnectionTimeout;
726  size_t _smtpKeepAliveTimeout;
727  std::string _imapServer;
728  int _imapPort;
729  std::string _imapUsername;
730  std::string _imapPassword;
731  bool _imapUseTLS;
732  bool _imapUseSSL;
733  std::vector<std::string> _imapFolder;
734  size_t _imapInterval;
735  size_t _imapConnectionTimeout;
736  bool _imapPurgeMail;
737  std::vector<std::string> _tlsCACerts;
738  std::vector<std::string> _tlsUserCerts;
739  size_t _availableTime;
740  size_t _returningMailsCheck;
741 
742  public:
749  std::string getOwnAddress() const;
750 
757  std::string getSmtpServer() const;
758 
765  int getSmtpPort() const;
766 
773  std::string getSmtpUsername() const;
774 
781  std::string getSmtpPassword() const;
782 
791  size_t getSmtpSubmitInterval() const;
792 
796  size_t getSmtpConnectionTimeout() const;
797 
806  size_t getSmtpKeepAliveTimeout() const;
807 
812  bool smtpAuthenticationNeeded() const;
813 
818  bool smtpUseTLS() const;
819 
824  bool smtpUseSSL() const;
825 
832  std::string getImapServer() const;
833 
840  int getImapPort() const;
841 
848  std::string getImapUsername() const;
849 
856  std::string getImapPassword() const;
857 
865  std::vector<std::string> getImapFolder() const;
866 
875  size_t getImapLookupInterval() const;
876 
880  size_t getImapConnectionTimeout() const;
881 
886  bool imapUseTLS() const;
887 
892  bool imapUseSSL() const;
893 
897  bool imapPurgeMail() const;
898 
903  std::vector<std::string> getTlsCACerts() const;
904 
909  std::vector<std::string> getTlsUserCerts() const;
910 
915  size_t getNodeAvailableTime() const;
916 
920  size_t getReturningMailChecks() const;
921  };
922 
923  const Configuration::Discovery& getDiscovery() const;
924  const Configuration::Debug& getDebug() const;
925  const Configuration::Logger& getLogger() const;
926  const Configuration::Network& getNetwork() const;
927  const Configuration::Security& getSecurity() const;
928  const Configuration::Daemon& getDaemon() const;
929  const Configuration::TimeSync& getTimeSync() const;
930  const Configuration::DHT& getDHT() const;
931  const Configuration::P2P& getP2P() const;
932  const Configuration::EMail& getEMail() const;
933 
934  private:
935  ibrcommon::ConfigFile _conf;
938  Configuration::Logger _logger;
939  Configuration::Network _network;
940  Configuration::Security _security;
941  Configuration::Daemon _daemon;
942  Configuration::TimeSync _timesync;
943  Configuration::DHT _dht;
944  Configuration::P2P _p2p;
945  Configuration::EMail _email;
946 
947  std::string _filename;
948  bool _doapi;
949  };
950  }
951 }
952 
953 #endif /*CONFIGURATION_H_*/