8 #if defined(HAVE_CONFIG_H)
41 #include <boost/algorithm/string/predicate.hpp>
42 #include <boost/filesystem.hpp>
43 #include <boost/interprocess/sync/file_lock.hpp>
44 #include <openssl/crypto.h>
47 using namespace boost;
58 #define MIN_CORE_FILEDESCRIPTORS 0
60 #define MIN_CORE_FILEDESCRIPTORS 150
105 fRequestShutdown =
true;
116 LogPrintf(
"Shutdown : In progress...\n");
118 TRY_LOCK(cs_Shutdown, lockShutdown);
119 if (!lockShutdown)
return;
143 delete pcoinsdbview; pcoinsdbview = NULL;
164 fRequestShutdown =
true;
172 bool static InitError(
const std::string &str)
178 bool static InitWarning(
const std::string &str)
184 bool static Bind(
const CService &addr,
unsigned int flags) {
187 std::string strError;
190 return InitError(strError);
199 string strUsage =
_(
"Options:") +
"\n";
200 strUsage +=
" -? " +
_(
"This help message") +
"\n";
201 strUsage +=
" -alertnotify=<cmd> " +
_(
"Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)") +
"\n";
202 strUsage +=
" -blocknotify=<cmd> " +
_(
"Execute command when the best block changes (%s in cmd is replaced by block hash)") +
"\n";
203 strUsage +=
" -checkblocks=<n> " +
_(
"How many blocks to check at startup (default: 288, 0 = all)") +
"\n";
204 strUsage +=
" -checklevel=<n> " +
_(
"How thorough the block verification of -checkblocks is (0-4, default: 3)") +
"\n";
205 strUsage +=
" -conf=<file> " +
_(
"Specify configuration file (default: anoncoin.conf)") +
"\n";
209 strUsage +=
" -daemon " +
_(
"Run in the background as a daemon and accept commands") +
"\n";
212 strUsage +=
" -datadir=<dir> " +
_(
"Specify data directory") +
"\n";
213 strUsage +=
" -dbcache=<n> " +
strprintf(
_(
"Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache) +
"\n";
214 strUsage +=
" -loadblock=<file> " +
_(
"Imports blocks from external blk000??.dat file") +
" " +
_(
"on startup") +
"\n";
215 strUsage +=
" -maxorphanblocks=<n> " +
strprintf(
_(
"Keep at most <n> unconnectable blocks in memory (default: %u)"), DEFAULT_MAX_ORPHAN_BLOCKS) +
"\n";
216 strUsage +=
" -maxorphantx=<n> " +
strprintf(
_(
"Keep at most <n> unconnectable transactions in memory (default: %u)"), DEFAULT_MAX_ORPHAN_TRANSACTIONS) +
"\n";
217 strUsage +=
" -par=<n> " +
strprintf(
_(
"Set the number of script verification threads (%u to %d, 0 = auto, <0 = leave that many cores free, default: %d)"), -(
int)boost::thread::hardware_concurrency(), MAX_SCRIPTCHECK_THREADS, DEFAULT_SCRIPTCHECK_THREADS) +
"\n";
218 strUsage +=
" -pid=<file> " +
_(
"Specify pid file (default: anoncoind.pid)") +
"\n";
219 strUsage +=
" -reindex " +
_(
"Rebuild block chain index from current blk000??.dat files") +
" " +
_(
"on startup") +
"\n";
220 strUsage +=
" -txindex " +
_(
"Maintain a full transaction index (default: 0)") +
"\n";
222 strUsage +=
"\n" +
_(
"Connection options:") +
"\n";
223 strUsage +=
" -addnode=<ip> " +
_(
"Add a node to connect to and attempt to keep the connection open") +
"\n";
224 strUsage +=
" -banscore=<n> " +
_(
"Threshold for disconnecting misbehaving peers (default: 100)") +
"\n";
225 strUsage +=
" -bantime=<n> " +
_(
"Number of seconds to keep misbehaving peers from reconnecting (default: 86400)") +
"\n";
226 strUsage +=
" -bind=<addr> " +
_(
"Bind to given address and always listen on it. Use [host]:port notation for IPv6") +
"\n";
227 strUsage +=
" -connect=<ip> " +
_(
"Connect only to the specified node(s)") +
"\n";
228 strUsage +=
" -discover " +
_(
"Discover own IP address (default: 1 when listening and no -externalip)") +
"\n";
229 strUsage +=
" -dns " +
_(
"Allow DNS lookups for -addnode, -seednode and -connect") +
" " +
_(
"(default: 1)") +
"\n";
230 strUsage +=
" -dnsseed " +
_(
"Query for peer addresses via DNS lookup, if low on addresses (default: 1 unless -connect)") +
"\n";
231 strUsage +=
" -forcednsseed " +
_(
"Always query for peer addresses via DNS lookup (default: 0)") +
"\n";
232 strUsage +=
" -externalip=<ip> " +
_(
"Specify your own public address") +
"\n";
233 strUsage +=
" -listen " +
_(
"Accept connections from outside (default: 1 if no -proxy or -connect)") +
"\n";
234 strUsage +=
" -maxconnections=<n> " +
_(
"Maintain at most <n> connections to peers (default: 125)") +
"\n";
235 strUsage +=
" -maxreceivebuffer=<n> " +
_(
"Maximum per-connection receive buffer, <n>*1000 bytes (default: 5000)") +
"\n";
236 strUsage +=
" -maxsendbuffer=<n> " +
_(
"Maximum per-connection send buffer, <n>*1000 bytes (default: 1000)") +
"\n";
237 strUsage +=
" -onion=<ip:port> " +
_(
"Use separate SOCKS5 proxy to reach peers via Tor hidden services (default: -proxy)") +
"\n";
238 strUsage +=
" -onlynet=<net> " +
_(
"Only connect to nodes in network <net> (ipv4, ipv6, onion or i2p)") +
"\n";
239 strUsage +=
" -port=<port> " +
_(
"Listen for connections on <port> (default: 9333 or testnet: 19333)") +
"\n";
240 strUsage +=
" -proxy=<ip:port> " +
_(
"Connect through SOCKS5 proxy") +
"\n";
241 strUsage +=
" -seednode=<ip> " +
_(
"Connect to a node to retrieve peer addresses, and disconnect") +
"\n";
242 strUsage +=
" -timeout=<n> " +
_(
"Specify connection timeout in milliseconds (default: 20000)") +
"\n";
245 strUsage +=
" -upnp " +
_(
"Use UPnP to map the listening port (default: 1 when listening)") +
"\n";
247 strUsage +=
" -upnp " +
_(
"Use UPnP to map the listening port (default: 0)") +
"\n";
252 strUsage +=
"\n" +
_(
"Wallet options:") +
"\n";
253 strUsage +=
" -disablewallet " +
_(
"Do not load the wallet and disable wallet RPC calls") +
"\n";
254 strUsage +=
" -keypool=<n> " +
_(
"Set key pool size to <n> (default: 100)") +
"\n";
255 strUsage +=
" -paytxfee=<amt> " +
_(
"Fee per kB to add to transactions you send") +
"\n";
256 strUsage +=
" -rescan " +
_(
"Rescan the block chain for missing wallet transactions") +
" " +
_(
"on startup") +
"\n";
257 strUsage +=
" -salvagewallet " +
_(
"Attempt to recover private keys from a corrupt wallet.dat") +
" " +
_(
"on startup") +
"\n";
258 strUsage +=
" -spendzeroconfchange " +
_(
"Spend unconfirmed change when sending transactions (default: 1)") +
"\n";
259 strUsage +=
" -upgradewallet " +
_(
"Upgrade wallet to latest format") +
" " +
_(
"on startup") +
"\n";
260 strUsage +=
" -wallet=<file> " +
_(
"Specify wallet file (within data directory)") +
" " +
_(
"(default: wallet.dat)") +
"\n";
261 strUsage +=
" -walletnotify=<cmd> " +
_(
"Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") +
"\n";
262 strUsage +=
" -zapwallettxes " +
_(
"Clear list of wallet transactions (diagnostic tool; implies -rescan)") +
"\n";
265 strUsage +=
"\n" +
_(
"Debugging/Testing options:") +
"\n";
268 strUsage +=
" -benchmark " +
_(
"Show benchmark information (default: 0)") +
"\n";
269 strUsage +=
" -checkpoints " +
_(
"Only accept block chain matching built-in checkpoints (default: 1)") +
"\n";
270 strUsage +=
" -dblogsize=<n> " +
_(
"Flush database activity from memory pool to disk log every <n> megabytes (default: 100)") +
"\n";
271 strUsage +=
" -disablesafemode " +
_(
"Disable safemode, override a real safe mode event (default: 0)") +
"\n";
272 strUsage +=
" -testsafemode " +
_(
"Force safe mode (default: 0)") +
"\n";
273 strUsage +=
" -dropmessagestest=<n> " +
_(
"Randomly drop 1 of every <n> network messages") +
"\n";
274 strUsage +=
" -fuzzmessagestest=<n> " +
_(
"Randomly fuzz 1 of every <n> network messages") +
"\n";
275 strUsage +=
" -flushwallet " +
_(
"Run a thread to flush wallet periodically (default: 1)") +
"\n";
277 strUsage +=
" -debug=<category> " +
_(
"Output debugging information (default: 0, supplying <category> is optional)") +
"\n";
278 strUsage +=
" " +
_(
"If <category> is not supplied, output all debugging information.") +
"\n";
279 strUsage +=
" " +
_(
"<category> can be:");
280 strUsage +=
" addrman, alert, coindb, db, lock, rand, rpc, selectcoins, mempool, net";
285 strUsage +=
" -gen " +
_(
"Generate coins (default: 0)") +
"\n";
286 strUsage +=
" -genproclimit=<n> " +
_(
"Set the processor limit for when generation is on (-1 = unlimited, default: -1)") +
"\n";
288 strUsage +=
" -help-debug " +
_(
"Show all debugging options (usage: --help -help-debug)") +
"\n";
289 strUsage +=
" -logtimestamps " +
_(
"Prepend debug output with timestamp (default: 1)") +
"\n";
292 strUsage +=
" -limitfreerelay=<n> " +
_(
"Continuously rate-limit free transactions to <n>*1000 bytes per minute (default:15)") +
"\n";
293 strUsage +=
" -maxsigcachesize=<n> " +
_(
"Limit size of signature cache to <n> entries (default: 50000)") +
"\n";
295 strUsage +=
" -mintxfee=<amt> " +
_(
"Fees smaller than this are considered zero fee (for transaction creation) (default:") +
" " +
FormatMoney(
CTransaction::nMinTxFee) +
")" +
"\n";
297 strUsage +=
" -printtoconsole " +
_(
"Send trace/debug info to console instead of debug.log file") +
"\n";
300 strUsage +=
" -printblock=<hash> " +
_(
"Print block on startup, if found in block index") +
"\n";
301 strUsage +=
" -printblocktree " +
_(
"Print block tree on startup (default: 0)") +
"\n";
302 strUsage +=
" -printpriority " +
_(
"Log transaction priority and fee per kB when mining blocks (default: 0)") +
"\n";
303 strUsage +=
" -privdb " +
_(
"Sets the DB_PRIVATE flag in the wallet db environment (default: 1)") +
"\n";
304 strUsage +=
" -regtest " +
_(
"Enter regression test mode, which uses a special chain in which blocks can be solved instantly.") +
"\n";
305 strUsage +=
" " +
_(
"This is intended for regression testing tools and app development.") +
"\n";
306 strUsage +=
" " +
_(
"In this mode -genproclimit controls how many blocks are generated immediately.") +
"\n";
308 strUsage +=
" -shrinkdebugfile " +
_(
"Shrink debug.log file on client startup (default: 1 when no -debug)") +
"\n";
309 strUsage +=
" -testnet " +
_(
"Use the test network") +
"\n";
311 strUsage +=
"\n" +
_(
"Node relay options:") +
"\n";
312 strUsage +=
" -datacarrier " +
_(
"Relay and mine data carrier transactions (default: 1)") +
"\n";
313 strUsage +=
"\n" +
_(
"Block creation options:") +
"\n";
314 strUsage +=
" -blockminsize=<n> " +
_(
"Set minimum block size in bytes (default: 0)") +
"\n";
315 strUsage +=
" -blockmaxsize=<n> " +
strprintf(
_(
"Set maximum block size in bytes (default: %d)"), DEFAULT_BLOCK_MAX_SIZE) +
"\n";
316 strUsage +=
" -blockprioritysize=<n> " +
strprintf(
_(
"Set maximum size of high-priority/low-fee transactions in bytes (default: %d)"), DEFAULT_BLOCK_PRIORITY_SIZE) +
"\n";
318 strUsage +=
"\n" +
_(
"RPC server options:") +
"\n";
319 strUsage +=
" -server " +
_(
"Accept command line and JSON-RPC commands") +
"\n";
320 strUsage +=
" -rpcuser=<user> " +
_(
"Username for JSON-RPC connections") +
"\n";
321 strUsage +=
" -rpcpassword=<pw> " +
_(
"Password for JSON-RPC connections") +
"\n";
322 strUsage +=
" -rpcport=<port> " +
_(
"Listen for JSON-RPC connections on <port> (default: 9332 or testnet: 19332)") +
"\n";
323 strUsage +=
" -rpcallowip=<ip> " +
_(
"Allow JSON-RPC connections from specified IP address") +
"\n";
324 strUsage +=
" -rpcthreads=<n> " +
_(
"Set the number of threads to service RPC calls (default: 4)") +
"\n";
326 strUsage +=
"\n" +
_(
"RPC SSL options: (see the Bitcoin Wiki for SSL setup instructions)") +
"\n";
327 strUsage +=
" -rpcssl " +
_(
"Use OpenSSL (https) for JSON-RPC connections") +
"\n";
328 strUsage +=
" -rpcsslcertificatechainfile=<file.cert> " +
_(
"Server certificate file (default: server.cert)") +
"\n";
329 strUsage +=
" -rpcsslprivatekeyfile=<file.pem> " +
_(
"Server private key (default: server.pem)") +
"\n";
330 strUsage +=
" -rpcsslciphers=<ciphers> " +
_(
"Acceptable ciphers (default: TLSv1.2+HIGH:TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!3DES:@STRENGTH)") +
"\n";
361 LogPrintf(
"Reindexing block file blk%05u.dat...\n", (
unsigned int)nFile);
373 filesystem::path pathBootstrap =
GetDataDir() /
"bootstrap.dat";
374 if (filesystem::exists(pathBootstrap)) {
375 FILE *file = fopen(pathBootstrap.string().c_str(),
"rb");
378 filesystem::path pathBootstrapOld =
GetDataDir() /
"bootstrap.dat.old";
379 LogPrintf(
"Importing bootstrap.dat...\n");
383 LogPrintf(
"Warning: Could not open bootstrap file %s\n", pathBootstrap.string());
388 BOOST_FOREACH(boost::filesystem::path &path, vImportFiles) {
389 FILE *file = fopen(path.string().c_str(),
"rb");
392 LogPrintf(
"Importing blocks file %s...\n", path.string());
395 LogPrintf(
"Warning: Could not open blocks file %s\n", path.string());
407 InitError(
"OpenSSL appears to lack support for elliptic curve cryptography. For more "
408 "information, visit https://en.bitcoin.it/wiki/OpenSSL_and_EC_Libraries");
425 _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
426 _CrtSetReportFile(_CRT_WARN, CreateFileA(
"NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));
430 _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
436 #ifndef PROCESS_DEP_ENABLE
439 #define PROCESS_DEP_ENABLE 0x00000001
441 typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD);
442 PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA(
"Kernel32.dll"),
"SetProcessDEPPolicy");
443 if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE);
447 int ret = WSAStartup(MAKEWORD(2,2), &wsadata);
448 if (ret != NO_ERROR || LOBYTE(wsadata.wVersion ) != 2 || HIBYTE(wsadata.wVersion) != 2)
450 return InitError(
strprintf(
"Error: Winsock library failed to start (WSAStartup returned error %d)", ret));
459 sigemptyset(&sa.sa_mask);
461 sigaction(SIGTERM, &sa, NULL);
462 sigaction(SIGINT, &sa, NULL);
465 struct sigaction sa_hup;
467 sigemptyset(&sa_hup.sa_mask);
469 sigaction(SIGHUP, &sa_hup, NULL);
471 #if defined (__SVR4) && defined (__sun)
473 signal(SIGPIPE, SIG_IGN);
483 LogPrintf(
"AppInit2 : parameter interaction: -bind set -> setting -listen=1\n");
489 LogPrintf(
"AppInit2 : parameter interaction: -connect set -> setting -dnsseed=0\n");
491 LogPrintf(
"AppInit2 : parameter interaction: -connect set -> setting -listen=0\n");
497 LogPrintf(
"AppInit2 : parameter interaction: -proxy set -> setting -listen=0\n");
503 LogPrintf(
"AppInit2 : parameter interaction: -listen=0 -> setting -upnp=0\n");
505 LogPrintf(
"AppInit2 : parameter interaction: -listen=0 -> setting -discover=0\n");
508 if (
mapArgs.count(
"-externalip")) {
511 LogPrintf(
"AppInit2 : parameter interaction: -externalip set -> setting -discover=0\n");
517 LogPrintf(
"AppInit2 : parameter interaction: -salvagewallet=1 -> setting -rescan=1\n");
523 LogPrintf(
"AppInit2 : parameter interaction: -zapwallettxes=1 -> setting -rescan=1\n");
527 int nBind = std::max((
int)
mapArgs.count(
"-bind"), 1);
532 return InitError(
_(
"Not enough file descriptors available."));
540 const vector<string>& categories =
mapMultiArgs[
"-debug"];
541 if (
GetBoolArg(
"-nodebug",
false) || find(categories.begin(), categories.end(), string(
"0")) != categories.end())
546 InitWarning(
_(
"Warning: Deprecated argument -debugnet ignored, use -debug=net"));
549 return InitError(
_(
"Error: Unsupported argument -socks found. Setting SOCKS version isn't possible anymore, only SOCKS5 proxies are supported."));
552 return InitError(
_(
"Error: Unsupported argument -tor found, use -onion."));
570 setvbuf(stdout, NULL, _IOLBF, 0);
572 bool fDisableWallet =
GetBoolArg(
"-disablewallet",
false);
577 int nNewTimeout =
GetArg(
"-timeout", 20000);
578 if (nNewTimeout > 0 && nNewTimeout < 600000)
585 const char* pszP2SH =
"/P2SH/";
586 COINBASE_FLAGS << std::vector<unsigned char>(pszP2SH, pszP2SH+strlen(pszP2SH));
594 if (
mapArgs.count(
"-mintxfee"))
600 return InitError(
strprintf(
_(
"Invalid amount for -mintxfee=<amount>: '%s'"),
mapArgs[
"-mintxfee"]));
602 if (
mapArgs.count(
"-minrelaytxfee"))
608 return InitError(
strprintf(
_(
"Invalid amount for -minrelaytxfee=<amount>: '%s'"),
mapArgs[
"-minrelaytxfee"]));
612 if (
mapArgs.count(
"-paytxfee"))
615 return InitError(
strprintf(
_(
"Invalid amount for -paytxfee=<amount>: '%s'"),
mapArgs[
"-paytxfee"]));
617 InitWarning(
_(
"Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction."));
626 return InitError(
_(
"Initialization sanity check failed. Anoncoin Core is shutting down."));
628 std::string strDataDir =
GetDataDir().string();
635 boost::filesystem::path pathLockFile =
GetDataDir() /
".lock";
636 FILE* file = fopen(pathLockFile.string().c_str(),
"a");
637 if (file) fclose(file);
638 static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
639 if (!lock.try_lock())
640 return InitError(
strprintf(
_(
"Cannot obtain a lock on data directory %s. Anoncoin Core is probably already running."), strDataDir));
644 LogPrintf(
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
646 LogPrintf(
"Using OpenSSL version %s\n", SSLeay_version(SSLEAY_VERSION));
648 LogPrintf(
"Using BerkeleyDB version %s\n", DbEnv::version(0, 0, 0));
653 LogPrintf(
"Using data directory %s\n", strDataDir);
654 LogPrintf(
"Using at most %i connections (%i file descriptors available)\n", nMaxConnections, nFD);
655 std::ostringstream strErrors;
658 if( !
GetBoolArg(
"-stfu",
false) && !IsBehindDarknet() )
659 InitWarning(
"Anoncoin is running on clearnet!\n");
670 #if defined(USE_SSE2)
671 scrypt_detect_sse2();
676 if (!fDisableWallet) {
683 boost::filesystem::path pathDatabase =
GetDataDir() /
"database";
686 boost::filesystem::rename(pathDatabase, pathDatabaseBak);
687 LogPrintf(
"Moved old %s to %s. Retrying.\n", pathDatabase.string(), pathDatabaseBak.string());
688 }
catch(boost::filesystem::filesystem_error &error) {
695 string msg =
strprintf(
_(
"Error initializing wallet database environment %s!"), strDataDir);
696 return InitError(msg);
712 string msg =
strprintf(
_(
"Warning: wallet.dat corrupt, data salvaged!"
713 " Original wallet.dat saved as wallet.{timestamp}.bak in %s; if"
714 " your balance or transactions are incorrect you should"
715 " restore from a backup."), strDataDir);
719 return InitError(
_(
"wallet.dat corrupt, salvage failed"));
722 #endif // ENABLE_WALLET
727 if (
mapArgs.count(
"-onlynet")) {
728 std::set<enum Network> nets;
729 BOOST_FOREACH(std::string snet,
mapMultiArgs[
"-onlynet"]) {
733 if (net == NET_NATIVE_I2P) {
741 #endif // ENABLE_I2PSAM
744 return InitError(
strprintf(
_(
"Unknown network specified in -onlynet: '%s'"), snet));
747 for (
int n = 0; n <
NET_MAX; n++) {
749 if (!nets.count(net))
759 return InitError(
strprintf(
_(
"Invalid -proxy address: '%s'"),
mapArgs[
"-proxy"]));
771 (fProxy ||
mapArgs.count(
"-onion"))) {
774 addrOnion = addrProxy;
778 return InitError(
strprintf(
_(
"Invalid -onion address: '%s'"),
mapArgs[
"-onion"]));
788 mapArgs[
"-i2p.options.enabled" ] =
"0";
792 bool fGenI2pDest =
GetBoolArg(
"-generatei2pdestination",
false);
794 mapArgs[
"-i2p.options.enabled" ] =
"1";
795 mapArgs[
"-i2p.options.static" ] =
"0";
799 bool fValidI2pSession =
false;
800 std:
string myI2pBase32Key;
803 if( IsI2PEnabled() ) {
806 myI2pBase32Key =
GetArg(
"-i2p.mydestination.base32key",
"");
810 if(
GetBoolArg(
"-i2p.options.static",
false ) ) {
811 LogPrintf(
"Attempting to create an I2P Sam session. With a static destination...\n" );
815 fValidI2pSession =
true;
817 LogPrintf(
"Error - Static Destination mismatch. Result: ShutDown.\n" );
819 LogPrintf(
"Error - invalid I2P keys. Check your configuration file. Result: ShutDown\n" );
821 LogPrintf(
"Attempting to create an I2P Sam session. With a dynamic destination...\n" );
824 myI2pKeys = retI2pKeys;
827 mapArgs[
"-i2p.mydestination.privatekey" ] = myI2pKeys.
priv;
828 mapArgs[
"-i2p.mydestination.publickey" ] = myI2pKeys.
pub;
829 mapArgs[
"-i2p.mydestination.base32key" ] = myI2pBase32Key;
830 fValidI2pSession =
true;
832 LogPrintf(
"Error - Unable to generate a valid I2P destination. Result: ShutDown.\n" );
834 if( fValidI2pSession ) {
835 LogPrintf(
"Using I2P SAM module version %s\n", FormatI2PNativeFullVersion());
840 mapArgs[
"-i2p.options.enabled" ] =
"0";
842 return InitError(
"Unable to create I2P SAM session" );
847 if( fValidI2pSession ) {
850 bool bErr =
uiInterface.ThreadSafeShowGeneratedI2PAddress(
_(
"Generated an I2P destination for you."),
851 myI2pKeys.
pub, myI2pKeys.
priv, myI2pBase32Key,
853 return InitError( bErr ?
_(
"Error - Unable to report I2P Destination.") :
_(
"Results also written to your debug.log file"));
863 return InitError(
_(
"Error - Unable to Generate I2P Destination.") );
865 #endif // ENABLE_I2PSAM
876 BOOST_FOREACH(std::string strBind,
mapMultiArgs[
"-bind"]) {
879 return InitError(
strprintf(
_(
"Cannot resolve -bind address: '%s'"), strBind));
884 struct in_addr inaddr_any;
885 inaddr_any.s_addr = INADDR_ANY;
893 fBound |= BindListenNativeI2P();
896 return InitError(
_(
"Failed to listen on any port. Use -listen=0 if you want this."));
899 if (
mapArgs.count(
"-externalip")) {
900 BOOST_FOREACH(
string strAddr,
mapMultiArgs[
"-externalip"]) {
903 return InitError(
strprintf(
_(
"Cannot resolve -externalip address: '%s'"), strAddr));
908 BOOST_FOREACH(
string strDest,
mapMultiArgs[
"-seednode"])
916 filesystem::path blocksDir =
GetDataDir() /
"blocks";
917 if (!filesystem::exists(blocksDir))
919 filesystem::create_directories(blocksDir);
921 for (
unsigned int i = 1; i < 10000; i++) {
923 if (!filesystem::exists(source))
break;
924 filesystem::path dest = blocksDir /
strprintf(
"blk%05u.dat", i-1);
926 filesystem::create_hard_link(source, dest);
927 LogPrintf(
"Hardlinked %s -> %s\n", source.string(), dest.string());
929 }
catch (filesystem::filesystem_error & e) {
932 LogPrintf(
"Error hardlinking blk%04u.dat : %s\n", i, e.what());
943 size_t nTotalCache = (
GetArg(
"-dbcache", nDefaultDbCache) << 20);
944 if (nTotalCache < (nMinDbCache << 20))
945 nTotalCache = (nMinDbCache << 20);
946 else if (nTotalCache > (nMaxDbCache << 20))
947 nTotalCache = (nMaxDbCache << 20);
948 size_t nBlockTreeDBCache = nTotalCache / 8;
949 if (nBlockTreeDBCache > (1 << 21) && !
GetBoolArg(
"-txindex",
false))
950 nBlockTreeDBCache = (1 << 21);
951 nTotalCache -= nBlockTreeDBCache;
952 size_t nCoinDBCache = nTotalCache / 2;
953 nTotalCache -= nCoinDBCache;
956 bool fLoaded =
false;
959 std::string strLoadError;
979 strLoadError =
_(
"Error loading block database");
986 return InitError(
_(
"Incorrect or no genesis block found. Wrong datadir for network?"));
990 strLoadError =
_(
"Error initializing block database");
996 strLoadError =
_(
"You need to rebuild the database using -reindex to change -txindex");
1002 GetArg(
"-checkblocks", 288))) {
1003 strLoadError =
_(
"Corrupted block database detected");
1006 }
catch(std::exception &e) {
1008 strLoadError =
_(
"Error opening block database");
1019 strLoadError +
".\n\n" +
_(
"Do you want to rebuild the block database now?"),
1023 fRequestShutdown =
false;
1025 LogPrintf(
"Aborted block database rebuild. Exiting.\n");
1029 return InitError(strLoadError);
1037 if (fRequestShutdown)
1039 LogPrintf(
"Shutdown requested. Exiting.\n");
1050 if (
mapArgs.count(
"-printblock"))
1052 string strMatch =
mapArgs[
"-printblock"];
1057 if (strncmp(hash.
ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
1069 LogPrintf(
"No blocks matching %s were found\n", strMatch);
1074 #ifdef ENABLE_WALLET
1075 if (fDisableWallet) {
1096 bool fFirstRun =
true;
1102 strErrors <<
_(
"Error loading wallet.dat: Wallet corrupted") <<
"\n";
1105 string msg(
_(
"Warning: error reading wallet.dat! All keys read correctly, but transaction data"
1106 " or address book entries might be missing or incorrect."));
1110 strErrors <<
_(
"Error loading wallet.dat: Wallet requires newer version of Anoncoin") <<
"\n";
1113 strErrors <<
_(
"Wallet needed to be rewritten: restart Anoncoin to complete") <<
"\n";
1115 return InitError(strErrors.str());
1118 strErrors <<
_(
"Error loading wallet.dat") <<
"\n";
1123 int nMaxVersion =
GetArg(
"-upgradewallet", 0);
1124 if (nMaxVersion == 0)
1127 nMaxVersion = CLIENT_VERSION;
1131 LogPrintf(
"Allowing wallet upgrade up to %i\n", nMaxVersion);
1132 if (nMaxVersion < pwalletMain->GetVersion())
1133 strErrors <<
_(
"Cannot downgrade wallet") <<
"\n";
1146 strErrors <<
_(
"Cannot write default address") <<
"\n";
1180 #else // ENABLE_WALLET
1182 #endif // !ENABLE_WALLET
1188 strErrors <<
"Failed to connect best block";
1190 std::vector<boost::filesystem::path> vImportFiles;
1191 if (
mapArgs.count(
"-loadblock"))
1193 BOOST_FOREACH(
string strFile,
mapMultiArgs[
"-loadblock"])
1194 vImportFiles.push_back(strFile);
1196 threadGroup.create_thread(boost::bind(&
ThreadImport, vImportFiles));
1204 if (!strErrors.str().empty())
1205 return InitError(strErrors.str());
1212 #ifdef ENABLE_WALLET
1214 LogPrintf(
"mapWallet.size() = %u\n", pwalletMain ? pwalletMain->
mapWallet.size() : 0);
1224 #ifdef ENABLE_WALLET
1234 #ifdef ENABLE_WALLET
const boost::filesystem::path & GetDataDir(bool fNetSpecific)
unsigned int nWalletDBUpdated
CClientUIInterface uiInterface
void SetReachable(enum Network net, bool fFlag)
CNodeSignals & GetNodeSignals()
std::set< int64_t > setKeyPool
void AddOneShot(string strDest)
bool SetAddressBook(const CTxDestination &address, const std::string &strName, const std::string &purpose)
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly)
Open a block file (blk?????.dat)
bool AddLocal(const CService &addr, int nScore)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
#define TRY_LOCK(cs, name)
const SAM::FullDestination & getMyDestination() const
std::map< CTxDestination, CAddressBookData > mapAddressBook
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
bool bSpendZeroConfChange
static SAM::StreamSessionAdapter & Instance()
boost::filesystem::path GetPidFile()
void ThreadScriptCheck()
Run an instance of the script checking thread.
void setSanityCheck(bool _fSanityCheck)
std::string strWalletFile
void SetLimited(enum Network net, bool fLimited)
Make a particular network entirely off-limits (no automatic connects to it)
bool VerifyDB(int nCheckLevel, int nCheckDepth)
Verify consistency of the block and coin databases.
void Flush(bool fShutdown)
bool fDiscover
Specific functions we need to implement I2P functionality.
unsigned short GetListenPort()
Don't bring GUI to foreground.
bool RenameOver(boost::filesystem::path src, boost::filesystem::path dest)
bool SetMaxVersion(int nVersion)
std::string HelpMessage(HelpMessageMode hmm)
DBErrors
Error statuses for the wallet database.
std::string DateTimeStrFormat(const char *pszFormat, int64_t nTime)
void RandAddSeedPerfmon()
static int64_t nMinTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) ...
string FormatMoney(int64_t n, bool fPlus)
void ReacceptWalletTransactions()
void RenameThread(const char *name)
bool isValidI2pDestination(const SAM::FullDestination &DestKeys)
CChain chainActive
The currently-connected chain of blocks.
bool SetDefaultKey(const CPubKey &vchPubKey)
volatile bool fReopenDebugLog
void InitializeI2pSettings(void)
void PrintBlockTree()
Print the loaded block tree.
void SetBestChain(const CBlockLocator &loc)
int RaiseFileDescriptorLimit(int nMinFD)
uint256 BuildMerkleTree() const
CBlockLocator GetLocator(const CBlockIndex *pindex=NULL) const
Return a CBlockLocator that refers to a block in this chain (by default the tip). ...
bool SetMinVersion(enum WalletFeature, CWalletDB *pwalletdbIn=NULL, bool fExplicit=false)
bool SetNameProxy(CService addrProxy)
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or NULL if none.
int Height() const
Return the maximal height in the chain.
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
enum Network ParseNetwork(std::string net)
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Access to the block database (blocks/index/)
volatile bool fRequestShutdown
void UnloadBlockIndex()
Unload database information.
void RegisterNodeSignals(CNodeSignals &nodeSignals)
Register with a network node to receive its signals.
A combination of a network address (CNetAddr) and a (TCP) port.
An encapsulated public key.
bool ActivateBestChain(CValidationState &state)
Find the best known block, and make it the tip of the block chain.
bool AppInit2(boost::thread_group &threadGroup)
Initialize anoncoin.
bool LoadBlockIndex()
Load the block tree and coins database from disk.
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
void AddTransactionsUpdated(unsigned int n)
void RegisterWallet(CWalletInterface *pwalletIn)
Register a wallet to receive updates from core.
std::string FormatFullVersion()
Access to the wallet database (wallet.dat)
void ThreadImport(std::vector< boost::filesystem::path > vImportFiles)
const std::string CLIENT_DATE
std::string strWalletFile
bool ReadBestBlock(CBlockLocator &locator)
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or NULL if none.
Capture information about block/transaction validation.
bool BindListenPort(const CService &addrBind, string &strError)
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
int ScanForWalletTransactions(CBlockIndex *pindexStart, bool fUpdate=false)
The block chain is a tree shaped structure starting with the genesis block at the root...
unsigned int nCoinCacheSize
std::string ToString() const
CCoinsView backed by the LevelDB coin database (chainstate/)
CBlockIndex * FindFork(const CBlockLocator &locator) const
Find the last common block between this chain and a locator.
static bool Recover(CDBEnv &dbenv, std::string filename, bool fOnlyKeys)
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
bool Lookup(const char *pszName, std::vector< CService > &vAddr, int portDefault, bool fAllowLookup, unsigned int nMaxSolutions)
bool ParseMoney(const string &str, int64_t &nRet)
static std::string GenerateB32AddressFromDestination(const std::string &destination)
void UnregisterAllWallets()
Unregister all wallets from core.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
void GenerateAnoncoins(bool fGenerate, CWallet *pwallet, int nThreads)
Run the miner threads.
VerifyResult Verify(std::string strFile, bool(*recoverFunc)(CDBEnv &dbenv, std::string strFile))
bool InitSanityCheck(void)
Sanity checks Ensure that Anoncoin is running in a usable environment with all necessary library supp...
bool WriteReindexing(bool fReindex)
std::map< uint256, CWalletTx > mapWallet
boost::signals2::signal< bool(const std::string &message, const std::string &caption, unsigned int style), boost::signals2::last_value< bool > > ThreadSafeMessageBox
Show message box.
static int64_t nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying and mining) ...
DBErrors LoadWallet(bool &fFirstRunRet)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
bool GetKeyFromPool(CPubKey &key)
bool LoadExternalBlockFile(FILE *fileIn, CDiskBlockPos *dbp)
Import blocks from an external file.
bool ECC_InitSanityCheck()
Check that required EC support is available at runtime.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
bool CheckDiskSpace(uint64_t nAdditionalBytes)
Check whether enough disk space is available for an incoming block.
#define MIN_CORE_FILEDESCRIPTORS
bool InitBlockIndex()
Initialize a new block tree database + block data on disk.
map< string, vector< string > > mapMultiArgs
bool Open(const boost::filesystem::path &path)
map< uint256, CBlockIndex * > mapBlockIndex
bool SetProxy(enum Network net, CService addrProxy)
void ThreadFlushWalletDB(const std::string &strWalletFile)
bool IsLimited(enum Network net)
boost::signals2::signal< void(const std::string &message)> InitMessage
Progress message during initialization.
void StartNode(boost::thread_group &threadGroup)
map< string, string > mapArgs
boost::filesystem::path GetDefaultDataDir()
void UnregisterNodeSignals(CNodeSignals &nodeSignals)
Unregister a network node.
boost::filesystem::path GetConfigFile()