#include "config/bitcoin-config.h"
#endif
-#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
-#include <pthread.h>
-#include <pthread_np.h>
-#endif
-
#include "util.h"
#include "chainparamsbase.h"
#include <stdarg.h>
+#if (defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__))
+#include <pthread.h>
+#include <pthread_np.h>
+#endif
+
#ifndef WIN32
// for posix_fallocate
#ifdef __linux__
#include <boost/program_options/parsers.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
-#include <openssl/rand.h>
+#include <openssl/conf.h>
// Work around clang compilation problem in Boost 1.46:
// /usr/include/boost/program_options/detail/config_file.hpp:163:17: error: call to function 'to_internal' that is neither visible in the template definition nor found by argument-dependent lookup
bool fDaemon = false;
bool fServer = false;
string strMiscWarning;
-bool fLogTimestamps = false;
-bool fLogIPs = false;
-volatile bool fReopenDebugLog = false;
+bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
+bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
+bool fLogIPs = DEFAULT_LOGIPS;
+std::atomic<bool> fReopenDebugLog(false);
CTranslationInterface translationInterface;
/** Init OpenSSL library multithreading support */
static CCriticalSection** ppmutexOpenSSL;
-void locking_callback(int mode, int i, const char* file, int line)
+void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
{
if (mode & CRYPTO_LOCK) {
ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
ppmutexOpenSSL[i] = new CCriticalSection();
CRYPTO_set_locking_callback(locking_callback);
-#ifdef WIN32
- // Seed OpenSSL PRNG with current contents of the screen
- RAND_screen();
-#endif
-
- // Seed OpenSSL PRNG with performance counter
- RandAddSeed();
+ // OpenSSL can optionally load a config file which lists optional loadable modules and engines.
+ // We don't use them so we don't require the config. However some of our libs may call functions
+ // which attempt to load the config file, possibly resulting in an exit() or crash if it is missing
+ // or corrupt. Explicitly tell OpenSSL not to try to load the file. The result for our libs will be
+ // that the config appears to have been loaded and there are no modules/engines available.
+ OPENSSL_no_config();
}
~CInit()
{
- // Securely erase the memory used by the PRNG
- RAND_cleanup();
// Shutdown OpenSSL library multithreading support
CRYPTO_set_locking_callback(NULL);
for (int i = 0; i < CRYPTO_num_locks(); i++)
// if not debugging everything and not debugging specific category, LogPrint does nothing.
if (setCategories.count(string("")) == 0 &&
+ setCategories.count(string("1")) == 0 &&
setCategories.count(string(category)) == 0)
return false;
}
char pszModule[MAX_PATH] = "";
GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));
#else
- const char* pszModule = "bitcoin";
+ const char* pszModule = "Zcash";
#endif
if (pex)
return strprintf(
boost::filesystem::path GetDefaultDataDir()
{
namespace fs = boost::filesystem;
- // Windows < Vista: C:\Documents and Settings\Username\Application Data\Bitcoin
- // Windows >= Vista: C:\Users\Username\AppData\Roaming\Bitcoin
- // Mac: ~/Library/Application Support/Bitcoin
- // Unix: ~/.bitcoin
+ // Windows < Vista: C:\Documents and Settings\Username\Application Data\Zcash
+ // Windows >= Vista: C:\Users\Username\AppData\Roaming\Zcash
+ // Mac: ~/Library/Application Support/Zcash
+ // Unix: ~/.zcash
#ifdef WIN32
// Windows
- return GetSpecialFolderPath(CSIDL_APPDATA) / "Bitcoin";
+ return GetSpecialFolderPath(CSIDL_APPDATA) / "Zcash";
#else
fs::path pathRet;
char* pszHome = getenv("HOME");
// Mac
pathRet /= "Library/Application Support";
TryCreateDirectory(pathRet);
- return pathRet / "Bitcoin";
+ return pathRet / "Zcash";
#else
// Unix
- return pathRet / ".bitcoin";
+ return pathRet / ".zcash";
#endif
#endif
}
static boost::filesystem::path pathCached;
static boost::filesystem::path pathCachedNetSpecific;
+static boost::filesystem::path zc_paramsPathCached;
static CCriticalSection csPathCached;
+static boost::filesystem::path ZC_GetBaseParamsDir()
+{
+ // Copied from GetDefaultDataDir and adapter for zcash params.
+
+ namespace fs = boost::filesystem;
+ // Windows < Vista: C:\Documents and Settings\Username\Application Data\ZcashParams
+ // Windows >= Vista: C:\Users\Username\AppData\Roaming\ZcashParams
+ // Mac: ~/Library/Application Support/ZcashParams
+ // Unix: ~/.zcash-params
+#ifdef WIN32
+ // Windows
+ return GetSpecialFolderPath(CSIDL_APPDATA) / "ZcashParams";
+#else
+ fs::path pathRet;
+ char* pszHome = getenv("HOME");
+ if (pszHome == NULL || strlen(pszHome) == 0)
+ pathRet = fs::path("/");
+ else
+ pathRet = fs::path(pszHome);
+#ifdef MAC_OSX
+ // Mac
+ pathRet /= "Library/Application Support";
+ TryCreateDirectory(pathRet);
+ return pathRet / "ZcashParams";
+#else
+ // Unix
+ return pathRet / ".zcash-params";
+#endif
+#endif
+}
+
+const boost::filesystem::path &ZC_GetParamsDir()
+{
+ namespace fs = boost::filesystem;
+
+ LOCK(csPathCached); // Reuse the same lock as upstream.
+
+ fs::path &path = zc_paramsPathCached;
+
+ // This can be called during exceptions by LogPrintf(), so we cache the
+ // value so we don't have to do memory allocations after that.
+ if (!path.empty())
+ return path;
+
+ path = ZC_GetBaseParamsDir();
+
+ return path;
+}
+
+// Return the user specified export directory. Create directory if it doesn't exist.
+// If user did not set option, return an empty path.
+// If there is a filesystem problem, throw an exception.
+const boost::filesystem::path GetExportDir()
+{
+ namespace fs = boost::filesystem;
+ fs::path path;
+ if (mapArgs.count("-exportdir")) {
+ path = fs::system_complete(mapArgs["-exportdir"]);
+ if (fs::exists(path) && !fs::is_directory(path)) {
+ throw std::runtime_error(strprintf("The -exportdir '%s' already exists and is not a directory", path.string()));
+ }
+ if (!fs::exists(path) && !fs::create_directories(path)) {
+ throw std::runtime_error(strprintf("Failed to create directory at -exportdir '%s'", path.string()));
+ }
+ }
+ return path;
+}
+
+
const boost::filesystem::path &GetDataDir(bool fNetSpecific)
{
namespace fs = boost::filesystem;
boost::filesystem::path GetConfigFile()
{
- boost::filesystem::path pathConfigFile(GetArg("-conf", "bitcoin.conf"));
+ boost::filesystem::path pathConfigFile(GetArg("-conf", "zcash.conf"));
if (!pathConfigFile.is_complete())
pathConfigFile = GetDataDir(false) / pathConfigFile;
{
boost::filesystem::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good())
- return; // No bitcoin.conf file is OK
+ throw missing_zcash_conf();
set<string> setOptions;
setOptions.insert("*");
for (boost::program_options::detail::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
{
- // Don't overwrite existing settings so command line settings override bitcoin.conf
+ // Don't overwrite existing settings so command line settings override zcash.conf
string strKey = string("-") + it->string_key;
if (mapSettingsRet.count(strKey) == 0)
{
#ifndef WIN32
boost::filesystem::path GetPidFile()
{
- boost::filesystem::path pathPidFile(GetArg("-pid", "bitcoind.pid"));
+ boost::filesystem::path pathPidFile(GetArg("-pid", "zcashd.pid"));
if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile;
return pathPidFile;
}
#endif
}
-void runCommand(std::string strCommand)
+void runCommand(const std::string& strCommand)
{
int nErr = ::system(strCommand.c_str());
if (nErr)
void SetupEnvironment()
{
- std::locale loc("C");
// On most POSIX systems (e.g. Linux, but not BSD) the environment's locale
// may be invalid, in which case the "C" locale is used as fallback.
#if !defined(WIN32) && !defined(MAC_OSX) && !defined(__FreeBSD__) && !defined(__OpenBSD__)
try {
- loc = std::locale(""); // Raises a runtime error if current locale is invalid
+ std::locale(""); // Raises a runtime error if current locale is invalid
} catch (const std::runtime_error&) {
setenv("LC_ALL", "C", 1);
}
#endif
- // The path locale is lazy initialized and to avoid deinitialization errors
+ // The path locale is lazy initialized and to avoid deinitialization errors
// in multithreading environments, it is set explicitly by the main thread.
+ // A dummy locale is used to extract the internal default locale, used by
+ // boost::filesystem::path, which is then used to explicitly imbue the path.
+ std::locale loc = boost::filesystem::path::imbue(std::locale::classic());
boost::filesystem::path::imbue(loc);
}
#endif // PRIO_THREAD
#endif // WIN32
}
+
+std::string LicenseInfo()
+{
+ return FormatParagraph(strprintf(_("Copyright (C) 2009-%i The Bitcoin Core Developers"), COPYRIGHT_YEAR)) + "\n" +
+ FormatParagraph(strprintf(_("Copyright (C) 2015-%i The Zcash Developers"), COPYRIGHT_YEAR)) + "\n" +
+ "\n" +
+ FormatParagraph(_("This is experimental software.")) + "\n" +
+ "\n" +
+ FormatParagraph(_("Distributed under the MIT software license, see the accompanying file COPYING or <http://www.opensource.org/licenses/mit-license.php>.")) + "\n" +
+ "\n" +
+ FormatParagraph(_("This product includes software developed by the OpenSSL Project for use in the OpenSSL Toolkit <https://www.openssl.org/> and cryptographic software written by Eric Young and UPnP software written by Thomas Bernard.")) +
+ "\n";
+}