Fabcoin Core  0.16.2
P2P Digital Currency
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
dev::eth::EthereumHost Class Reference

The EthereumHost class. More...

#include <EthereumHost.h>

Inheritance diagram for dev::eth::EthereumHost:
[legend]
Collaboration diagram for dev::eth::EthereumHost:
[legend]

Public Member Functions

 EthereumHost (BlockChain const &_ch, OverlayDB const &_db, TransactionQueue &_tq, BlockQueue &_bq, u256 _networkId)
 Start server, but don't listen. More...
 
virtual ~EthereumHost ()
 Will block on network process events. More...
 
unsigned protocolVersion () const
 
u256 networkId () const
 
void setNetworkId (u256 _n)
 
void reset ()
 
void completeSync ()
 Don't sync further - used only in test mode. More...
 
bool isSyncing () const
 
bool isBanned (p2p::NodeID const &_id) const
 
void noteNewTransactions ()
 
void noteNewBlocks ()
 
void onBlockImported (BlockHeader const &_info)
 
BlockChain const & chain () const
 
OverlayDB const & db () const
 
BlockQueuebq ()
 
BlockQueue const & bq () const
 
SyncStatus status () const
 
h256 latestBlockSent ()
 
void foreachPeer (std::function< bool(std::shared_ptr< EthereumPeer >)> const &_f) const
 
- Public Member Functions inherited from dev::p2p::HostCapability< EthereumPeer >
 HostCapability ()
 
virtual ~HostCapability ()
 
- Public Member Functions inherited from dev::p2p::HostCapabilityFace
 HostCapabilityFace ()
 
virtual ~HostCapabilityFace ()
 
Hosthost () const
 
std::vector< std::pair< std::shared_ptr< SessionFace >, std::shared_ptr< Peer > > > peerSessions () const
 
std::vector< std::pair< std::shared_ptr< SessionFace >, std::shared_ptr< Peer > > > peerSessions (u256 const &_version) const
 

Static Public Member Functions

static char const * stateName (SyncState _s)
 
- Static Public Member Functions inherited from dev::p2p::HostCapability< EthereumPeer >
static std::string staticName ()
 
static u256 staticVersion ()
 
static unsigned staticMessageCount ()
 

Static Public Attributes

static unsigned const c_oldProtocolVersion = 62
 

Protected Member Functions

std::shared_ptr< p2p::CapabilitynewPeerCapability (std::shared_ptr< p2p::SessionFace > const &_s, unsigned _idOffset, p2p::CapDesc const &_cap, uint16_t _capID) override
 
- Protected Member Functions inherited from dev::p2p::HostCapability< EthereumPeer >
virtual std::string name () const
 
virtual u256 version () const
 
virtual unsigned messageCount () const
 
virtual std::shared_ptr< CapabilitynewPeerCapability (std::shared_ptr< SessionFace > const &_s, unsigned _idOffset, CapDesc const &_cap, uint16_t _capID)
 
- Protected Member Functions inherited from dev::p2p::HostCapabilityFace
CapDesc capDesc () const
 

Private Member Functions

std::tuple< std::vector< std::shared_ptr< EthereumPeer > >, std::vector< std::shared_ptr< EthereumPeer > >, std::vector< std::shared_ptr< p2p::SessionFace > > > randomSelection (unsigned _percent=25, std::function< bool(EthereumPeer *)> const &_allow=[](EthereumPeer const *){return true;})
 
virtual void doWork () override
 Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network. More...
 
void maintainTransactions ()
 
void maintainBlocks (h256 const &_currentBlock)
 
void onTransactionImported (ImportResult _ir, h256 const &_h, h512 const &_nodeId)
 
bool isInitialised () const
 Check to see if the network peer-state initialisation has happened. More...
 
bool ensureInitialised ()
 Initialises the network peer-state, doing the stuff that needs to be once-only. More...
 
virtual void onStarting () override
 
virtual void onStopping () override
 
- Private Member Functions inherited from dev::Worker
 Worker (std::string const &_name="anon", unsigned _idleWaitMs=30)
 
 Worker (Worker &&_m)
 Move-constructor. More...
 
Workeroperator= (Worker &&_m)
 Move-assignment. More...
 
virtual ~Worker ()
 
void setName (std::string _n)
 Allows changing worker name if work is stopped. More...
 
void startWorking ()
 Starts worker thread; causes startedWorking() to be called. More...
 
void stopWorking ()
 Stop worker thread; causes call to stopWorking(). More...
 
bool isWorking () const
 Returns if worker thread is present. More...
 
virtual void startedWorking ()
 Called after thread is started from startWorking(). More...
 
