IBR-DTNSuite  0.8
daemon/src/Configuration.h
Go to the documentation of this file.
00001 #ifndef CONFIGURATION_H_
00002 #define CONFIGURATION_H_
00003 
00004 #include "ibrcommon/data/ConfigFile.h"
00005 #include "core/Node.h"
00006 #include "routing/StaticRoutingExtension.h"
00007 #include <ibrcommon/Exceptions.h>
00008 #include <ibrcommon/net/vinterface.h>
00009 #include <map>
00010 #include <list>
00011 #include <ibrcommon/thread/Timer.h>
00012 
00013 using namespace dtn::net;
00014 using namespace dtn::core;
00015 using namespace dtn::data;
00016 
00017 namespace dtn
00018 {
00019         namespace daemon
00020         {
00024                 class Configuration
00025                 {
00026                 private:
00027                         Configuration();
00028                         virtual ~Configuration();
00029 
00030                 public:
00031                         class NetConfig
00032                         {
00033                         public:
00034                                 enum NetType
00035                                 {
00036                                         NETWORK_UNKNOWN = 0,
00037                                         NETWORK_TCP = 1,
00038                                         NETWORK_UDP = 2,
00039                                         NETWORK_HTTP = 3,
00040                                         NETWORK_LOWPAN = 4,
00041                                         NETWORK_FILE = 5,
00042                                         NETWORK_DGRAM_UDP = 6,
00043                                         NETWORK_DGRAM_LOWPAN = 7,
00044                                         NETWORK_DGRAM_ETHERNET = 8
00045                                 };
00046 
00047                                 NetConfig(std::string name, NetType type, const std::string &url, bool discovery = true);
00048                                 NetConfig(std::string name, NetType type, const ibrcommon::vaddress &address, int port, bool discovery = true);
00049                                 NetConfig(std::string name, NetType type, const ibrcommon::vinterface &iface, int port, bool discovery = true);
00050                                 NetConfig(std::string name, NetType type, int port, bool discovery = true);
00051                                 virtual ~NetConfig();
00052 
00053                                 std::string name;
00054                                 NetType type;
00055                                 std::string url;
00056                                 ibrcommon::vinterface interface;
00057                                 ibrcommon::vaddress address;
00058                                 int mtu;
00059                                 int port;
00060                                 bool discovery;
00061                         };
00062 
00063                         class ParameterNotSetException : ibrcommon::Exception
00064                         {
00065                         };
00066 
00067                         class ParameterNotFoundException : ibrcommon::Exception
00068                         {
00069                         };
00070 
00071                         static Configuration &getInstance();
00072 
00076                         void load();
00077                         void load(string filename);
00078 
00079                         void params(int argc, char *argv[]);
00080 
00084                         string getNodename();
00085 
00091                         int getTimezone();
00092 
00099                         ibrcommon::File getPath(string name);
00100 
00107                         unsigned int getUID() const;
00108 
00115                         unsigned int getGID() const;
00116 
00123                         const std::string getUser() const;
00124 
00129                         bool doAPI();
00130 
00131                         Configuration::NetConfig getAPIInterface();
00132                         ibrcommon::File getAPISocket();
00133 
00138                         std::string version();
00139 
00146                         std::string getNotifyCommand();
00147 
00152                         std::string getStorage() const;
00153 
00154                         enum RoutingExtension
00155                         {
00156                                 DEFAULT_ROUTING = 0,
00157                                 EPIDEMIC_ROUTING = 1,
00158                                 FLOOD_ROUTING = 2,
00159                                 PROPHET_ROUTING = 3
00160                         };
00161 
00167                         size_t getLimit(std::string);
00168 
00169                         class Extension
00170                         {
00171                         protected:
00172                                 virtual void load(const ibrcommon::ConfigFile &conf) = 0;
00173                         };
00174 
00175                         class Discovery : public Configuration::Extension
00176                         {
00177                                 friend class Configuration;
00178                         protected:
00179                                 Discovery();
00180                                 virtual ~Discovery();
00181                                 void load(const ibrcommon::ConfigFile &conf);
00182 
00183                                 bool _enabled;
00184                                 unsigned int _timeout;
00185 
00186                         public:
00187                                 bool enabled() const;
00188                                 bool announce() const;
00189                                 bool shortbeacon() const;
00190                                 char version() const;
00191                                 const ibrcommon::vaddress address() const throw (ParameterNotFoundException);
00192                                 int port() const;
00193                                 unsigned int timeout() const;
00194                         };
00195 
00196                         class Statistic : public Configuration::Extension
00197                         {
00198                                 friend class Configuration;
00199                         protected:
00200                                 Statistic();
00201                                 virtual ~Statistic();
00202                                 void load(const ibrcommon::ConfigFile &conf);
00203 
00204                         public:
00208                                 bool enabled() const;
00209 
00213                                 ibrcommon::File logfile() const throw (ParameterNotSetException);
00214 
00218                                 std::string type() const;
00219 
00223                                 unsigned int interval() const;
00224 
00228                                 std::string address() const;
00229 
00233                                 unsigned int port() const;
00234                         };
00235 
00236                         class Debug : public Configuration::Extension
00237                         {
00238                                 friend class Configuration;
00239                         protected:
00240                                 Debug();
00241                                 virtual ~Debug();
00242                                 void load(const ibrcommon::ConfigFile &conf);
00243 
00244                                 bool _enabled;
00245                                 bool _quiet;
00246                                 int _level;
00247 
00248                         public:
00252                                 int level() const;
00253 
00257                                 bool enabled() const;
00258 
00263                                 bool quiet() const;
00264                         };
00265 
00266                         class Logger : public Configuration::Extension
00267                         {
00268                                 friend class Configuration;
00269                         protected:
00270                                 Logger();
00271                                 virtual ~Logger();
00272                                 void load(const ibrcommon::ConfigFile &conf);
00273 
00274                                 bool _quiet;
00275                                 unsigned int _options;
00276                                 bool _timestamps;
00277                                 ibrcommon::File _logfile;
00278 
00279                         public:
00284                                 bool quiet() const;
00285 
00290                                 const ibrcommon::File& getLogfile() const;
00291 
00301                                 unsigned int options() const;
00302 
00306                                 std::ostream &output() const;
00307 
00311                                 bool display_timestamps() const;
00312                         };
00313 
00314                         class Network :  public Configuration::Extension
00315                         {
00316                                 friend class Configuration;
00317                         public:
00318                                 /* prophet routing parameters */
00319                                 struct ProphetConfig{
00320                                         float p_encounter_max;
00321                                         float p_encounter_first;
00322                                         float p_first_threshold;
00323                                         float beta;
00324                                         float gamma;
00325                                         float delta;
00326                                         ibrcommon::Timer::time_t time_unit;
00327                                         ibrcommon::Timer::time_t i_typ;
00328                                         ibrcommon::Timer::time_t next_exchange_timeout;
00329                                         std::string forwarding_strategy;
00330                                         unsigned int gtmx_nf_max;
00331                                 };
00332                         protected:
00333                                 Network();
00334                                 virtual ~Network();
00335                                 void load(const ibrcommon::ConfigFile &conf);
00336 
00337                                 std::multimap<std::string, std::string> _static_routes;
00338                                 std::list<Node> _nodes;
00339                                 std::list<NetConfig> _interfaces;
00340                                 std::string _routing;
00341                                 bool _forwarding;
00342                                 bool _tcp_nodelay;
00343                                 size_t _tcp_chunksize;
00344                                 size_t _tcp_idle_timeout;
00345                                 ibrcommon::vinterface _default_net;
00346                                 bool _use_default_net;
00347                                 bool _dynamic_rebind;
00348                                 size_t _auto_connect;
00349                                 bool _fragmentation;
00350                                 ProphetConfig _prophet_config;
00351 
00352                         public:
00356                                 const std::list<NetConfig>& getInterfaces() const;
00357 
00361                                 const std::list<Node>& getStaticNodes() const;
00362 
00366                                 const std::multimap<std::string, std::string>& getStaticRoutes() const;
00367 
00371                                 RoutingExtension getRoutingExtension() const;
00372 
00377                                 bool doForwarding() const;
00378 
00382                                 bool getTCPOptionNoDelay() const;
00383 
00387                                 size_t getTCPChunkSize() const;
00388 
00392                                 size_t getTCPIdleTimeout() const;
00393 
00397                                 bool doDynamicRebind() const;
00398 
00402                                 size_t getAutoConnect() const;
00403 
00407                                 bool doFragmentation() const;
00408 
00412                                 ProphetConfig getProphetConfig() const;
00413                         };
00414 
00415                         class Security : public Configuration::Extension
00416                         {
00417                                 friend class Configuration;
00418                         private:
00419                                 bool _enabled;
00420                                 bool _tlsEnabled;
00421                                 bool _tlsRequired;
00422                                 bool _tlsOptionalOnBadClock;
00423 
00424                         protected:
00425                                 Security();
00426                                 virtual ~Security();
00427                                 void load(const ibrcommon::ConfigFile &conf);
00428 
00429                         public:
00430                                 bool enabled() const;
00431 
00438                                 bool doTLS() const;
00439 
00445                                 bool TLSRequired() const;
00446 
00447 #ifdef WITH_BUNDLE_SECURITY
00448                                 enum Level
00449                                 {
00450                                         SECURITY_LEVEL_NONE = 0,
00451                                         SECURITY_LEVEL_AUTHENTICATED = 1,
00452                                         SECURITY_LEVEL_ENCRYPTED = 2
00453                                 };
00454 
00455                                 Level getLevel() const;
00456 
00457                                 const ibrcommon::File& getPath() const;
00458 
00459                                 const ibrcommon::File& getBABDefaultKey() const;
00460 
00461                         private:
00462                                 ibrcommon::File _path;
00463                                 Level _level;
00464                                 ibrcommon::File _bab_default_key;
00465 #endif
00466 #if defined WITH_BUNDLE_SECURITY || defined WITH_TLS
00467                         public:
00468                                 const ibrcommon::File& getCertificate() const;
00469 
00470                                 const ibrcommon::File& getKey() const;
00471                         private:
00472                                 ibrcommon::File _cert;
00473                                 ibrcommon::File _key;
00474 #endif
00475 #ifdef WITH_TLS
00476                         public:
00481                                 const ibrcommon::File& getTrustedCAPath() const;
00482 
00487                                 bool TLSEncryptionDisabled() const;
00488 
00489                         private:
00490                                 ibrcommon::File _trustedCAPath;
00491                                 bool _disableEncryption;
00492 #endif
00493                         };
00494 
00495                         class Daemon : public Configuration::Extension
00496                         {
00497                                 friend class Configuration;
00498                         private:
00499                                 bool _daemonize;
00500                                 ibrcommon::File _pidfile;
00501                                 bool _kill;
00502                                 size_t _threads;
00503 
00504                         protected:
00505                                 Daemon();
00506                                 virtual ~Daemon();
00507                                 void load(const ibrcommon::ConfigFile &conf);
00508 
00509                         public:
00510                                 bool daemonize() const;
00511                                 const ibrcommon::File& getPidFile() const;
00512                                 bool kill_daemon() const;
00513                                 size_t getThreads() const;
00514                         };
00515 
00516                         class TimeSync : public Configuration::Extension
00517                         {
00518                                 friend class Configuration;
00519                         protected:
00520                                 TimeSync();
00521                                 virtual ~TimeSync();
00522                                 void load(const ibrcommon::ConfigFile &conf);
00523 
00524                                 bool _reference;
00525                                 bool _sync;
00526                                 bool _discovery;
00527                                 int _qot_tick;
00528                                 float _sigma;
00529                                 float _sync_level;
00530 
00531                         public:
00532                                 bool hasReference() const;
00533                                 bool syncOnDiscovery() const;
00534                                 bool sendDiscoveryAnnouncements() const;
00535                                 int getQualityOfTimeTick() const;
00536 
00537                                 float getSigma() const;
00538                                 float getSyncLevel() const;
00539                         };
00540         
00541                         class DHT: public Configuration::Extension
00542                         {
00543                                 friend class Configuration;
00544                         protected:
00545                                 DHT();
00546                                 virtual ~DHT();
00547                                 void load(const ibrcommon::ConfigFile &conf);
00548 
00549                         private:
00550                                 bool _enabled;
00551                                 int _port;
00552                                 string _id;
00553                                 string _ipv4bind;
00554                                 string _ipv6bind;
00555                                 std::vector<string> _bootstrappingdomains;
00556                                 bool _dnsbootstrapping;
00557                                 std::vector<string> _bootstrappingips;
00558                                 string _nodesFilePath;
00559                                 bool _ipv4;
00560                                 bool _ipv6;
00561                                 bool _blacklist;
00562                                 bool _selfannounce;
00563                                 std::vector<int> _portFilter;
00564                                 int _minRating;
00565                                 bool _allowNeighbourToAnnounceMe;
00566                                 bool _allowNeighbourAnnouncement;
00567                                 bool _ignoreDHTNeighbourInformations;
00568 
00569                         public:
00573                                 bool enabled() const;
00574 
00578                                 bool randomPort() const;
00579 
00583                                 unsigned int getPort() const;
00584 
00588                                 string getID() const;
00589 
00593                                 bool randomID() const;
00594 
00598                                 bool isDNSBootstrappingEnabled() const;
00599 
00603                                 std::vector<string> getDNSBootstrappingNames() const;
00604 
00608                                 bool isIPBootstrappingEnabled() const;
00609 
00613                                 std::vector<string> getIPBootstrappingIPs() const;
00614 
00618                                 string getIPv4Binding() const;
00619 
00623                                 string getIPv6Binding() const;
00624 
00632                                 string getPathToNodeFiles() const;
00633 
00637                                 bool isIPv4Enabled() const;
00638 
00642                                 bool isIPv6Enabled() const;
00643 
00647                                 std::vector<int> getPortFilter() const;
00648 
00652                                 bool isBlacklistEnabled() const;
00653 
00657                                 bool isSelfAnnouncingEnabled() const;
00658 
00662                                 int getMinimumRating() const;
00663 
00667                                 bool isNeighbourAnnouncementEnabled() const;
00668 
00672                                 bool isNeighbourAllowedToAnnounceMe() const;
00673                                 
00683                                 bool ignoreDHTNeighbourInformations() const;
00684                         };
00685 
00686                         const Configuration::Discovery& getDiscovery() const;
00687                         const Configuration::Statistic& getStatistic() const;
00688                         const Configuration::Debug& getDebug() const;
00689                         const Configuration::Logger& getLogger() const;
00690                         const Configuration::Network& getNetwork() const;
00691                         const Configuration::Security& getSecurity() const;
00692                         const Configuration::Daemon& getDaemon() const;
00693                         const Configuration::TimeSync& getTimeSync() const;
00694                         const Configuration::DHT& getDHT() const;
00695 
00696                 private:
00697                         ibrcommon::ConfigFile _conf;
00698                         Configuration::Discovery _disco;
00699                         Configuration::Statistic _stats;
00700                         Configuration::Debug _debug;
00701                         Configuration::Logger _logger;
00702                         Configuration::Network _network;
00703                         Configuration::Security _security;
00704                         Configuration::Daemon _daemon;
00705                         Configuration::TimeSync _timesync;
00706                         Configuration::DHT _dht;
00707 
00708                         std::string _filename;
00709                         bool _doapi;
00710                 };
00711         }
00712 }
00713 
00714 #endif /*CONFIGURATION_H_*/