|
IBR-DTNSuite 0.6
|
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 <list> 00010 00011 using namespace dtn::net; 00012 using namespace dtn::core; 00013 using namespace dtn::data; 00014 00015 namespace dtn 00016 { 00017 namespace daemon 00018 { 00022 class Configuration 00023 { 00024 private: 00025 Configuration(); 00026 virtual ~Configuration(); 00027 00028 public: 00029 class NetConfig 00030 { 00031 public: 00032 enum NetType 00033 { 00034 NETWORK_UNKNOWN = 0, 00035 NETWORK_TCP = 1, 00036 NETWORK_UDP = 2, 00037 NETWORK_HTTP = 3, 00038 NETWORK_LOWPAN = 4 00039 }; 00040 00041 NetConfig(std::string name, NetType type, const std::string &url, bool discovery = true); 00042 NetConfig(std::string name, NetType type, const ibrcommon::vaddress &address, int port, bool discovery = true); 00043 NetConfig(std::string name, NetType type, const ibrcommon::vinterface &iface, int port, bool discovery = true); 00044 NetConfig(std::string name, NetType type, int port, bool discovery = true); 00045 virtual ~NetConfig(); 00046 00047 std::string name; 00048 NetType type; 00049 std::string url; 00050 ibrcommon::vinterface interface; 00051 ibrcommon::vaddress address; 00052 int port; 00053 bool discovery; 00054 }; 00055 00056 class ParameterNotSetException : ibrcommon::Exception 00057 { 00058 }; 00059 00060 class ParameterNotFoundException : ibrcommon::Exception 00061 { 00062 }; 00063 00064 static Configuration &getInstance(); 00065 00069 void load(); 00070 void load(string filename); 00071 00072 void params(int argc, char *argv[]); 00073 00077 string getNodename(); 00078 00084 int getTimezone(); 00085 00092 ibrcommon::File getPath(string name); 00093 00100 unsigned int getUID() const; 00101 00108 unsigned int getGID() const; 00109 00116 const std::string getUser() const; 00117 00122 bool doAPI(); 00123 00124 Configuration::NetConfig getAPIInterface(); 00125 ibrcommon::File getAPISocket(); 00126 00131 std::string version(); 00132 00139 std::string getNotifyCommand(); 00140 00145 std::string getStorage() const; 00146 00147 enum RoutingExtension 00148 { 00149 DEFAULT_ROUTING = 0, 00150 EPIDEMIC_ROUTING = 1, 00151 FLOOD_ROUTING = 2 00152 }; 00153 00159 size_t getLimit(std::string); 00160 00161 class Extension 00162 { 00163 protected: 00164 virtual void load(const ibrcommon::ConfigFile &conf) = 0; 00165 }; 00166 00167 class Discovery : public Configuration::Extension 00168 { 00169 friend class Configuration; 00170 protected: 00171 Discovery(); 00172 virtual ~Discovery(); 00173 void load(const ibrcommon::ConfigFile &conf); 00174 00175 bool _enabled; 00176 unsigned int _timeout; 00177 00178 public: 00179 bool enabled() const; 00180 bool announce() const; 00181 bool shortbeacon() const; 00182 char version() const; 00183 const ibrcommon::vaddress address() const throw (ParameterNotFoundException); 00184 int port() const; 00185 unsigned int timeout() const; 00186 }; 00187 00188 class Statistic : public Configuration::Extension 00189 { 00190 friend class Configuration; 00191 protected: 00192 Statistic(); 00193 virtual ~Statistic(); 00194 void load(const ibrcommon::ConfigFile &conf); 00195 00196 public: 00200 bool enabled() const; 00201 00205 ibrcommon::File logfile() const throw (ParameterNotSetException); 00206 00210 std::string type() const; 00211 00215 unsigned int interval() const; 00216 00220 std::string address() const; 00221 00225 unsigned int port() const; 00226 }; 00227 00228 class Debug : public Configuration::Extension 00229 { 00230 friend class Configuration; 00231 protected: 00232 Debug(); 00233 virtual ~Debug(); 00234 void load(const ibrcommon::ConfigFile &conf); 00235 00236 bool _enabled; 00237 bool _quiet; 00238 int _level; 00239 00240 public: 00244 int level() const; 00245 00249 bool enabled() const; 00250 00255 bool quiet() const; 00256 }; 00257 00258 class Logger : public Configuration::Extension 00259 { 00260 friend class Configuration; 00261 protected: 00262 Logger(); 00263 virtual ~Logger(); 00264 void load(const ibrcommon::ConfigFile &conf); 00265 00266 bool _quiet; 00267 unsigned int _options; 00268 bool _timestamps; 00269 ibrcommon::File _logfile; 00270 00271 public: 00276 bool quiet() const; 00277 00282 const ibrcommon::File& getLogfile() const; 00283 00293 unsigned int options() const; 00294 00298 std::ostream &output() const; 00299 00303 bool display_timestamps() const; 00304 }; 00305 00306 class Network : public Configuration::Extension 00307 { 00308 friend class Configuration; 00309 protected: 00310 Network(); 00311 virtual ~Network(); 00312 void load(const ibrcommon::ConfigFile &conf); 00313 00314 std::list<dtn::routing::StaticRoutingExtension::StaticRoute> _static_routes; 00315 std::list<Node> _nodes; 00316 std::list<NetConfig> _interfaces; 00317 std::string _routing; 00318 bool _forwarding; 00319 bool _tcp_nodelay; 00320 size_t _tcp_chunksize; 00321 ibrcommon::vinterface _default_net; 00322 bool _use_default_net; 00323 bool _dynamic_rebind; 00324 size_t _auto_connect; 00325 00326 public: 00330 const std::list<NetConfig>& getInterfaces() const; 00331 00335 const std::list<Node>& getStaticNodes() const; 00336 00340 const list<dtn::routing::StaticRoutingExtension::StaticRoute>& getStaticRoutes() const; 00341 00345 RoutingExtension getRoutingExtension() const; 00346 00351 bool doForwarding() const; 00352 00356 bool getTCPOptionNoDelay() const; 00357 00361 size_t getTCPChunkSize() const; 00362 00366 bool doDynamicRebind() const; 00367 00371 size_t getAutoConnect() const; 00372 }; 00373 00374 class Security : public Configuration::Extension 00375 { 00376 friend class Configuration; 00377 private: 00378 bool _enabled; 00379 bool _tlsEnabled; 00380 bool _tlsRequired; 00381 00382 protected: 00383 Security(); 00384 virtual ~Security(); 00385 void load(const ibrcommon::ConfigFile &conf); 00386 00387 public: 00388 bool enabled() const; 00389 00396 bool doTLS() const; 00397 00403 bool TLSRequired() const; 00404 00405 #ifdef WITH_BUNDLE_SECURITY 00406 enum Level 00407 { 00408 SECURITY_LEVEL_NONE = 0, 00409 SECURITY_LEVEL_AUTHENTICATED = 1, 00410 SECURITY_LEVEL_ENCRYPTED = 2 00411 }; 00412 00413 Level getLevel() const; 00414 00415 const ibrcommon::File& getPath() const; 00416 00417 const ibrcommon::File& getBABDefaultKey() const; 00418 00419 private: 00420 ibrcommon::File _path; 00421 Level _level; 00422 ibrcommon::File _bab_default_key; 00423 #endif 00424 #if defined WITH_BUNDLE_SECURITY || defined WITH_TLS 00425 public: 00426 const ibrcommon::File& getCA() const; 00427 00428 const ibrcommon::File& getKey() const; 00429 private: 00430 ibrcommon::File _ca; 00431 ibrcommon::File _key; 00432 #endif 00433 #ifdef WITH_TLS 00434 public: 00439 const ibrcommon::File& getTrustedCAPath() const; 00440 00445 bool TLSEncryptionDisabled() const; 00446 00447 private: 00448 ibrcommon::File _trustedCAPath; 00449 bool _disableEncryption; 00450 #endif 00451 }; 00452 00453 class Daemon : public Configuration::Extension 00454 { 00455 friend class Configuration; 00456 private: 00457 bool _daemonize; 00458 ibrcommon::File _pidfile; 00459 bool _kill; 00460 00461 protected: 00462 Daemon(); 00463 virtual ~Daemon(); 00464 void load(const ibrcommon::ConfigFile &conf); 00465 00466 public: 00467 bool daemonize() const; 00468 const ibrcommon::File& getPidFile() const; 00469 bool kill_daemon() const; 00470 }; 00471 00472 const Configuration::Discovery& getDiscovery() const; 00473 const Configuration::Statistic& getStatistic() const; 00474 const Configuration::Debug& getDebug() const; 00475 const Configuration::Logger& getLogger() const; 00476 const Configuration::Network& getNetwork() const; 00477 const Configuration::Security& getSecurity() const; 00478 const Configuration::Daemon& getDaemon() const; 00479 00480 private: 00481 ibrcommon::ConfigFile _conf; 00482 Configuration::Discovery _disco; 00483 Configuration::Statistic _stats; 00484 Configuration::Debug _debug; 00485 Configuration::Logger _logger; 00486 Configuration::Network _network; 00487 Configuration::Security _security; 00488 Configuration::Daemon _daemon; 00489 00490 std::string _filename; 00491 bool _doapi; 00492 }; 00493 } 00494 } 00495 00496 #endif /*CONFIGURATION_H_*/