diff --git a/src/Application.cpp b/src/Application.cpp index af3b17f9a..2fe18c161 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -95,13 +95,14 @@ void Application::run() // // Set up UNL. // - getUNL().nodeBootstrap(); + if (!theConfig.RUN_STANDALONE) + getUNL().nodeBootstrap(); // // Allow peer connections. // - if (!theConfig.PEER_IP.empty() && theConfig.PEER_PORT) + if (!theConfig.RUN_STANDALONE && !theConfig.PEER_IP.empty() && theConfig.PEER_PORT) { mPeerDoor = new PeerDoor(mIOService); } @@ -127,7 +128,8 @@ void Application::run() // // Begin connecting to network. // - mConnectionPool.start(); + if (!theConfig.RUN_STANDALONE) + mConnectionPool.start(); // New stuff. NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase"); @@ -155,7 +157,14 @@ void Application::run() } - mNetOps.setStateTimer(); + if (theConfig.RUN_STANDALONE) + { + Log(lsWARNING) << "Running in standalone mode"; + mNetOps.setStandAlone(); + mMasterLedger.runStandAlone(); + } + else + mNetOps.setStateTimer(); mIOService.run(); // This blocks diff --git a/src/Config.cpp b/src/Config.cpp index cf9c135bf..ef79cae52 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -40,6 +40,11 @@ Config theConfig; +void Config::init() +{ + RUN_STANDALONE = false; +} + void Config::setup(const std::string& strConf) { boost::system::error_code ec; diff --git a/src/Config.h b/src/Config.h index 585980b92..a7828da7b 100644 --- a/src/Config.h +++ b/src/Config.h @@ -63,6 +63,7 @@ public: int LEDGER_PROPOSAL_DELAY_SECONDS; int LEDGER_AVALANCHE_SECONDS; bool LEDGER_CREATOR; // should be false unless we are starting a new ledger + bool RUN_STANDALONE; // Note: The following parameters do not relate to the UNL or trust at all unsigned int NETWORK_QUORUM; // Minimum number of nodes to consider the network present @@ -100,6 +101,7 @@ public: // Client behavior int ACCOUNT_PROBE_MAX; // How far to scan for accounts. + void init(); void setup(const std::string& strConf); void load(); }; diff --git a/src/ConnectionPool.cpp b/src/ConnectionPool.cpp index 2a7f38bb7..3d79fbc2a 100644 --- a/src/ConnectionPool.cpp +++ b/src/ConnectionPool.cpp @@ -42,6 +42,9 @@ ConnectionPool::ConnectionPool(boost::asio::io_service& io_service) : void ConnectionPool::start() { + if (theConfig.RUN_STANDALONE) + return; + // Start running policy. policyEnforce(); @@ -243,6 +246,8 @@ void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg) // Requires sane IP and port. void ConnectionPool::connectTo(const std::string& strIp, int iPort) { + if (theConfig.RUN_STANDALONE) + return; { Database* db = theApp->getWalletDB()->getDB(); ScopedLock sl(theApp->getWalletDB()->getDBLock()); diff --git a/src/LedgerMaster.h b/src/LedgerMaster.h index 9f9603f1b..187aaeec1 100644 --- a/src/LedgerMaster.h +++ b/src/LedgerMaster.h @@ -43,6 +43,8 @@ public: // The finalized ledger is the last closed/accepted ledger Ledger::pointer getClosedLedger() { return mFinalizedLedger; } + void runStandAlone() { mFinalizedLedger = mCurrentLedger; } + TransactionEngineResult doTransaction(const SerializedTransaction& txn, uint32 targetLedger, TransactionEngineParams params); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index afbf87e32..d7180a6ae 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -333,7 +333,7 @@ public: void NetworkOPs::checkState(const boost::system::error_code& result) { // Network state machine - if (result == boost::asio::error::operation_aborted) + if ((result == boost::asio::error::operation_aborted) || theConfig.RUN_STANDALONE) return; setStateTimer(); @@ -680,7 +680,7 @@ void NetworkOPs::setMode(OperatingMode om) mConnectTime = boost::posix_time::second_clock::universal_time(); Log l((om < mMode) ? lsWARNING : lsINFO); if (om == omDISCONNECTED) - l << "STATE->Disonnected"; + l << "STATE->Disconnected"; else if (om == omCONNECTED) l << "STATE->Connected"; else if (om == omTRACKING) diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 46ea9eda7..9bf863a35 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -832,6 +832,9 @@ Json::Value RPCServer::doAccountWalletSet(const Json::Value& params) { Json::Value RPCServer::doConnect(const Json::Value& params) { + if (theConfig.RUN_STANDALONE) + return "cannot connect in standalone mode"; + // connect [port] std::string strIp; int iPort = -1; diff --git a/src/main.cpp b/src/main.cpp index 155408170..c78da1e24 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,6 +84,7 @@ int main(int argc, char* argv[]) int iResult = 0; po::variables_map vm; // Map of options. bool bTest = false; + theConfig.init(); // // Set up option parsing. @@ -93,6 +94,7 @@ int main(int argc, char* argv[]) ("help,h", "Display this message.") ("conf", po::value(), "Specify the configuration file.") ("rpc", "Perform rpc command (default).") + ("standalone,a", "Run with no peers.") ("test,t", "Perform unit tests.") ("parameters", po::value< vector >(), "Specify comma separated parameters.") ("verbose,v", "Increase log level") @@ -142,6 +144,11 @@ int main(int argc, char* argv[]) Log::setMinSeverity(lsTRACE); } + if (vm.count("standalone")) + { + theConfig.RUN_STANDALONE = true; + } + if (!iResult) { theConfig.setup(vm.count("conf") ? vm["conf"].as() : "");