// Bitflash entry point -- starts node threads then runs GUI (or headless). #include "headers_core.h" #ifndef _WIN32 #include #endif // BITFLASH_NO_GUI builds the same entry point without ImGui, GLFW or OpenGL, // so the binary does not need libGL present just to start. See headless.cpp. #ifndef BITFLASH_NO_GUI int RunGUI(int argc, char* argv[]); #endif // Global definitions (were in ui.cpp, now here) map mapAddressBook; bool gPoolServerRunning = false; static bool arg(int argc, char* argv[], const char* key) { for (int i=1;i= val.size()) { fprintf(stderr, "Ignoring %s: expected ADDRESS:ENCHEX\n", s.c_str()); continue; } vBtfExtraSeeds.push_back(make_pair(val.substr(0, colon), val.substr(colon + 1))); } // net.cpp has described nListenPort as "tunable via /port" since it was // written, but nothing ever read the option, so the port was fixed at 8433 // and a second node could not start on a machine already running one. string strPort = argval2(argc, argv, "/port", "-port"); if (!strPort.empty()) { int nPort = atoi(strPort.c_str()); if (nPort <= 0 || nPort > 65535) fprintf(stderr, "Ignoring /port=%s: not a port number\n", strPort.c_str()); else { nListenPort = htons((unsigned short)nPort); // Or we would announce a port we never bound. addrLocalHost.port = nListenPort; } } } int main(int argc, char* argv[]) { if (arg(argc,argv,"/help") || arg(argc,argv,"-help") || arg(argc,argv,"--help") || arg(argc,argv,"/?")) { PrintUsage(); return 0; } ParseStartupArguments(argc, argv); printf("Loading block index...\n"); string strErrors; if (!LoadBlockIndex()) { fprintf(stderr,"LoadBlockIndex failed\n"); return 1; } printf("Loading wallet...\n"); if (!LoadWallet()) { fprintf(stderr,"LoadWallet failed\n"); return 1; } printf("Height=%d\n", nBestHeight); ReacceptWalletTransactions(); if (!StartNode(strErrors)) { fprintf(stderr,"StartNode: %s\n",strErrors.c_str()); return 1; } if (nMineMode == MINE_OPERATOR) { gPoolServerRunning = true; gPoolRunning = true; if (_beginthread(ThreadRPCServer, 0, NULL) == (uintptr_t)-1) printf("Error: _beginthread(ThreadRPCServer) failed\n"); } if (fGenerateBitcoins) if (_beginthread(ThreadBitcoinMiner, 0, NULL) == (uintptr_t)-1) printf("Error: _beginthread(ThreadBitcoinMiner) failed\n"); #ifdef BITFLASH_NO_GUI // Nothing else this binary can do; /nogui is accepted and redundant. bool fHeadless = true; #else bool fHeadless = arg(argc,argv,"/nogui") || arg(argc,argv,"-nogui") || arg(argc,argv,"/daemon") || arg(argc,argv,"-daemon"); #endif if (fHeadless) { #ifndef _WIN32 auto sig=[](int){fShutdown=true;}; signal(SIGINT,sig); signal(SIGTERM,sig); #endif printf("Running headless. Ctrl-C to stop.\n"); while (!fShutdown) Sleep(500); StopNode(); return 0; } #ifdef BITFLASH_NO_GUI return 0; // unreachable: fHeadless is always true in this build #else int ret = RunGUI(argc, argv); fShutdown = true; StopNode(); return ret; #endif }