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