1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2013 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or https://www.opensource.org/licenses/mit-license.php .
6 #include "clientversion.h"
7 #include "rpc/server.h"
11 #include "scheduler.h"
13 #include "httpserver.h"
16 #include <boost/algorithm/string/predicate.hpp>
17 #include <boost/filesystem.hpp>
18 #include <boost/thread.hpp>
27 /* Introduction text for doxygen: */
29 /*! \mainpage Developer documentation
31 * \section intro_sec Introduction
33 * This is the developer documentation of the reference client for an experimental new digital currency called Bitcoin (https://www.bitcoin.org/),
34 * which enables instant payments to anyone, anywhere in the world. Bitcoin uses peer-to-peer technology to operate
35 * with no central authority: managing transactions and issuing money are carried out collectively by the network.
37 * The software is a community-driven open source project, released under the MIT license.
40 * Use the buttons <code>Namespaces</code>, <code>Classes</code> or <code>Files</code> at the top of the page to start navigating the code.
44 #define KOMODO_ASSETCHAIN_MAXLEN 65
45 extern char ASSETCHAINS_SYMBOL[KOMODO_ASSETCHAIN_MAXLEN];
46 void komodo_passport_iteration();
47 uint64_t komodo_interestsum();
48 int32_t komodo_longestchain();
50 void WaitForShutdown(boost::thread_group* threadGroup)
52 bool fShutdown = ShutdownRequested();
53 // Tell the main threads to shutdown.
56 //fprintf(stderr,"call passport iteration\n");
57 if ( ASSETCHAINS_SYMBOL[0] == 0 )
59 komodo_passport_iteration();
65 komodo_longestchain();
68 fShutdown = ShutdownRequested();
72 Interrupt(*threadGroup);
73 threadGroup->join_all();
77 //////////////////////////////////////////////////////////////////////////////
81 extern int32_t IS_KOMODO_NOTARY,USE_EXTERNAL_PUBKEY,ASSETCHAIN_INIT;
82 extern std::string NOTARY_PUBKEY;
83 int32_t komodo_is_issuer();
84 void komodo_passport_iteration();
86 bool AppInit(int argc, char* argv[])
88 boost::thread_group threadGroup;
96 // If Qt is used, parameters/komodo.conf are parsed in qt/bitcoin.cpp's main()
97 ParseParameters(argc, argv);
99 // Process help and version before taking care about datadir
100 if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
102 std::string strUsage = _("Komodo Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n" + PrivacyInfo();
104 if (mapArgs.count("-version"))
106 strUsage += LicenseInfo();
110 strUsage += "\n" + _("Usage:") + "\n" +
111 " komodod [options] " + _("Start Komodo Daemon") + "\n";
113 strUsage += "\n" + HelpMessage(HMM_BITCOIND);
116 fprintf(stdout, "%s", strUsage.c_str());
122 if (!AppInitNetworking())
125 void komodo_args(char *argv0);
126 komodo_args(argv[0]);
127 fprintf(stderr,"call komodo_args.(%s) NOTARY_PUBKEY.(%s)\n",argv[0],NOTARY_PUBKEY.c_str());
128 while ( ASSETCHAIN_INIT == 0 )
130 //if ( komodo_is_issuer() != 0 )
131 // komodo_passport_iteration();
133 boost::this_thread::sleep_for(boost::chrono::seconds(1));
138 printf("initialized %s at %u\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL));
139 if (!boost::filesystem::is_directory(GetDataDir(false)))
141 fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
146 ReadConfigFile(mapArgs, mapMultiArgs);
147 } catch (const missing_zcash_conf& e) {
149 (_("Before starting komodod, you need to create a configuration file:\n"
151 "It can be completely empty! That indicates you are happy with the default\n"
152 "configuration of komodod. But requiring a configuration file to start ensures\n"
153 "that komodod won't accidentally compromise your privacy if there was a default\n"
154 "option you needed to change.\n"
156 "You can look at the example configuration file for suggestions of default\n"
157 "options that you may want to change. It should be in one of these locations,\n"
158 "depending on how you installed Komodo:\n") +
159 _("- Source code: %s\n"
160 "- .deb package: %s\n")).c_str(),
161 GetConfigFile().string().c_str(),
162 "contrib/debian/examples/komodo.conf",
163 "/usr/share/doc/komodo/examples/komodo.conf");
165 } catch (const std::exception& e) {
166 fprintf(stderr,"Error reading configuration file: %s\n", e.what());
169 // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
170 if (!SelectParamsFromCommandLine()) {
171 fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
176 bool fCommandLine = false;
177 for (int i = 1; i < argc; i++)
178 if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
183 fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
188 fDaemon = GetBoolArg("-daemon", false);
191 fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
197 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
200 if (pid > 0) // Parent process, pid is child process id
204 // Child process falls through to rest of initialization
206 pid_t sid = setsid();
208 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
211 SoftSetBoolArg("-server", true);
213 fRet = AppInit2(threadGroup, scheduler);
215 catch (const std::exception& e) {
216 PrintExceptionContinue(&e, "AppInit()");
218 PrintExceptionContinue(NULL, "AppInit()");
222 Interrupt(threadGroup);
223 // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
224 // the startup-failure cases to make sure they don't result in a hang due to some
225 // thread-blocking-waiting-for-another-thread-during-startup case
227 WaitForShutdown(&threadGroup);
234 int main(int argc, char* argv[])
238 // Connect bitcoind signal handlers
241 return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE);