]> Git Repo - VerusCoin.git/blob - src/bitcoind.cpp
Merge branch 'mike'
[VerusCoin.git] / src / bitcoind.cpp
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 http://www.opensource.org/licenses/mit-license.php.
5
6 #include "clientversion.h"
7 #include "rpc/server.h"
8 #include "init.h"
9 #include "main.h"
10 #include "noui.h"
11 #include "scheduler.h"
12 #include "util.h"
13 #include "httpserver.h"
14 #include "httprpc.h"
15
16 #include <boost/algorithm/string/predicate.hpp>
17 #include <boost/filesystem.hpp>
18 #include <boost/thread.hpp>
19
20 #include <stdio.h>
21
22 #ifdef _WIN32
23 #define frpintf(...)
24 #define printf(...)
25 #endif
26
27 /* Introduction text for doxygen: */
28
29 /*! \mainpage Developer documentation
30  *
31  * \section intro_sec Introduction
32  *
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.
36  *
37  * The software is a community-driven open source project, released under the MIT license.
38  *
39  * \section Navigation
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.
41  */
42
43 static bool fDaemon;
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();
49
50 void WaitForShutdown(boost::thread_group* threadGroup)
51 {
52     bool fShutdown = ShutdownRequested();
53     // Tell the main threads to shutdown.
54     while (!fShutdown)
55     {
56         //fprintf(stderr,"call passport iteration\n");
57         if ( ASSETCHAINS_SYMBOL[0] == 0 )
58         {
59             komodo_passport_iteration();
60             MilliSleep(10000);
61         }
62         else
63         {
64             komodo_interestsum();
65             komodo_longestchain();
66             MilliSleep(20000);
67         }
68         fShutdown = ShutdownRequested();
69     }
70     if (threadGroup)
71     {
72         Interrupt(*threadGroup);
73         threadGroup->join_all();
74     }
75 }
76
77 //////////////////////////////////////////////////////////////////////////////
78 //
79 // Start
80 //
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();
85
86 bool AppInit(int argc, char* argv[])
87 {
88     boost::thread_group threadGroup;
89     CScheduler scheduler;
90
91     bool fRet = false;
92
93     //
94     // Parameters
95     //
96     // If Qt is used, parameters/komodo.conf are parsed in qt/bitcoin.cpp's main()
97     ParseParameters(argc, argv);
98
99     // Process help and version before taking care about datadir
100     if (mapArgs.count("-?") || mapArgs.count("-h") ||  mapArgs.count("-help") || mapArgs.count("-version"))
101     {
102         std::string strUsage = _("Komodo Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n" + PrivacyInfo();
103
104         if (mapArgs.count("-version"))
105         {
106             strUsage += LicenseInfo();
107         }
108         else
109         {
110             strUsage += "\n" + _("Usage:") + "\n" +
111                   "  komodod [options]                     " + _("Start Komodo Daemon") + "\n";
112
113             strUsage += "\n" + HelpMessage(HMM_BITCOIND);
114         }
115
116         fprintf(stdout, "%s", strUsage.c_str());
117         return true;
118     }
119
120     try
121     {
122         void komodo_args(char *argv0);
123         komodo_args(argv[0]);
124         fprintf(stderr,"call komodo_args.(%s) NOTARY_PUBKEY.(%s)\n",argv[0],NOTARY_PUBKEY.c_str());
125         while ( ASSETCHAIN_INIT == 0 )
126         {
127             //if ( komodo_is_issuer() != 0 )
128             //    komodo_passport_iteration();
129             #ifdef _WIN32
130             boost::this_thread::sleep_for(boost::chrono::seconds(1));
131             #else
132             sleep(1);
133             #endif
134         }
135         printf("initialized %s at %u\n",ASSETCHAINS_SYMBOL,(uint32_t)time(NULL));
136         if (!boost::filesystem::is_directory(GetDataDir(false)))
137         {
138             fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
139             return false;
140         }
141         try
142         {
143             ReadConfigFile(mapArgs, mapMultiArgs);
144         } catch (const missing_zcash_conf& e) {
145             fprintf(stderr,
146                 (_("Before starting komodod, you need to create a configuration file:\n"
147                    "%s\n"
148                    "It can be completely empty! That indicates you are happy with the default\n"
149                    "configuration of komodod. But requiring a configuration file to start ensures\n"
150                    "that komodod won't accidentally compromise your privacy if there was a default\n"
151                    "option you needed to change.\n"
152                    "\n"
153                    "You can look at the example configuration file for suggestions of default\n"
154                    "options that you may want to change. It should be in one of these locations,\n"
155                    "depending on how you installed Komodo:\n") +
156                  _("- Source code:  %s\n"
157                    "- .deb package: %s\n")).c_str(),
158                 GetConfigFile().string().c_str(),
159                 "contrib/debian/examples/komodo.conf",
160                 "/usr/share/doc/komodo/examples/komodo.conf");
161             return false;
162         } catch (const std::exception& e) {
163             fprintf(stderr,"Error reading configuration file: %s\n", e.what());
164             return false;
165         }
166         // Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
167         if (!SelectParamsFromCommandLine()) {
168             fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
169             return false;
170         }
171
172         // Command-line RPC
173         bool fCommandLine = false;
174         for (int i = 1; i < argc; i++)
175             if (!IsSwitchChar(argv[i][0]) && !boost::algorithm::istarts_with(argv[i], "komodo:"))
176                 fCommandLine = true;
177
178         if (fCommandLine)
179         {
180             fprintf(stderr, "Error: There is no RPC client functionality in komodod. Use the komodo-cli utility instead.\n");
181             exit(EXIT_FAILURE);
182         }
183
184 #ifndef _WIN32
185         fDaemon = GetBoolArg("-daemon", false);
186         if (fDaemon)
187         {
188             fprintf(stdout, "Komodo %s server starting\n",ASSETCHAINS_SYMBOL);
189
190             // Daemonize
191             pid_t pid = fork();
192             if (pid < 0)
193             {
194                 fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);
195                 return false;
196             }
197             if (pid > 0) // Parent process, pid is child process id
198             {
199                 return true;
200             }
201             // Child process falls through to rest of initialization
202
203             pid_t sid = setsid();
204             if (sid < 0)
205                 fprintf(stderr, "Error: setsid() returned %d errno %d\n", sid, errno);
206         }
207 #endif
208         SoftSetBoolArg("-server", true);
209
210         fRet = AppInit2(threadGroup, scheduler);
211     }
212     catch (const std::exception& e) {
213         PrintExceptionContinue(&e, "AppInit()");
214     } catch (...) {
215         PrintExceptionContinue(NULL, "AppInit()");
216     }
217     if (!fRet)
218     {
219         Interrupt(threadGroup);
220         // threadGroup.join_all(); was left out intentionally here, because we didn't re-test all of
221         // the startup-failure cases to make sure they don't result in a hang due to some
222         // thread-blocking-waiting-for-another-thread-during-startup case
223     } else {
224         WaitForShutdown(&threadGroup);
225     }
226     Shutdown();
227
228     return fRet;
229 }
230
231 int main(int argc, char* argv[])
232 {
233     SetupEnvironment();
234
235     // Connect bitcoind signal handlers
236     noui_connect();
237
238     return (AppInit(argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE);
239 }
This page took 0.036818 seconds and 4 git commands to generate.