virtual void workLoop ()
 Overrides doWork(); should call shouldStop() often and exit when true. More...
 
bool shouldStop () const
 
virtual void doneWorking ()
 Called when is to be stopped, just prior to thread being joined. More...
 

Private Attributes

BlockChain const & m_chain
 
OverlayDB const & m_db
 References to DB, needed for some of the Ethereum Protocol responses. More...
 
TransactionQueuem_tq
 Maintains a list of incoming transactions not yet in a block on the blockchain. More...
 
BlockQueuem_bq
 Maintains a list of incoming blocks not yet on the blockchain (to be imported). More...
 
u256 m_networkId
 
h256 m_latestBlockSent
 
h256Hash m_transactionsSent
 
std::unordered_set< p2p::NodeIDm_banned
 
bool m_newTransactions = false
 
bool m_newBlocks = false
 
RecursiveMutex x_sync
 
Mutex x_transactions
 
std::unique_ptr< BlockChainSyncm_sync
 
std::atomic< time_t > m_lastTick = { 0 }
 
std::shared_ptr< EthereumHostDataFacem_hostData
 
std::shared_ptr< EthereumPeerObserverFacem_peerObserver
 

Static Private Attributes

static char const *const s_stateNames [static_cast< int >(SyncState::Size)] = {"NotSynced", "Idle", "Waiting", "Blocks", "State", "NewBlocks" }
 

Detailed Description

The EthereumHost class.

Warning
None of this is thread-safe. You have been warned. Syncs to peers and sends new blocks and transactions.

Definition at line 61 of file EthereumHost.h.

Constructor & Destructor Documentation

EthereumHost::EthereumHost ( BlockChain const &  _ch,
OverlayDB const &  _db,
TransactionQueue _tq,
BlockQueue _bq,
u256  _networkId 
)

Start server, but don't listen.

Definition at line 377 of file EthereumHost.cpp.

Here is the call graph for this function:

EthereumHost::~EthereumHost ( )
virtual

Will block on network process events.

Definition at line 395 of file EthereumHost.cpp.

Member Function Documentation

BlockQueue& dev::eth::EthereumHost::bq ( )
inline

Definition at line 87 of file EthereumHost.h.

Here is the caller graph for this function:

BlockQueue const& dev::eth::EthereumHost::bq ( ) const
inline

Definition at line 88 of file EthereumHost.h.

BlockChain const& dev::eth::EthereumHost::chain ( ) const
inline

Definition at line 85 of file EthereumHost.h.

Here is the caller graph for this function:

void EthereumHost::completeSync ( )

Don't sync further - used only in test mode.

Definition at line 424 of file EthereumHost.cpp.

OverlayDB const& dev::eth::EthereumHost::db ( ) const
inline

Definition at line 86 of file EthereumHost.h.

void EthereumHost::doWork ( )
overrideprivatevirtual

Sync with the BlockChain. It might contain one of our mined blocks, we might have new candidates from the network.

Reimplemented from dev::Worker.

Definition at line 430 of file EthereumHost.cpp.

Here is the call graph for this function:

bool EthereumHost::ensureInitialised ( )
private

Initialises the network peer-state, doing the stuff that needs to be once-only.

Returns
true if it really was first.

Definition at line 399 of file EthereumHost.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumHost::foreachPeer ( std::function< bool(std::shared_ptr< EthereumPeer >)> const &  _f) const

Definition at line 504 of file EthereumHost.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool dev::eth::EthereumHost::isBanned ( p2p::NodeID const &  _id) const
inline

Definition at line 79 of file EthereumHost.h.

bool dev::eth::EthereumHost::isInitialised ( ) const
inlineprivate

Check to see if the network peer-state initialisation has happened.

Definition at line 112 of file EthereumHost.h.

bool EthereumHost::isSyncing ( ) const

Definition at line 601 of file EthereumHost.cpp.

Here is the caller graph for this function:

h256 dev::eth::EthereumHost::latestBlockSent ( )
inline

Definition at line 90 of file EthereumHost.h.

void EthereumHost::maintainBlocks ( h256 const &  _currentBlock)
private

Definition at line 552 of file EthereumHost.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumHost::maintainTransactions ( )
private

Definition at line 461 of file EthereumHost.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

u256 dev::eth::EthereumHost::networkId ( ) const
inline

Definition at line 71 of file EthereumHost.h.

shared_ptr< Capability > EthereumHost::newPeerCapability ( std::shared_ptr< p2p::SessionFace > const &  _s,
unsigned  _idOffset,
p2p::CapDesc const &  _cap,
uint16_t  _capID 
)
overrideprotected

Definition at line 644 of file EthereumHost.cpp.

Here is the call graph for this function:

