00001 #ifndef CONFIG_H
00002 #define CONFIG_H
00003
00004 #include <map>
00005 #include "ConnectionTableEntry.h"
00006 #include "SslCtx.h"
00007
00008 class Config : public BasicObject
00009 {
00010 public:
00011 Config();
00012 virtual ~Config();
00013
00014 int save();
00015 int save(string path);
00016 void save(std::ostream& out);
00017
00018 int load();
00019 int load(string path);
00020 void load(std::istream& in);
00021
00022 void setValue(string category, string var, string val);
00023 void setValue(string var, string val);
00024 void setValue(string var, bool val);
00025 void setValue(string var, double val);
00026 void setValue(string var, int val);
00027
00028 string getString(string category, string var);
00029 string getString(string var);
00030 bool getBool(string var);
00031 int getInt(string var);
00032 double getDouble(string var);
00033
00034 static bool matchTag(string buf, string tag);
00035 static bool readBool(string buf, string tag);
00036 static int readInt(string buf, string tag);
00037 static double readDouble(string buf, string tag);
00038 static string readString(string buf, string tag);
00039
00040 bool set(string var, string val);
00041
00042 void getHelpForVariables(std::ostream& out);
00043
00044 ConnectionTableEntry* getSelf();
00045 int getMaxConnections();
00046 int getMaxHosts();
00047 string getPeerListFileName();
00048 double getConnectPropagationProbability();
00049 double getDiscoveryPropagationProbability();
00050 double getDiscoveryResponseProbability();
00051 const string getCertPath(void) { return (const string)m_certPath; }
00052 int getMinConnections(void) { return m_minConnections; }
00053 int getRWTimeout(void) { return m_rwTimeout; }
00054 bool doFastRouting();
00055 bool avoidCensoredNodes();
00056
00057 virtual void toStream(std::ostream& out);
00058
00059 SslCtx* getServerSslCtx(void) { return m_serverSslCtx; }
00060 SslCtx* getClientSslCtx(void) { return m_clientSslCtx; }
00061
00062 const static string MAX_CONNECTIONS_TAG;
00063 const static string MAX_HOSTS_TAG;
00064 const static string CERTIFICATE_PATH_TAG;
00065 const static string MIN_CONNECTIONS_TAG;
00066 const static string CPP_TAG;
00067 const static string DPP_TAG;
00068 const static string DRP_TAG;
00069 const static string RW_TIMEOUT_TAG;
00070 const static string DO_FAST_ROUTING_TAG;
00071 const static string AVOID_CENSORED_NODES_TAG;
00072
00073 private:
00075 int m_maxConnections;
00076
00078 int m_maxHosts;
00079
00081 double m_cpp;
00082
00084 double m_dpp;
00085
00087 double m_drp;
00088
00090 bool m_doFastRouting;
00091
00093 bool m_avoidCensoredNodes;
00094
00096 ConnectionTableEntry* m_selfNode;
00097
00099 string m_certPath;
00100
00102 int m_minConnections;
00103
00105 string m_hostFile;
00106
00108 int m_rwTimeout;
00109
00111 SslCtx* m_serverSslCtx;
00112
00114 SslCtx* m_clientSslCtx;
00115
00116 class VariableList { public: map<string, string> m_variableList; };
00117
00118 map<string, VariableList> m_categoryList;
00119 };
00120
00121 #endif