|
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 00325 public: 00329 const std::list<NetConfig>& getInterfaces() const; 00330 00334 const std::list<Node>& getStaticNodes() const; 00335 00339 const list<dtn::routing::StaticRoutingExtension::StaticRoute>& getStaticRoutes() const; 00340 00344 RoutingExtension getRoutingExtension() const; 00345 00350 bool doForwarding() const; 00351 00355 bool getTCPOptionNoDelay() const; 00356 00360 size_t getTCPChunkSize() const; 00361 00365 bool doDynamicRebind() const; 00366 }; 00367 00368 class Security : public Configuration::Extension 00369 { 00370 friend class Configuration; 00371 private: 00372 bool _enabled; 00373 00374 protected: 00375 Security(); 00376 virtual ~Security(); 00377 void load(const ibrcommon::ConfigFile &conf); 00378 00379 public: 00380 bool enabled() const; 00381 00382 #ifdef WITH_BUNDLE_SECURITY 00383 enum Level 00384 { 00385 SECURITY_LEVEL_NONE = 0, 00386 SECURITY_LEVEL_AUTHENTICATED = 1, 00387 SECURITY_LEVEL_ENCRYPTED = 2 00388 }; 00389 00390 Level getLevel() const; 00391 00392 const ibrcommon::File& getPath() const; 00393 00394 const ibrcommon::File& getCA() const; 00395 00396 const ibrcommon::File& getKey() const; 00397 00398 const ibrcommon::File& getBABDefaultKey() const; 00399 00400 private: 00401 ibrcommon::File _path; 00402 Level _level; 00403 ibrcommon::File _ca; 00404 ibrcommon::File _key; 00405 ibrcommon::File _bab_default_key; 00406 #endif 00407 }; 00408 00409 class Daemon : public Configuration::Extension 00410 { 00411 friend class Configuration; 00412 private: 00413 bool _daemonize; 00414 ibrcommon::File _pidfile; 00415 bool _kill; 00416 00417 protected: 00418 Daemon(); 00419 virtual ~Daemon(); 00420 void load(const ibrcommon::ConfigFile &conf); 00421 00422 public: 00423 bool daemonize() const; 00424 const ibrcommon::File& getPidFile() const; 00425 bool kill_daemon() const; 00426 }; 00427 00428 const Configuration::Discovery& getDiscovery() const; 00429 const Configuration::Statistic& getStatistic() const; 00430 const Configuration::Debug& getDebug() const; 00431 const Configuration::Logger& getLogger() const; 00432 const Configuration::Network& getNetwork() const; 00433 const Configuration::Security& getSecurity() const; 00434 const Configuration::Daemon& getDaemon() const; 00435 00436 private: 00437 ibrcommon::ConfigFile _conf; 00438 Configuration::Discovery _disco; 00439 Configuration::Statistic _stats; 00440 Configuration::Debug _debug; 00441 Configuration::Logger _logger; 00442 Configuration::Network _network; 00443 Configuration::Security _security; 00444 Configuration::Daemon _daemon; 00445 00446 std::string _filename; 00447 bool _doapi; 00448 }; 00449 } 00450 } 00451 00452 #endif /*CONFIGURATION_H_*/