void dev::eth::EthereumHost::noteNewBlocks ( )
inline

Definition at line 82 of file EthereumHost.h.

void dev::eth::EthereumHost::noteNewTransactions ( )
inline

Definition at line 81 of file EthereumHost.h.

void dev::eth::EthereumHost::onBlockImported ( BlockHeader const &  _info)
inline

Definition at line 83 of file EthereumHost.h.

virtual void dev::eth::EthereumHost::onStarting ( )
inlineoverrideprivatevirtual

Reimplemented from dev::p2p::HostCapabilityFace.

Definition at line 117 of file EthereumHost.h.

virtual void dev::eth::EthereumHost::onStopping ( )
inlineoverrideprivatevirtual

Reimplemented from dev::p2p::HostCapabilityFace.

Definition at line 118 of file EthereumHost.h.

void EthereumHost::onTransactionImported ( ImportResult  _ir,
h256 const &  _h,
h512 const &  _nodeId 
)
private

Definition at line 612 of file EthereumHost.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned dev::eth::EthereumHost::protocolVersion ( ) const
inline

Definition at line 70 of file EthereumHost.h.

Here is the caller graph for this function:

tuple< vector< shared_ptr< EthereumPeer > >, vector< shared_ptr< EthereumPeer > >, vector< shared_ptr< SessionFace > > > EthereumHost::randomSelection ( unsigned  _percent = 25,
std::function< bool(EthereumPeer *)> const &  _allow = [](EthereumPeer const*){ return true; } 
)
private

Definition at line 523 of file EthereumHost.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumHost::reset ( )

Definition at line 414 of file EthereumHost.cpp.

void dev::eth::EthereumHost::setNetworkId ( u256  _n)
inline

Definition at line 72 of file EthereumHost.h.

static char const* dev::eth::EthereumHost::stateName ( SyncState  _s)
inlinestatic

Definition at line 91 of file EthereumHost.h.

SyncStatus EthereumHost::status ( ) const

Definition at line 606 of file EthereumHost.cpp.

Member Data Documentation

unsigned const EthereumHost::c_oldProtocolVersion = 62
static

Definition at line 93 of file EthereumHost.h.

std::unordered_set<p2p::NodeID> dev::eth::EthereumHost::m_banned
private

Definition at line 130 of file EthereumHost.h.

BlockQueue& dev::eth::EthereumHost::m_bq
private

Maintains a list of incoming blocks not yet on the blockchain (to be imported).

Definition at line 123 of file EthereumHost.h.

BlockChain const& dev::eth::EthereumHost::m_chain
private

Definition at line 120 of file EthereumHost.h.

OverlayDB const& dev::eth::EthereumHost::m_db
private

References to DB, needed for some of the Ethereum Protocol responses.

Definition at line 121 of file EthereumHost.h.

std::shared_ptr<EthereumHostDataFace> dev::eth::EthereumHost::m_hostData
private

Definition at line 140 of file EthereumHost.h.

std::atomic<time_t> dev::eth::EthereumHost::m_lastTick = { 0 }
private

Definition at line 138 of file EthereumHost.h.

h256 dev::eth::EthereumHost::m_latestBlockSent
private

Definition at line 127 of file EthereumHost.h.

u256 dev::eth::EthereumHost::m_networkId
private

Definition at line 125 of file EthereumHost.h.

bool dev::eth::EthereumHost::m_newBlocks = false
private

Definition at line 133 of file EthereumHost.h.

bool dev::eth::EthereumHost::m_newTransactions = false
private

Definition at line 132 of file EthereumHost.h.

std::shared_ptr<EthereumPeerObserverFace> dev::eth::EthereumHost::m_peerObserver
private

Definition at line 141 of file EthereumHost.h.

std::unique_ptr<BlockChainSync> dev::eth::EthereumHost::m_sync
private

Definition at line 137 of file EthereumHost.h.

TransactionQueue& dev::eth::EthereumHost::m_tq
private

Maintains a list of incoming transactions not yet in a block on the blockchain.

Definition at line 122 of file EthereumHost.h.

h256Hash dev::eth::EthereumHost::m_transactionsSent
private

Definition at line 128 of file EthereumHost.h.

char const *const EthereumHost::s_stateNames = {"NotSynced", "Idle", "Waiting", "Blocks", "State", "NewBlocks" }
staticprivate

Definition at line 100 of file EthereumHost.h.

RecursiveMutex dev::eth::EthereumHost::x_sync
mutableprivate

Definition at line 135 of file EthereumHost.h.

Mutex dev::eth::EthereumHost::x_transactions
mutableprivate

Definition at line 136 of file EthereumHost.h.


The documentation for this class was generated from the following files: