Add ripple_main module

This commit is contained in:
Vinnie Falco
2013-05-22 16:17:13 -07:00
parent cee678f849
commit a5360379ac
12 changed files with 262 additions and 130 deletions

View File

@@ -24,8 +24,6 @@
#include <boost/filesystem.hpp>
#include <boost/thread.hpp>
SETUP_LOG();
LogPartition TaggedCachePartition("TaggedCache");
LogPartition AutoSocketPartition("AutoSocket");
Application* theApp = NULL;
@@ -80,7 +78,7 @@ bool Instance::running = true;
void Application::stop()
{
cLog(lsINFO) << "Received shutdown request";
WriteLog (lsINFO, Application) << "Received shutdown request";
StopSustain();
mShutdown = true;
mIOService.stop();
@@ -94,7 +92,7 @@ void Application::stop()
mHashNodeLDB = NULL;
#endif
cLog(lsINFO) << "Stopped: " << mIOService.stopped();
WriteLog (lsINFO, Application) << "Stopped: " << mIOService.stopped();
Instance::shutdown();
}
@@ -172,7 +170,7 @@ void Application::setup()
#ifdef USE_LEVELDB
if (mHashedObjectStore.isLevelDB())
{
cLog(lsINFO) << "LevelDB used for nodes";
WriteLog (lsINFO, Application) << "LevelDB used for nodes";
leveldb::Options options;
options.create_if_missing = true;
options.block_cache = leveldb::NewLRUCache(theConfig.getSize(siHashNodeDBCache) * 1024 * 1024);
@@ -183,7 +181,7 @@ void Application::setup()
leveldb::Status status = leveldb::DB::Open(options, (theConfig.DATA_DIR / "hashnode").string(), &mHashNodeLDB);
if (!status.ok() || !mHashNodeLDB)
{
cLog(lsFATAL) << "Unable to open/create hash node db: "
WriteLog (lsFATAL, Application) << "Unable to open/create hash node db: "
<< (theConfig.DATA_DIR / "hashnode").string()
<< " " << status.ToString();
StopSustain();
@@ -193,7 +191,7 @@ void Application::setup()
else
#endif
{
cLog(lsINFO) << "SQLite used for nodes";
WriteLog (lsINFO, Application) << "SQLite used for nodes";
boost::thread t5(boost::bind(&InitDB, &mHashNodeDB, "hashnode.db", HashNodeDBInit, HashNodeDBCount));
t5.join();
}
@@ -206,13 +204,13 @@ void Application::setup()
if (theConfig.START_UP == Config::FRESH)
{
cLog(lsINFO) << "Starting new Ledger";
WriteLog (lsINFO, Application) << "Starting new Ledger";
startNewLedger();
}
else if (theConfig.START_UP == Config::LOAD)
{
cLog(lsINFO) << "Loading specified Ledger";
WriteLog (lsINFO, Application) << "Loading specified Ledger";
if (!loadOldLedger(theConfig.START_LEDGER))
{
@@ -271,14 +269,14 @@ void Application::setup()
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open peer service: %s") % e.what());
WriteLog (lsFATAL, Application) << boost::str(boost::format("Can not open peer service: %s") % e.what());
exit(3);
}
}
else
{
cLog(lsINFO) << "Peer interface: disabled";
WriteLog (lsINFO, Application) << "Peer interface: disabled";
}
//
@@ -293,14 +291,14 @@ void Application::setup()
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open RPC service: %s") % e.what());
WriteLog (lsFATAL, Application) << boost::str(boost::format("Can not open RPC service: %s") % e.what());
exit(3);
}
}
else
{
cLog(lsINFO) << "RPC interface: disabled";
WriteLog (lsINFO, Application) << "RPC interface: disabled";
}
//
@@ -315,14 +313,14 @@ void Application::setup()
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open private websocket service: %s") % e.what());
WriteLog (lsFATAL, Application) << boost::str(boost::format("Can not open private websocket service: %s") % e.what());
exit(3);
}
}
else
{
cLog(lsINFO) << "WS private interface: disabled";
WriteLog (lsINFO, Application) << "WS private interface: disabled";
}
//
@@ -337,14 +335,14 @@ void Application::setup()
catch (const std::exception& e)
{
// Must run as directed or exit.
cLog(lsFATAL) << boost::str(boost::format("Can not open public websocket service: %s") % e.what());
WriteLog (lsFATAL, Application) << boost::str(boost::format("Can not open public websocket service: %s") % e.what());
exit(3);
}
}
else
{
cLog(lsINFO) << "WS public interface: disabled";
WriteLog (lsINFO, Application) << "WS public interface: disabled";
}
//
@@ -356,7 +354,7 @@ void Application::setup()
if (theConfig.RUN_STANDALONE)
{
cLog(lsWARNING) << "Running in standalone mode";
WriteLog (lsWARNING, Application) << "Running in standalone mode";
mNetOps.setStandAlone();
}
@@ -380,7 +378,7 @@ void Application::run()
if (mWSPrivateDoor)
mWSPrivateDoor->stop();
cLog(lsINFO) << "Done.";
WriteLog (lsINFO, Application) << "Done.";
}
void Application::sweep()
@@ -389,7 +387,7 @@ void Application::sweep()
boost::filesystem::space_info space = boost::filesystem::space(theConfig.DATA_DIR);
if (space.available < (512 * 1024 * 1024))
{
cLog(lsFATAL) << "Remaining free disk space is less than 512MB";
WriteLog (lsFATAL, Application) << "Remaining free disk space is less than 512MB";
theApp->stop();
}
@@ -428,8 +426,8 @@ void Application::startNewLedger()
RippleAddress rootAddress = RippleAddress::createAccountPublic(rootGeneratorMaster, 0);
// Print enough information to be able to claim root account.
cLog(lsINFO) << "Root master seed: " << rootSeedMaster.humanSeed();
cLog(lsINFO) << "Root account: " << rootAddress.humanAccountID();
WriteLog (lsINFO, Application) << "Root master seed: " << rootSeedMaster.humanSeed();
WriteLog (lsINFO, Application) << "Root account: " << rootAddress.humanAccountID();
{
Ledger::pointer firstLedger = boost::make_shared<Ledger>(rootAddress, SYSTEM_CURRENCY_START);
@@ -466,29 +464,29 @@ bool Application::loadOldLedger(const std::string& l)
if (!loadLedger)
{
cLog(lsFATAL) << "No Ledger found?" << std::endl;
WriteLog (lsFATAL, Application) << "No Ledger found?" << std::endl;
return false;
}
loadLedger->setClosed();
cLog(lsINFO) << "Loading ledger " << loadLedger->getHash() << " seq:" << loadLedger->getLedgerSeq();
WriteLog (lsINFO, Application) << "Loading ledger " << loadLedger->getHash() << " seq:" << loadLedger->getLedgerSeq();
if (loadLedger->getAccountHash().isZero())
{
cLog(lsFATAL) << "Ledger is empty.";
WriteLog (lsFATAL, Application) << "Ledger is empty.";
assert(false);
return false;
}
if (!loadLedger->walkLedger())
{
cLog(lsFATAL) << "Ledger is missing nodes.";
WriteLog (lsFATAL, Application) << "Ledger is missing nodes.";
return false;
}
if (!loadLedger->assertSane())
{
cLog(lsFATAL) << "Ledger is not sane.";
WriteLog (lsFATAL, Application) << "Ledger is not sane.";
return false;
}
mLedgerMaster.setLedgerRangePresent(loadLedger->getLedgerSeq(), loadLedger->getLedgerSeq());
@@ -499,12 +497,12 @@ bool Application::loadOldLedger(const std::string& l)
}
catch (SHAMapMissingNode&)
{
cLog(lsFATAL) << "Data is missing for selected ledger";
WriteLog (lsFATAL, Application) << "Data is missing for selected ledger";
return false;
}
catch (boost::bad_lexical_cast&)
{
cLog(lsFATAL) << "Ledger specified '" << l << "' is not valid";
WriteLog (lsFATAL, Application) << "Ledger specified '" << l << "' is not valid";
return false;
}
return true;