e7a6f79e5a
027fdb8 When/if the copyright line does not mention Bitcoin Core developers, add a second line to copyrights in -version, About dialog, and splash screen (Luke Dashjr) cc2095e Rewrite FormatParagraph to handle newlines within input strings correctly (Luke Dashjr) cddffaf Bugfix: Include COPYRIGHT_HOLDERS_SUBSTITUTION in Makefile substitutions so it gets passed to extract-strings correctly (Luke Dashjr) 29598e4 Move PACKAGE_URL to configure.ac (Luke Dashjr) 78ec83d splashscreen: Resize text to fit exactly (Luke Dashjr) 3cae140 Bugfix: Actually use _COPYRIGHT_HOLDERS_SUBSTITUTION everywhere (Luke Dashjr) 4d5a3df Bugfix: gitian-descriptors: Add missing python-setuptools requirement for OS X (biplist module) (Luke Dashjr) e4ab5e5 Bugfix: Correct copyright year in Mac DMG background image (Luke Dashjr) 917b1d0 Set copyright holders displayed in notices separately from the package name (Luke Dashjr) c39a6ff Travis & gitian-osx: Use depends for ds_store and mac_alias modules (Luke Dashjr) 902ccde depends: Add mac_alias to depends (Luke Dashjr) 82a2d98 depends: Add ds_store to depends (Cory Fields) de619a3 depends: Pass PYTHONPATH along to configure (Cory Fields) e611b6e macdeploy: Use rsvg-convert rather than cairosvg (Luke Dashjr) 63bcdc5 More complicated package name substitution for Mac deployment (Luke Dashjr) 1a6c67c Parameterise 2009 in translatable copyright strings (Luke Dashjr) d5f4683 Unify package name to as few places as possible without major changes (Luke Dashjr)
207 lines
6.4 KiB
C++
207 lines
6.4 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// Copyright (c) 2014-2017 The Dash Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
#include "config/dash-config.h"
|
|
#endif
|
|
|
|
#include "chainparams.h"
|
|
#include "clientversion.h"
|
|
#include "rpc/server.h"
|
|
#include "init.h"
|
|
#include "noui.h"
|
|
#include "scheduler.h"
|
|
#include "util.h"
|
|
#include "masternodeconfig.h"
|
|
#include "httpserver.h"
|
|
#include "httprpc.h"
|
|
#include "utilstrencodings.h"
|
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/thread.hpp>
|
|
|
|
#include <stdio.h>
|
|
|
|
/* Introduction text for doxygen: */
|
|
|
|
/*! \mainpage Developer documentation
|
|
*
|
|
* \section intro_sec Introduction
|
|
*
|
|
* This is the developer documentation of the reference client for an experimental new digital currency called Dash (https://www.dash.org/),
|
|
* which enables instant payments to anyone, anywhere in the world. Dash uses peer-to-peer technology to operate
|
|
* with no central authority: managing transactions and issuing money are carried out collectively by the network.
|
|
*
|
|
* The software is a community-driven open source project, released under the MIT license.
|
|
*
|
|
* \section Navigation
|
|
* Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
|
|
*/
|
|
|
|
static bool fDaemon;
|
|
|
|
void WaitForShutdown(boost::thread_group* threadGroup)
|
|
{
|
|
bool fShutdown = ShutdownRequested();
|
|
// Tell the main threads to shutdown.
|
|
while (!fShutdown)
|
|
{
|
|
MilliSleep(200);
|
|
fShutdown = ShutdownRequested();
|
|
}
|
|
if (threadGroup)
|
|
{
|
|
Interrupt(*threadGroup);
|
|
threadGroup->join_all();
|
|
}
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// Start
|
|
//
|
|
bool AppInit(int argc, char* argv[])
|
|
{
|
|
boost::thread_group threadGroup;
|
|
CScheduler scheduler;
|
|
|
|
bool fRet = false;
|
|
|
|
//
|
|
// Parameters
|
|
//
|
|
// If Qt is used, parameters/dash.conf are parsed in qt/dash.cpp's main()
|
|
ParseParameters(argc, argv);
|
|
|
|
// Process help and version before taking care about datadir
|
|
if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
|
|
{
|
|
std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";
|
|
|
|
if (mapArgs.count("-version"))
|
|
{
|
|
strUsage += FormatParagraph(LicenseInfo());
|
|
}
|
|
else
|
|
{
|
|
strUsage += "\n" + _("Usage:") + "\n" +
|
|
" dashd [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";
|
|
|
|
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
|
|
}
|
|
|
|
fprintf(stdout, "%s", strUsage.c_str());
|
|
return true;
|
|
}
|
|
|
|
try
|
|
{
|
|
bool datadirFromCmdLine = mapArgs.count("-datadir") != 0;
|
|
if (datadirFromCmdLine && !boost::filesystem::is_directory(GetDataDir(false)))
|
|
{
|
|
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
|
|
return false;
|
|
}
|
|
try
|
|
{
|
|
ReadConfigFile(mapArgs, mapMultiArgs);
|
|
} catch (const std::exception& e) {
|
|
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
|
|
return false;
|
|
}
|
|
if (!datadirFromCmdLine && !boost::filesystem::is_directory(GetDataDir(false)))
|
|
{
|
|
fprintf(stderr, "Error: Specified data directory \"%s\" from config file does not exist.\n", mapArgs["-datadir"].c_str());
|
|
return EXIT_FAILURE;
|
|
}
|
|
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
|
try {
|
|
SelectParams(ChainNameFromCommandLine());
|
|
} catch (const std::exception& e) {
|
|
fprintf(stderr, "Error: %s\n", e.what());
|
|
return false;
|
|
}
|
|
|
|
// parse masternode.conf
|
|
std::string strErr;
|
|
if(!masternodeConfig.read(strErr)) {
|
|
fprintf(stderr,"Error reading masternode configuration file: %s\n", strErr.c_str());
|
|
return false;
|
|
}
|
|
|
|
// Command-line RPC
|
|
bool fCommandLine = false;
|
|
for (int i = 1; i < argc; i++)
|
|
if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "dash:"))
|
|
fCommandLine = true;
|
|
|
|
if (fCommandLine)
|
|
{
|
|
fprintf(stderr, "Error: There is no RPC client functionality in dashd anymore. Use the dash-cli utility instead.\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
#ifndef WIN32
|
|
fDaemon = GetBoolArg("-daemon", false);
|
|
if (fDaemon)
|
|
{
|
|
fprintf(stdout, "Dash Core server starting\n");
|
|
|
|
// Daemonize
|
|
pid_t pid = fork();
|
|
if (pid < 0)
|
|
{
|
|
fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
|
|
return false;
|
|
}
|
|
if (pid > 0) // Parent process, pid is child process id
|
|
{
|
|
return true;
|
|
}
|
|
// Child process falls through to rest of initialization
|
|
|
|
pid_t sid = setsid();
|
|
if (sid < 0)
|
|
fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
|
|
}
|
|
#endif
|
|
SoftSetBoolArg("-server", true);
|
|
|
|
// Set this early so that parameter interactions go to console
|
|
InitLogging();
|
|
InitParameterInteraction();
|
|
fRet = AppInit2(threadGroup, scheduler);
|
|
}
|
|
catch (const std::exception& e) {
|
|
PrintExceptionContinue(&e, "AppInit()");
|
|
} catch (...) {
|
|
PrintExceptionContinue(NULL, "AppInit()");
|
|
}
|
|
|
|
if (!fRet)
|
|
{
|
|
Interrupt(threadGroup);
|
|
// threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
|
|
// the startup-failure cases to make sure they don't result in a hang due to some
|
|
// thread-blocking-waiting-for-another-thread-during-startup case
|
|
} else {
|
|
WaitForShutdown(&threadGroup);
|
|
}
|
|
Shutdown();
|
|
|
|
return fRet;
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
SetupEnvironment();
|
|
|
|
// Connect dashd signal handlers
|
|
noui_connect();
|
|
|
|
return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE);
|
|
}
|