]> Git Repo - VerusCoin.git/blame - src/bitcoind.cpp
test
[VerusCoin.git] / src / bitcoind.cpp
CommitLineData
c862d2ff 1// Copyright (c) 2009-2010 Satoshi Nakamoto
f914f1a7 2// Copyright (c) 2009-2013 The Bitcoin Core developers
78253fcb 3// Distributed under the MIT software license, see the accompanying
c862d2ff
CF
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
71697f97 6#include "clientversion.h"
fb78cc23 7#include "rpcserver.h"
c862d2ff 8#include "init.h"
722fa283 9#include "main.h"
51ed9ec9 10#include "noui.h"
ddd0acd3 11#include "scheduler.h"
51ed9ec9
BD
12#include "util.h"
13
c862d2ff 14#include <boost/algorithm/string/predicate.hpp>
51ed9ec9 15#include <boost/filesystem.hpp>
ad49c256 16#include <boost/thread.hpp>
c862d2ff 17
0e165b97
WL
18/* Introduction text for doxygen: */
19
20/*! \mainpage Developer documentation
21 *
22 * \section intro_sec Introduction
23 *
447d37e7 24 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
0e165b97
WL
25 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
26 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
27 *
28 * The software is a community-driven open source project, released under the MIT license.
29 *
30 * \section Navigation
31 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
32 */
33
8b9adca4 34static bool fDaemon;
43a3c405 35extern char ASSETCHAINS_SYMBOL[16];
ab918767 36void komodo_passport_iteration();
8b9adca4 37
28ee7e8b 38void WaitForShutdown(boost::thread_group* threadGroup)
c862d2ff 39{
c55d1600 40 bool fShutdown = ShutdownRequested();
c862d2ff 41 // Tell the main threads to shutdown.
c55d1600 42 while (!fShutdown)
c862d2ff 43 {
2b469f43 44 MilliSleep(10000);
ab918767 45 komodo_passport_iteration();
c55d1600 46 fShutdown = ShutdownRequested();
c862d2ff
CF
47 }
48 if (threadGroup)
c55d1600 49 {
c862d2ff 50 threadGroup->interrupt_all();
c55d1600
PK
51 threadGroup->join_all();
52 }
c862d2ff
CF
53}
54
55//////////////////////////////////////////////////////////////////////////////
56//
57// Start
58//
928b75a4 59extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
86ea7309 60extern std::string NOTARY_PUBKEY;
654dfaaf 61int32_t komodo_is_issuer();
35fc5e66 62void komodo_passport_iteration();
86ea7309 63
c862d2ff
CF
64bool AppInit(int argc, char* argv[])
65{
66 boost::thread_group threadGroup;
ddd0acd3 67 CScheduler scheduler;
c862d2ff
CF
68
69 bool fRet = false;
3d0a1ce1
PJ
70
71 //
72 // Parameters
73 //
5166804f 74 // If Qt is used, parameters/komodo.conf are parsed in qt/bitcoin.cpp's main()
3d0a1ce1
PJ
75 ParseParameters(argc, argv);
76
77 // Process help and version before taking care about datadir
af6edac0 78 if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
3d0a1ce1 79 {
5166804f 80 std::string strUsage = _("Komodo Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
3d0a1ce1
PJ
81
82 if (mapArgs.count("-version"))
83 {
84 strUsage += LicenseInfo();
85 }
86 else
87 {
88 strUsage += "\n" + _("Usage:") + "\n" +
5166804f 89 " komodod [options] " + _("Start Komodo Daemon") + "\n";
3d0a1ce1
PJ
90
91 strUsage += "\n" + HelpMessage(HMM_BITCOIND);
92 }
93
94 fprintf(stdout, "%s", strUsage.c_str());
95 return false;
96 }
97
c862d2ff
CF
98 try
99 {
561ff778 100 void komodo_args();
101 komodo_args();
533a5d5d 102 fprintf(stderr,"call komodo_args NOTARY_PUBKEY.(%s)\n",NOTARY_PUBKEY.c_str());
928b75a4 103 while ( ASSETCHAIN_INIT == 0 )
104 {
35fc5e66 105 //if ( komodo_is_issuer() != 0 )
214fa084 106 // komodo_passport_iteration();
928b75a4 107 sleep(1);
108 }
aa6b6152 109 printf("initialized %s\n",ASSETCHAINS_SYMBOL);
c862d2ff
CF
110 if (!boost::filesystem::is_directory(GetDataDir(false)))
111 {
a2189fba
PK
112 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
113 return false;
c862d2ff 114 }
4ae5e721
WL
115 try
116 {
117 ReadConfigFile(mapArgs, mapMultiArgs);
27df4123 118 } catch (const std::exception& e) {
4ae5e721
WL
119 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
120 return false;
121 }
a3d946eb 122 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
a2189fba
PK
123 if (!SelectParamsFromCommandLine()) {
124 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
125 return false;
126 }
561ff778 127
c862d2ff 128 // Command-line RPC
917ac1dc 129 bool fCommandLine = false;
c862d2ff 130 for (int i = 1; i < argc; i++)
5166804f 131 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
c862d2ff
CF
132 fCommandLine = true;
133
134 if (fCommandLine)
135 {
5166804f 136 fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
b750cf1f 137 exit(1);
c862d2ff 138 }
998397aa 139
a034c7eb 140#ifndef WIN32
c862d2ff
CF
141 fDaemon = GetBoolArg("-daemon", false);
142 if (fDaemon)
143 {
ce906ce7 144 fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
8b9adca4 145
c862d2ff
CF
146 // Daemonize
147 pid_t pid = fork();
148 if (pid < 0)
149 {
150 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
151 return false;
152 }
153 if (pid > 0) // Parent process, pid is child process id
154 {
c862d2ff
CF
155 return true;
156 }
157 // Child process falls through to rest of initialization
158
159 pid_t sid = setsid();
160 if (sid < 0)
161 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
162 }
163#endif
8b9adca4 164 SoftSetBoolArg("-server", true);
c862d2ff 165
ddd0acd3 166 fRet = AppInit2(threadGroup, scheduler);
c862d2ff 167 }
27df4123 168 catch (const std::exception& e) {
c862d2ff
CF
169 PrintExceptionContinue(&e, "AppInit()");
170 } catch (...) {
171 PrintExceptionContinue(NULL, "AppInit()");
172 }
c55d1600
PK
173
174 if (!fRet)
175 {
c862d2ff 176 threadGroup.interrupt_all();
c55d1600
PK
177 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
178 // the startup-failure cases to make sure they don't result in a hang due to some
179 // thread-blocking-waiting-for-another-thread-during-startup case
28ee7e8b
WL
180 } else {
181 WaitForShutdown(&threadGroup);
c862d2ff
CF
182 }
183 Shutdown();
184
185 return fRet;
186}
187
c862d2ff
CF
188int main(int argc, char* argv[])
189{
5248ff40
SC
190 SetupEnvironment();
191
c862d2ff
CF
192 // Connect bitcoind signal handlers
193 noui_connect();
194
0b78ba8a 195 return (AppInit(argc, argv) ? 0 : 1);
c862d2ff 196}
This page took 0.200215 seconds and 4 git commands to generate.