diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj index fb722f3abb..75f330249b 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj +++ b/Builds/VisualStudio2012/RippleD.vcxproj @@ -700,7 +700,7 @@ true true - + true true true @@ -1502,7 +1502,7 @@ - + diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters index 8db08ba08c..96eb688949 100644 --- a/Builds/VisualStudio2012/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters @@ -1,24 +1,12 @@  - - {ddf42dfe-eaad-4275-8cb7-5c02be627366} - {9766e229-8795-43d8-871e-60de90501333} {bcc68889-41a4-4090-ac3f-12a3ba1d8961} - - {f669c93c-60da-4674-a693-9eebcddacb6f} - - - {3debb18d-0f76-4208-accb-f96cb9ce6dab} - - - {1f093002-9955-4915-a17b-398d55c9fc76} - {ca8e7c6c-0e6d-4915-b7b4-0a0b21f91d16} @@ -61,24 +49,6 @@ {99ac4d07-04a7-4ce3-96c7-b8ea578f1a61} - - {6967f835-a1b0-47e3-9bd9-6fc8bd0f3df7} - - - {fe2722a9-6550-4098-91eb-1575f7419a42} - - - {e1f02660-3d99-4ef3-b79a-2a8da16e2ec7} - - - {5280f25b-a657-45f7-a0e6-822891d0f20f} - - - {8710b403-2cfa-4991-b8b4-8214d1947528} - - - {223ac5ce-c9a0-4196-9b75-4f5fbe8bfa00} - {c84fc3af-f487-4eba-af78-d4be009f76d1} @@ -157,6 +127,36 @@ {d1648d3f-7d71-495d-afc9-576ed00d7185} + + {ddf42dfe-eaad-4275-8cb7-5c02be627366} + + + {f669c93c-60da-4674-a693-9eebcddacb6f} + + + {3debb18d-0f76-4208-accb-f96cb9ce6dab} + + + {fe2722a9-6550-4098-91eb-1575f7419a42} + + + {e1f02660-3d99-4ef3-b79a-2a8da16e2ec7} + + + {223ac5ce-c9a0-4196-9b75-4f5fbe8bfa00} + + + {5280f25b-a657-45f7-a0e6-822891d0f20f} + + + {8710b403-2cfa-4991-b8b4-8214d1947528} + + + {1f093002-9955-4915-a17b-398d55c9fc76} + + + {6967f835-a1b0-47e3-9bd9-6fc8bd0f3df7} + @@ -204,9 +204,6 @@ [1] Ripple\ripple_basics - - [1] Ripple\ripple_core\functional - [1] Ripple\ripple_core\functional @@ -292,175 +289,175 @@ [1] Ripple\ripple_websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\port + [0] Libraries\leveldb\port - [0] src\leveldb\port + [0] Libraries\leveldb\port [1] Ripple\ripple_app @@ -853,25 +850,25 @@ [1] Ripple - [0] src\protobuf + [0] Libraries\protobuf - [0] src\beast + [0] Libraries\beast - [0] src\beast + [0] Libraries\beast - [0] src\beast + [0] Libraries\beast - [0] src\beast + [0] Libraries\beast - [0] src\beast + [0] Libraries\beast - [0] src\beast + [0] Libraries\beast @@ -880,6 +877,9 @@ [1] Ripple\ripple_core\peerfinder + + [1] Ripple\ripple_core\functional + @@ -957,9 +957,6 @@ [1] Ripple\ripple_basics - - [1] Ripple\ripple_core\functional - [1] Ripple\ripple_core\functional @@ -1054,211 +1051,211 @@ [1] Ripple\ripple_websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\websocket + [0] Libraries\websocket - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\db + [0] Libraries\leveldb\db - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\util + [0] Libraries\leveldb\util - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\table + [0] Libraries\leveldb\table - [0] src\leveldb\port\win + [0] Libraries\leveldb\port\win - [0] src\leveldb\port + [0] Libraries\leveldb\port - [0] src\leveldb\port + [0] Libraries\leveldb\port - [0] src\leveldb\port + [0] Libraries\leveldb\port - [0] src\leveldb\port + [0] Libraries\leveldb\port - [0] src\leveldb\port + [0] Libraries\leveldb\port - [0] src\leveldb\port + [0] Libraries\leveldb\port [1] Ripple\ripple_basics\utility @@ -1735,6 +1732,9 @@ [1] Ripple\ripple_core\peerfinder + + [1] Ripple\ripple_core\functional + diff --git a/doc/todo/VFALCO_TODO.txt b/doc/todo/VFALCO_TODO.txt index ef1c2d06af..6cb5d69a4c 100644 --- a/doc/todo/VFALCO_TODO.txt +++ b/doc/todo/VFALCO_TODO.txt @@ -3,6 +3,8 @@ RIPPLE TODO -------------------------------------------------------------------------------- Vinnie's List: Changes day to day, descending priority +- Clean up calculation of COnfig file location. +- Remove TESTNET and all related code and settings. - Full review of config docs / settings for RPC/WS - Fix RPCDoor to respect config setting for [rpc_secure] - Remove addRpcSub, findRpcSub, and notify the appropriate partner(s) diff --git a/src/ripple_app/main/ripple_Application.cpp b/src/ripple_app/main/ripple_Application.cpp index af2be2c9a3..f5b22fce5d 100644 --- a/src/ripple_app/main/ripple_Application.cpp +++ b/src/ripple_app/main/ripple_Application.cpp @@ -229,11 +229,13 @@ public: m_validators->addStrings (strings); } +#if 0 { String const& localValidatorsPath (getConfig().localValidatorsPath); if (localValidatorsPath != String::empty) m_validators->addFile (localValidatorsPath); } +#endif } //-------------------------------------------------------------------------- diff --git a/src/ripple_app/peers/ripple_UniqueNodeList.cpp b/src/ripple_app/peers/ripple_UniqueNodeList.cpp index 8e061ea8ef..9bdefd59c0 100644 --- a/src/ripple_app/peers/ripple_UniqueNodeList.cpp +++ b/src/ripple_app/peers/ripple_UniqueNodeList.cpp @@ -515,21 +515,24 @@ public: { if (pConfig.empty ()) { - WriteLog (lsINFO, UniqueNodeList) << VALIDATORS_FILE_NAME " path not specified."; + WriteLog (lsINFO, UniqueNodeList) << Config::Helpers::getValidatorsFileName() << + " path not specified."; return false; } if (!boost::filesystem::exists (pConfig)) { - WriteLog (lsWARNING, UniqueNodeList) << str (boost::format (VALIDATORS_FILE_NAME " not found: %s") % pConfig); + WriteLog (lsWARNING, UniqueNodeList) << Config::Helpers::getValidatorsFileName() << + " not found: " << pConfig; return false; } if (!boost::filesystem::is_regular_file (pConfig)) { - WriteLog (lsWARNING, UniqueNodeList) << str (boost::format (VALIDATORS_FILE_NAME " not regular file: %s") % pConfig); + WriteLog (lsWARNING, UniqueNodeList) << Config::Helpers::getValidatorsFileName() << + " not regular file: " << pConfig; return false; } @@ -538,7 +541,8 @@ public: if (!ifsDefault) { - WriteLog (lsFATAL, UniqueNodeList) << str (boost::format (VALIDATORS_FILE_NAME " failed to open: %s") % pConfig); + WriteLog (lsFATAL, UniqueNodeList) << Config::Helpers::getValidatorsFileName() << + " failed to open: " << pConfig; return false; } @@ -550,7 +554,8 @@ public: if (ifsDefault.bad ()) { - WriteLog (lsFATAL, UniqueNodeList) << str (boost::format ("Failed to read: %s") % pConfig); + WriteLog (lsFATAL, UniqueNodeList) << Config::Helpers::getValidatorsFileName() << + "Failed to read: " << pConfig; return false; } @@ -2002,7 +2007,10 @@ private: if (!bReject) { - WriteLog (lsTRACE, UniqueNodeList) << "Fetch '" VALIDATORS_FILE_NAME "' complete."; + WriteLog (lsTRACE, UniqueNodeList) << + "Fetch '" << + Config::Helpers::getValidatorsFileName () << + "' complete."; if (!err) { diff --git a/src/ripple_core/functional/ripple_Config.cpp b/src/ripple_core/functional/Config.cpp similarity index 80% rename from src/ripple_core/functional/ripple_Config.cpp rename to src/ripple_core/functional/Config.cpp index 3394324988..9945af769c 100644 --- a/src/ripple_core/functional/ripple_Config.cpp +++ b/src/ripple_core/functional/Config.cpp @@ -16,18 +16,26 @@ #define DEFAULT_FEE_OFFER DEFAULT_FEE_DEFAULT #define DEFAULT_FEE_OPERATION 1 -// VFALCO TODO Convert this to a SharedSingleton to prevent exit leaks -// -Config& getConfig () -{ - static Config config; - return config; -} +//------------------------------------------------------------------------------ Config::Config () : m_rpcPort (5001) , SSL_CONTEXT (boost::asio::ssl::context::sslv23) { + //-------------------------------------------------------------------------- + // + // VFALCO NOTE Clean member area + // + + peerListeningPort = SYSTEM_PEER_PORT; + + peerPROXYListeningPort = 0; + + // + // + // + //-------------------------------------------------------------------------- + // // Defaults // @@ -86,21 +94,6 @@ Config::Config () ELB_SUPPORT = false; RUN_STANDALONE = false; START_UP = NORMAL; - - - //-------------------------------------------------------------------------- - // - // VFALCO NOTE Clean area - // - - peerListeningPort = SYSTEM_PEER_PORT; - - peerPROXYListeningPort = 0; - - // - // - // - //-------------------------------------------------------------------------- } void Config::setup (const std::string& strConf, bool bTestNet, bool bQuiet) @@ -118,13 +111,15 @@ void Config::setup (const std::string& strConf, bool bTestNet, bool bQuiet) QUIET = bQuiet; NODE_SIZE = 0; - // TESTNET forces a "testnet-" prefix on the conf file and db directory. - strDbPath = TESTNET ? "testnet-db" : "db"; - strConfFile = boost::str (boost::format (TESTNET ? "testnet-%s" : "%s") - % (strConf.empty () ? CONFIG_FILE_NAME : strConf)); + // VFALCO NOTE TESTNET forces a "testnet-" prefix on the conf + // file and db directory, unless --conf is specified + // in which case there is no forced prefix. + + strDbPath = Helpers::getDatabaseDirName (TESTNET); + strConfFile = strConf.empty () ? Helpers::getConfigFileName (TESTNET) : strConf; + + VALIDATORS_BASE = Helpers::getValidatorsFileName (TESTNET); - VALIDATORS_BASE = boost::str (boost::format (TESTNET ? "testnet-%s" : "%s") - % VALIDATORS_FILE_NAME); VALIDATORS_URI = boost::str (boost::format ("/%s") % VALIDATORS_BASE); if (TESTNET) @@ -526,7 +521,6 @@ void Config::load () if (SectionSingleB (secConfig, SECTION_VALIDATORS_FILE, strTemp)) { - localValidatorsPath = strTemp; VALIDATORS_FILE = strTemp; } @@ -572,6 +566,164 @@ int Config::getSize (SizedItemName item) return -1; } +//------------------------------------------------------------------------------ +// +// VFALCO NOTE Clean members area +// + +Config& getConfig () +{ + static Config config; + return config; +} + +//------------------------------------------------------------------------------ + +/* The location of the configuration file is checked as follows, + in order of descending priority: + + 1. In the path specified by --conf command line option if present + (which is relative to the current directory) + 2. In the current user's "home" directory + 3. In the same directory as the rippled executable + 4. In the "current" directory defined by the process which launched rippled +*/ +File Config::findConfigFile (String commandLineLocation, bool forTestNetwork) +{ + File file (File::nonexistent ()); + +#if 0 + // Highest priority goes to commandLineLocation + // + if (file == File::nonexistent() && commandLineLocation != String::empty) + { + // If commandLineLocation is a full path, + // this will just assign the full path to file. + // + file = File::getCurrentDirectory().getChildFile (commandLineLocation); + + if (! file.existsAsFile ()) + file = File::nonexistent (); + } + + // Next, we will look in the user's home directory + // +#else + +#if 0 + // VFALCO NOTE This is the original legacy code... + + std::string strConfFile; + + // Determine the config and data directories. + // If the config file is found in the current working directory, + // use the current working directory as the config directory and + // that with "db" as the data directory. + { + String s; + + if (forTestNetwork) + s += "testnet-"; + + if (commandLineLocation != String::empty) + s += Helpers::getConfigFileName (forTestNetwork); + + strConfFile = boost::str (boost::format (forTestNetwork ? "testnet-%s" : "%s") + % (strConf.empty () ? Helpers::getConfigFileName() : strConf)); + + VALIDATORS_BASE = boost::str (boost::format (TESTNET ? "testnet-%s" : "%s") + % VALIDATORS_FILE_NAME); + VALIDATORS_URI = boost::str (boost::format ("/%s") % VALIDATORS_BASE); + + if (TESTNET) + { + SIGN_TRANSACTION = HashPrefix::txSignTestnet; + SIGN_VALIDATION = HashPrefix::validationTestnet; + SIGN_PROPOSAL = HashPrefix::proposalTestnet; + } + else + { + SIGN_TRANSACTION = HashPrefix::txSign; + SIGN_VALIDATION = HashPrefix::validation; + SIGN_PROPOSAL = HashPrefix::proposal; + } + + if (TESTNET) + Base58::setCurrentAlphabet (Base58::getTestnetAlphabet ()); + + if (!strConf.empty ()) + { + // --conf= : everything is relative that file. + CONFIG_FILE = strConfFile; + CONFIG_DIR = boost::filesystem::absolute (CONFIG_FILE); + CONFIG_DIR.remove_filename (); + DATA_DIR = CONFIG_DIR / strDbPath; + } + else + { + CONFIG_DIR = boost::filesystem::current_path (); + CONFIG_FILE = CONFIG_DIR / strConfFile; + DATA_DIR = CONFIG_DIR / strDbPath; + + if (exists (CONFIG_FILE) + // Can we figure out XDG dirs? + || (!getenv ("HOME") && (!getenv ("XDG_CONFIG_HOME") || !getenv ("XDG_DATA_HOME")))) + { + // Current working directory is fine, put dbs in a subdir. + nothing (); + } + else + { + // Construct XDG config and data home. + // http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html + std::string strHome = strGetEnv ("HOME"); + std::string strXdgConfigHome = strGetEnv ("XDG_CONFIG_HOME"); + std::string strXdgDataHome = strGetEnv ("XDG_DATA_HOME"); + + if (strXdgConfigHome.empty ()) + { + // $XDG_CONFIG_HOME was not set, use default based on $HOME. + strXdgConfigHome = boost::str (boost::format ("%s/.config") % strHome); + } + + if (strXdgDataHome.empty ()) + { + // $XDG_DATA_HOME was not set, use default based on $HOME. + strXdgDataHome = boost::str (boost::format ("%s/.local/share") % strHome); + } + + CONFIG_DIR = boost::str (boost::format ("%s/" SYSTEM_NAME) % strXdgConfigHome); + CONFIG_FILE = CONFIG_DIR / strConfFile; + DATA_DIR = boost::str (boost::format ("%s/" SYSTEM_NAME) % strXdgDataHome); + + boost::filesystem::create_directories (CONFIG_DIR, ec); + + if (ec) + throw std::runtime_error (boost::str (boost::format ("Can not create %s") % CONFIG_DIR)); + } + } + +#endif + +#endif + + return file; +} + +//------------------------------------------------------------------------------ + +File Config::getConfigDir () const +{ + return File (String (CONFIG_FILE.native ().c_str ())).getParentDirectory (); +} + +File Config::getDatabaseDir () const +{ + return File (String (DATA_DIR.native ().c_str ())); +} + +//------------------------------------------------------------------------------ + void Config::setRpcIpAndOptionalPort (std::string const& newAddress) { String const s (newAddress.c_str ()); @@ -632,3 +784,6 @@ Config::Role Config::getAdminRole (Json::Value const& params, std::string const& return role; } +// +// +//------------------------------------------------------------------------------ diff --git a/src/ripple_core/functional/ripple_Config.h b/src/ripple_core/functional/Config.h similarity index 74% rename from src/ripple_core/functional/ripple_Config.h rename to src/ripple_core/functional/Config.h index c0251f95dd..0c8ead96cc 100644 --- a/src/ripple_core/functional/ripple_Config.h +++ b/src/ripple_core/functional/Config.h @@ -4,8 +4,8 @@ */ //============================================================================== -#ifndef RIPPLE_CONFIG_H -#define RIPPLE_CONFIG_H +#ifndef RIPPLE_CORE_CONFIG_H_INCLUDED +#define RIPPLE_CORE_CONFIG_H_INCLUDED // VFALCO TODO Replace these with beast "unsigned long long" generators // VFALCO NOTE Apparently these are used elsewhere. Make them constants in the config @@ -19,10 +19,7 @@ // VFALCO NOTE Set this to 1 to enable code which is unnecessary #define ENABLE_INSECURE 0 -#define CONFIG_FILE_NAME SYSTEM_NAME "d.cfg" // rippled.cfg - #define DEFAULT_VALIDATORS_SITE "" -#define VALIDATORS_FILE_NAME "validators.txt" const int DOMAIN_BYTES_MAX = 256; const int PUBLIC_BYTES_MAX = 33; // Maximum bytes for an account public key. @@ -77,18 +74,210 @@ struct SizedItem class Config { public: - // Configuration parameters - bool QUIET; - bool TESTNET; + //-------------------------------------------------------------------------- + // + // VFALCO NOTE To tame this "Config" beast I am breaking it up into + // individual sections related to a specific area of the + // program. For example, listening port configuration. Or + // node database configuration. Each class has its own + // default constructor, and load function for reading in + // settings from the parsed config file data. + // + // Clean member area. Please follow this style for modifying + // or adding code in the file. + + struct Helpers + { + // This replaces CONFIG_FILE_NAME + static char const* getConfigFileName (bool forTestNetwork = false) + { + return forTestNetwork ? "testnet-rippled.cfg" : "rippled.cfg"; + } + + static char const* getDatabaseDirName (bool forTestNetwork = false) + { + return forTestNetwork ? "testnet-db" : "db"; + } + + static char const* getValidatorsFileName (bool forTestNetwork = false) + { + return forTestNetwork ? "testnet-validators.txt" : "validators.txt"; + } + }; + + /** The result of performing a load on the parsed config file data. + This type is convertible to `bool`. + A value of `true` indicates an error occurred, + while `false` indicates no error. + */ + class Error : public SafeBool + { + public: + Error () noexcept + : m_what (String::empty) + , m_fileName ("") + , m_lineNumber (0) + { + } + + Error (String what, char const* fileName, int lineNumber) noexcept + : m_what (what) + , m_fileName (fileName) + , m_lineNumber (lineNumber) + { + } + + bool asBoolean () const noexcept + { + return m_what != String::empty; + } + + String what () const noexcept + { + return m_what; + } + + char const* fileName () const + { + return m_fileName; + } + + int lineNumber () const + { + return m_lineNumber; + } + + private: + String m_what; + char const* m_fileName; + int m_lineNumber; + }; + + /** Listening socket settings. */ + struct DoorSettings + { + /** Create a default set of door (listening socket) settings. */ + DoorSettings (); + + /** Load settings from the configuration file. */ + //Error load (ParsedConfigFile const& file); + }; + + //-------------------------------------------------------------------------- + + /** Determine the location of the config file. + This searches the location provided on the command line first, + followed by the platform specific "user's home" directory. + @param commandLineLocation an optional location passed from the command line. + @param forTestNetwork Whether or not we are operating on the test network (DEPRECATATED) + */ + static File findConfigFile ( + String commandLineLocation = String::empty, + bool forTestNetwork = false); + + //-------------------------------------------------------------------------- + + // Settings related to the configuration file location and directories + + /** Returns the directory from which the configuration file was loaded. */ + File getConfigDir () const; + + /** Returns the directory in which the current database files are located. */ + File getDatabaseDir () const; + + // LEGACY FIELDS, REMOVE ASAP + boost::filesystem::path CONFIG_FILE; // used by UniqueNodeList +private: + boost::filesystem::path CONFIG_DIR; +public: + // VFALCO TODO Make this private and fix callers to go through getDatabaseDir() + boost::filesystem::path DATA_DIR; + + //-------------------------------------------------------------------------- + + // Settings related to validators - boost::filesystem::path CONFIG_FILE; - boost::filesystem::path CONFIG_DIR; - boost::filesystem::path DATA_DIR; - boost::filesystem::path DEBUG_LOGFILE; boost::filesystem::path VALIDATORS_FILE; // As specifed in rippled.cfg. //-------------------------------------------------------------------------- + // Settings related to RPC + + /** Get the client or server RPC IP address. + @note The string may not always be in a valid parsable state. + @return A string representing the address. + */ + std::string getRpcIP () const { return m_rpcIP; } + + /** Get the client or server RPC port number. + @note The port number may be invalid (out of range or zero) + @return The RPC port number. + */ + int getRpcPort () const { return m_rpcPort; } + + /** Set the client or server RPC IP and optional port. + @note The string is not syntax checked. + @param newAddress A string in the format [':'] + */ + void setRpcIpAndOptionalPort (std::string const& newAddress); + + /** Set the client or server RPC IP. + @note The string is not syntax-checked. + @param newIP A string representing the IP address to use. + */ + void setRpcIP (std::string const& newIP) { m_rpcIP = newIP; } + + /** Set the client or server RPC port number. + @note The port number is not range checked. + @param newPort The RPC port number to use. + */ + void setRpcPort (int newPort) { m_rpcPort = newPort; } + + /** Convert the RPC/port combination to a readable string. + */ + String const getRpcAddress () + { + String s; + + s << m_rpcIP.c_str () << ":" << m_rpcPort; + + return s; + } + + /** Determine the level of administrative permission to grant. + */ + enum Role + { + GUEST, + USER, + ADMIN, + FORBID + }; + Role getAdminRole (Json::Value const& params, std::string const& strRemoteIp) const; + + /** Listening port number for peer connections. */ + int peerListeningPort; + + /** PROXY listening port number + If this is not zero, it indicates an additional port number on + which we should accept incoming Peer connections that will also + require a PROXY handshake. + + The PROXY Protocol: + http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt + */ + int peerPROXYListeningPort; + + /** List of Validators entries from rippled.cfg */ + std::vector validators; + +private: + std::string m_rpcIP; + int m_rpcPort; // VFALCO TODO This should be a short. +public: + + //-------------------------------------------------------------------------- + /** Parameters for the main NodeStore database. This is 1 or more strings of the form = @@ -111,39 +300,24 @@ public: StringPairArray ephemeralNodeDatabase; /** Parameters for importing an old database in to the current node database. - If this is not empty, then it specifies the key/value parameters for another node database from which to import all data into the current node database specified by @ref nodeDatabase. - The format of this string is in the form: '='['|''='value] - @see parseDelimitedKeyValueString */ StringPairArray importNodeDatabase; - // Listening port number for peer connections. // - int peerListeningPort; - - /** PROXY listening port number - If this is not zero, it indicates an additional port number on - which we should accept incoming Peer connections that will also - require a PROXY handshake. - - The PROXY Protocol: - http://haproxy.1wt.eu/download/1.5/doc/proxy-protocol.txt - */ - int peerPROXYListeningPort; - - /** List of Validators entries from rippled.cfg */ - std::vector validators; - - /** Path to local validators.txt file from rippled.cfg */ - String localValidatorsPath; - + // //-------------------------------------------------------------------------- +public: + // Configuration parameters + bool QUIET; + bool TESTNET; + + boost::filesystem::path DEBUG_LOGFILE; bool ELB_SUPPORT; // Support Amazon ELB @@ -217,71 +391,6 @@ public: std::string WEBSOCKET_SSL_CHAIN; std::string WEBSOCKET_SSL_KEY; - //---------------------------------------------------------------------------- - // - // VFALCO NOTE Please follow this style for modifying or adding code in the file. - // -public: - /** Get the client or server RPC IP address. - @note The string may not always be in a valid parsable state. - @return A string representing the address. - */ - std::string getRpcIP () const { return m_rpcIP; } - - /** Get the client or server RPC port number. - @note The port number may be invalid (out of range or zero) - @return The RPC port number. - */ - int getRpcPort () const { return m_rpcPort; } - - /** Set the client or server RPC IP and optional port. - @note The string is not syntax checked. - @param newAddress A string in the format [':'] - */ - void setRpcIpAndOptionalPort (std::string const& newAddress); - - /** Set the client or server RPC IP. - @note The string is not syntax-checked. - @param newIP A string representing the IP address to use. - */ - void setRpcIP (std::string const& newIP) { m_rpcIP = newIP; } - - /** Set the client or server RPC port number. - @note The port number is not range checked. - @param newPort The RPC port number to use. - */ - void setRpcPort (int newPort) { m_rpcPort = newPort; } - - /** Convert the RPC/port combination to a readable string. - */ - String const getRpcAddress () - { - String s; - - s << m_rpcIP.c_str () << ":" << m_rpcPort; - - return s; - } - - /** Determine the level of administrative permission to grant. - */ - enum Role - { - GUEST, - USER, - ADMIN, - FORBID - }; - Role getAdminRole (Json::Value const& params, std::string const& strRemoteIp) const; - -private: - std::string m_rpcIP; - // VFALCO TODO This should be a short. - int m_rpcPort; - // - //---------------------------------------------------------------------------- - -public: // RPC parameters std::vector RPC_ADMIN_ALLOW; std::string RPC_ADMIN_PASSWORD; @@ -295,7 +404,6 @@ public: std::string RPC_SSL_CERT; std::string RPC_SSL_CHAIN; std::string RPC_SSL_KEY; - //---------------------------------------------------------------------------- // Path searching int PATH_SEARCH_OLD; diff --git a/src/ripple_core/ripple_core.cpp b/src/ripple_core/ripple_core.cpp index 0d0d421fe0..40fc22519b 100644 --- a/src/ripple_core/ripple_core.cpp +++ b/src/ripple_core/ripple_core.cpp @@ -28,7 +28,7 @@ namespace ripple { -#include "functional/ripple_Config.cpp" +#include "functional/Config.cpp" # include "functional/ripple_LoadFeeTrack.h" // private #include "functional/ripple_LoadFeeTrack.cpp" #include "functional/ripple_Job.cpp" diff --git a/src/ripple_core/ripple_core.h b/src/ripple_core/ripple_core.h index 5d0d0d1ea2..897ae538be 100644 --- a/src/ripple_core/ripple_core.h +++ b/src/ripple_core/ripple_core.h @@ -26,7 +26,7 @@ namespace ripple // Order matters # include "functional/ripple_ConfigSections.h" -#include "functional/ripple_Config.h" +#include "functional/Config.h" #include "functional/ripple_ILoadFeeTrack.h" # include "functional/ripple_LoadEvent.h" # include "functional/ripple_LoadMonitor.h"