From 2bdd06f5cc5a0cca58f8a79fec0a9b94fd5a1dcb Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 3 May 2012 15:45:04 -0700 Subject: [PATCH] Pass io_service to NetworkOPs to it can set timers. --- src/Application.cpp | 6 ++---- src/Application.h | 5 ++--- src/NetworkOPs.h | 25 ++++++++++++++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 01daae4b1b..be9af22fa7 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -41,11 +41,9 @@ DatabaseCon::~DatabaseCon() delete mDatabase; } -Application::Application() : - mUNL(mIOService), +Application::Application() : mNetOps(mIOService), mUNL(mIOService), mTxnDB(NULL), mLedgerDB(NULL), mWalletDB(NULL), mHashNodeDB(NULL), mNetNodeDB(NULL), - mConnectionPool(mIOService), - mPeerDoor(NULL), mRPCDoor(NULL) + mConnectionPool(mIOService), mPeerDoor(NULL), mRPCDoor(NULL) { nothing(); } diff --git a/src/Application.h b/src/Application.h index b1023b1eac..293bf4a5a1 100644 --- a/src/Application.h +++ b/src/Application.h @@ -34,11 +34,10 @@ public: class Application { - NetworkOPs mNetOps; - Wallet mWallet; - boost::asio::io_service mIOService; + NetworkOPs mNetOps; + Wallet mWallet; TimingService mTimingService; UniqueNodeList mUNL; PubKeyCache mPKCache; diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index bf9eb9c8a1..525f5b9f16 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -11,27 +11,35 @@ class Peer; class NetworkOPs { +public: enum Fault { // exceptions these functions can throw - IO_ERROR=1, - NO_NETWORK=2, + IO_ERROR = 1, + NO_NETWORK = 2, }; enum OperatingMode { // how we process transactions or account balance requests - DISCONNECTED=0, // not ready to process requests - CONNECTED=1, // convinced we are talking to the network - TRACKING=2, // convinced we agree with the network - FULL=3 // we have the ledger and can even validate + omDISCONNECTED = 0, // not ready to process requests + omCONNECTED = 1, // convinced we are talking to the network + omTRACKING = 2, // convinced we agree with the network + omFULL = 3 // we have the ledger and can even validate }; +protected: + OperatingMode mMode; + boost::asio::deadline_timer mNetTimer; + public: + NetworkOPs(boost::asio::io_service& io_service) : mMode(omDISCONNECTED), mNetTimer(io_service) { ; } + // network information uint64 getNetworkTime(); uint32 getCurrentLedgerID(); + OperatingMode getOperatingMode() { return mMode; } // transaction operations - Transaction::pointer processTransaction(Transaction::pointer transaction, Peer* source=NULL); + Transaction::pointer processTransaction(Transaction::pointer transaction, Peer* source = NULL); Transaction::pointer findTransactionByID(const uint256& transactionID); int findTransactionsBySource(std::list&, const NewcoinAddress& sourceAccount, uint32 minSeq, uint32 maxSeq); @@ -52,6 +60,9 @@ public: const std::vector& myNode, std::list >& newNodes); bool getAccountStateNodes(uint32 ledgerSeq, const uint256& myNodeId, const std::vector& myNode, std::list >& newNodes); + + // network state machine + void checkState(); }; #endif