#include "ipcollector.h"
#include "ui_interface.h"
#include "checkpoints.h"
-#include <boost/format.hpp>
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/convenience.hpp>
fTaken = true;
}
}
- static bool fExit;
+ volatile static bool fExit;
if (fFirstThread)
{
fShutdown = true;
" -dbcache=<n> " + _("Set database cache size in megabytes (default: 25)") + "\n" +
" -dblogsize=<n> " + _("Set database disk log size in megabytes (default: 100)") + "\n" +
" -timeout=<n> " + _("Specify connection timeout in milliseconds (default: 5000)") + "\n" +
- " -proxy=<ip:port> " + _("Connect through socks proxy") + "\n" +
- " -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
+ " -proxy=<ip:port> " + _("Connect through socks5 proxy") + "\n" +
" -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
" -torname=<host.onion> " + _("Send the specified hidden service name when connecting to Tor nodes (default: none)") + "\n"
" -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
#endif
" -paytxfee=<amt> " + _("Fee per KB to add to transactions you send") + "\n" +
- " -mininput=<amt> " + str(boost::format(_("When creating transactions, ignore inputs with value less than this (default: %s)")) % FormatMoney(MIN_TXOUT_AMOUNT)) + "\n" +
+ " -mininput=<amt> " + ((string)("When creating transactions, ignore inputs with value less than this (default: ") + FormatMoney(MIN_TXOUT_AMOUNT) + ")") + "\n" +
#ifdef QT_GUI
" -server " + _("Accept command line and JSON-RPC commands") + "\n" +
#endif
" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +
" -zapwallettxes " + _("Clear list of wallet transactions (diagnostic tool; implies -rescan)") + "\n" +
" -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n" +
- " -checkblocks=<n> " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" +
+ " -checkblocks=<n> " + _("How many blocks to check at startup (default: 192, 0 = all)") + "\n" +
" -checklevel=<n> " + _("How thorough the block verification is (0-6, default: 1)") + "\n" +
" -par=N " + _("Set the number of script verification threads (1-16, 0=auto, default: 0)") + "\n" +
" -loadblock=<file> " + _("Imports blocks from external blk000?.dat file") + "\n" +
return strUsage;
}
-/** Initialize bitcoin.
- * @pre Parameters should be parsed and config file should be read.
- */
+bool DropBlockIndex()
+{
+ try
+ {
+#ifdef USE_LEVELDB
+ filesystem::path directory = GetDataDir() / "txleveldb";
+ filesystem::remove_all(directory); // remove directory
+#else
+ filesystem::path indexFile = GetDataDir() / "blkindex.dat";
+ filesystem::remove(indexFile); // remove index file
+#endif
+
+ unsigned int nFile = 1;
+ for ( ; ; )
+ {
+ filesystem::path strBlockFile = GetDataDir() / strprintf("blk%04u.dat", nFile);
+ // Break if no such file
+ if( !filesystem::exists( strBlockFile ) )
+ break;
+ filesystem::remove(strBlockFile);
+ nFile++;
+ }
+ return true;
+ }
+ catch(const std::exception&)
+ {
+ // TODO: report error here
+ return false;
+ }
+}
+
+// Initialize bitcoin.
+// @pre Parameters should be parsed and config file should be read.
bool AppInit2()
{
// ********************************************************* Step 1: setup
// Ping and address broadcast intervals
nPingInterval = max<int64_t>(10 * 60, GetArg("-keepalive", 30 * 60));
- CheckpointsMode = Checkpoints::STRICT;
- std::string strCpMode = GetArg("-cppolicy", "strict");
+ CheckpointsMode = Checkpoints::CP_STRICT;
+ auto strCpMode = GetArg("-cppolicy", "strict");
if(strCpMode == "strict") {
- CheckpointsMode = Checkpoints::STRICT;
+ CheckpointsMode = Checkpoints::CP_STRICT;
}
if(strCpMode == "advisory") {
- CheckpointsMode = Checkpoints::ADVISORY;
+ CheckpointsMode = Checkpoints::CP_ADVISORY;
}
if(strCpMode == "permissive") {
- CheckpointsMode = Checkpoints::PERMISSIVE;
+ CheckpointsMode = Checkpoints::CP_PERMISSIVE;
}
fTestNet = GetBoolArg("-testnet");
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
- std::string strDataDir = GetDataDir().string();
+ auto strDataDir = GetDataDir().string();
strWalletFileName = GetArg("-wallet", "wallet.dat");
// strWalletFileName must be a plain filename without a directory
printf("Startup time: %s\n", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
printf("Used data directory %s\n", strDataDir.c_str());
- std::ostringstream strErrors;
if (fDaemon)
fprintf(stdout, "NovaCoin server starting\n");
NewThread(ThreadScriptCheck, NULL);
}
- int64_t nStart;
-
// ********************************************************* Step 5: verify database integrity
uiInterface.InitMessage(_("Verifying database integrity..."));
// ********************************************************* Step 6: network initialization
- int nSocksVersion = GetArgInt("-socks", 5);
-
- if (nSocksVersion != 4 && nSocksVersion != 5)
- return InitError(strprintf(_("Unknown -socks proxy version requested: %i"), nSocksVersion));
-
if (mapArgs.count("-onlynet")) {
std::set<enum Network> nets;
for(std::string snet : mapMultiArgs["-onlynet"]) {
SetLimited(net);
}
}
-#if defined(USE_IPV6)
-#if ! USE_IPV6
- else
- SetLimited(NET_IPV6);
-#endif
-#endif
CService addrProxy;
bool fProxy = false;
return InitError(strprintf(_("Invalid -proxy address: '%s'"), mapArgs["-proxy"].c_str()));
if (!IsLimited(NET_IPV4))
- SetProxy(NET_IPV4, addrProxy, nSocksVersion);
- if (nSocksVersion > 4) {
-#ifdef USE_IPV6
+ SetProxy(NET_IPV4, addrProxy);
if (!IsLimited(NET_IPV6))
- SetProxy(NET_IPV6, addrProxy, nSocksVersion);
-#endif
- SetNameProxy(addrProxy, nSocksVersion);
- }
+ SetProxy(NET_IPV6, addrProxy);
+ SetNameProxy(addrProxy);
fProxy = true;
}
addrOnion = CService(mapArgs["-tor"], nSocksDefault);
if (!addrOnion.IsValid())
return InitError(strprintf(_("Invalid -tor address: '%s'"), mapArgs["-tor"].c_str()));
- SetProxy(NET_TOR, addrOnion, 5);
+ SetProxy(NET_TOR, addrOnion);
SetReachable(NET_TOR);
}
// see Step 2: parameter interactions for more information about these
if (!IsLimited(NET_IPV4) || !IsLimited(NET_IPV6))
{
- fNoListen = !GetBoolArg("-listen", true);
+ fListen = GetBoolArg("-listen", true);
fDiscover = GetBoolArg("-discover", true);
fNameLookup = GetBoolArg("-dns", true);
} else {
// Don't listen, discover addresses or search for nodes if IPv4 and IPv6 networking is disabled.
- fNoListen = true;
+ fListen = false;
fDiscover = fNameLookup = false;
SoftSetBoolArg("-irc", false);
SoftSetBoolArg("-dnsseed", false);
}
bool fBound = false;
- if (!fNoListen)
+ if (fListen)
{
- std::string strError;
if (mapArgs.count("-bind")) {
for(std::string strBind : mapMultiArgs["-bind"]) {
CService addrBind;
} else {
struct in_addr inaddr_any;
inaddr_any.s_addr = INADDR_ANY;
-#ifdef USE_IPV6
if (!IsLimited(NET_IPV6))
fBound |= Bind(CService(in6addr_any, GetListenPort()), false);
-#endif
if (!IsLimited(NET_IPV4))
fBound |= Bind(CService(inaddr_any, GetListenPort()), !fBound);
struct in_addr inaddr_loopback;
inaddr_loopback.s_addr = htonl(INADDR_LOOPBACK);
-#ifdef USE_IPV6
if (!BindListenPort(CService(in6addr_loopback, GetListenPort()), strError))
return InitError(strError);
-#endif
if (!BindListenPort(CService(inaddr_loopback, GetListenPort()), strError))
return InitError(strError);
}
printf("Loading block index...\n");
bool fLoaded = false;
+ int64_t nStart;
while (!fLoaded) {
std::string strLoadError;
uiInterface.InitMessage(_("Loading block index..."));
} while(false);
if (!fLoaded) {
+ DropBlockIndex();
// TODO: suggest reindex here
return InitError(strLoadError);
}
if (mapArgs.count("-printblock"))
{
- string strMatch = mapArgs["-printblock"];
+ auto strMatch = mapArgs["-printblock"];
int nFound = 0;
- for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
+ for (auto mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)
{
- uint256 hash = (*mi).first;
- if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)
+ auto hash = (*mi).first;
+ if (strMatch.compare(hash.ToString()) == 0)
{
- CBlockIndex* pindex = (*mi).second;
+ auto pindex = (*mi).second;
CBlock block;
block.ReadFromDisk(pindex);
block.BuildMerkleTree();
uiInterface.InitMessage(_("Loading wallet..."));
printf("Loading wallet...\n");
nStart = GetTimeMillis();
+ std::ostringstream strErrors;
bool fFirstRun = true;
pwalletMain = new CWallet(strWalletFileName);
DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRun);
if (!pwalletMain->SetAddressBookName(pwalletMain->vchDefaultKey.GetID(), ""))
strErrors << _("Cannot write default address") << "\n";
- CMalleableKeyView keyView = pwalletMain->GenerateNewMalleableKey();
+ auto keyView = pwalletMain->GenerateNewMalleableKey();
CMalleableKey mKey;
if (!pwalletMain->GetMalleableKey(keyView, mKey))
strErrors << _("Unable to generate new malleable key");
{
FILE *file = fopen(strFile.c_str(), "rb");
if (file)
- LoadExternalBlockFile(file);
+ LoadExternalBlockFile(file, uiInterface);
}
StartShutdown();
}
FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
if (file) {
filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
- LoadExternalBlockFile(file);
+ LoadExternalBlockFile(file, uiInterface);
RenameOver(pathBootstrap, pathBootstrapOld);
}
}