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

The EthereumPeer class. More...

#include <EthereumPeer.h>

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

Public Member Functions

 EthereumPeer (std::shared_ptr< p2p::SessionFace > _s, p2p::HostCapabilityFace *_h, unsigned _i, p2p::CapDesc const &_cap, uint16_t _capID)
 Basic constructor. More...
 
virtual ~EthereumPeer ()
 Basic destructor. More...
 
void init (unsigned _hostProtocolVersion, u256 _hostNetworkId, u256 _chainTotalDifficulty, h256 _chainCurrentHash, h256 _chainGenesisHash, std::shared_ptr< EthereumHostDataFace > _hostData, std::shared_ptr< EthereumPeerObserverFace > _observer)
 
p2p::NodeID id () const
 
void setIdle ()
 Abort sync and reset fetch. More...
 
void requestBlockHeaders (h256 const &_startHash, unsigned _count, unsigned _skip, bool _reverse)
 Request hashes for given parent hash. More...
 
void requestBlockHeaders (unsigned _startNumber, unsigned _count, unsigned _skip, bool _reverse)
 
void requestBlockBodies (h256s const &_blocks)
 Request specified blocks from peer. More...
 
void requestNodeData (h256s const &_hashes)
 Request values for specified keys from peer. More...
 
void requestReceipts (h256s const &_blocks)
 Request receipts for specified blocks from peer. More...
 
bool isRude () const
 Check if this node is rude. More...
 
void setRude ()
 Set that it's a rude node. More...
 
void abortSync ()
 Abort the sync operation. More...
 
- Public Member Functions inherited from dev::p2p::Capability
 Capability (std::shared_ptr< SessionFace > _s, HostCapabilityFace *_h, unsigned _idOffset, uint16_t _protocolID)
 
virtual ~Capability ()
 

Static Public Member Functions

static std::string name ()
 What is our name? More...
 
static u256 version ()
 What is our version? More...
 
static unsigned messageCount ()
 How many message types do we have? More...
 

Private Member Functions

unsigned askOverride () const
 Figure out the amount of blocks we should be asking for. More...
 
virtual bool interpret (unsigned _id, RLP const &_r)
 Interpret an incoming message. More...
 
void requestStatus (u256 _hostNetworkId, u256 _chainTotalDifficulty, h256 _chainCurrentHash, h256 _chainGenesisHash)
 Request status. Called from constructor. More...
 
void clearKnownTransactions ()
 Clear all known transactions. More...
 
void requestByHashes (h256s const &_hashes, Asking _asking, SubprotocolPacketType _packetType)
 
void setAsking (Asking _g)
 Update our asking state. More...
 
bool needsSyncing () const
 Do we presently need syncing with this peer? More...
 
bool isConversing () const
 Are we presently in the process of communicating with this peer? More...
 
bool isCriticalSyncing () const
 Are we presently in a critical part of the syncing process with this peer? More...
 
void tick ()
 Runs period checks to check up on the peer. More...
 

Private Attributes

unsigned m_hostProtocolVersion = 0
 
unsigned m_protocolVersion
 Peer's protocol version. More...
 
u256 m_networkId
 Peer's network id. More...
 
Asking m_asking = Asking::Nothing
 What, if anything, we last asked the other peer for. More...
 
std::atomic< time_t > m_lastAsk
 When we asked for it. Allows a time out. More...
 
h256 m_latestHash
 These are determined through either a Status message or from NewBlock. More...
 
u256 m_totalDifficulty
 Peer's latest block's total difficulty. More...
 
h256 m_genesisHash
 Peer's genesis hash. More...
 
u256 const m_peerCapabilityVersion
 Protocol version this peer supports received as capability. More...
 
bool m_requireTransactions = false
 Have we received a GetTransactions packet that we haven't yet answered? More...
 
Mutex x_knownBlocks
 
h256Hash m_knownBlocks
 Blocks that the peer already knows about (that don't need to be sent to them). More...
 
Mutex x_knownTransactions
 
h256Hash m_knownTransactions
 Transactions that the peer already knows of. More...
 
unsigned m_unknownNewBlocks = 0
 Number of unknown NewBlocks received from this peer. More...
 
unsigned m_lastAskedHeaders = 0
 Number of hashes asked. More...
 
std::shared_ptr< EthereumPeerObserverFacem_observer
 
std::shared_ptr< EthereumHostDataFacem_hostData
 

Friends

class EthereumHost
 
class BlockChainSync
 

Additional Inherited Members

- Protected Member Functions inherited from dev::p2p::Capability
std::shared_ptr< SessionFacesession () const
 
HostCapabilityFacehostCapability () const
 
void disable (std::string const &_problem)
 
RLPStreamprep (RLPStream &_s, unsigned _id, unsigned _args=0)
 
void sealAndSend (RLPStream &_s)
 
void addRating (int _r)
 
- Protected Attributes inherited from dev::p2p::Capability
uint16_t const c_protocolID
 

Detailed Description

The EthereumPeer class.

Todo:
Document fully.
Todo:
make state transitions thread-safe.

Definition at line 83 of file EthereumPeer.h.

Constructor & Destructor Documentation

EthereumPeer::EthereumPeer ( std::shared_ptr< p2p::SessionFace _s,
p2p::HostCapabilityFace _h,
unsigned  _i,
p2p::CapDesc const &  _cap,
uint16_t  _capID 
)

Basic constructor.

Definition at line 53 of file EthereumPeer.cpp.

Here is the call graph for this function:

EthereumPeer::~EthereumPeer ( )
virtual

Basic destructor.

Definition at line 60 of file EthereumPeer.cpp.

Here is the call graph for this function:

Member Function Documentation

void EthereumPeer::abortSync ( )

Abort the sync operation.

Definition at line 110 of file EthereumPeer.cpp.

Here is the caller graph for this function:

unsigned EthereumPeer::askOverride ( ) const
private

Figure out the amount of blocks we should be asking for.

Definition at line 86 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::EthereumPeer::clearKnownTransactions ( )
inlineprivate

Clear all known transactions.

Definition at line 146 of file EthereumPeer.h.

p2p::NodeID dev::eth::EthereumPeer::id ( ) const
inline

Definition at line 106 of file EthereumPeer.h.

Here is the call graph for this function:

void EthereumPeer::init ( unsigned  _hostProtocolVersion,
u256  _hostNetworkId,
u256  _chainTotalDifficulty,
h256  _chainCurrentHash,
h256  _chainGenesisHash,
std::shared_ptr< EthereumHostDataFace _hostData,
std::shared_ptr< EthereumPeerObserverFace _observer 
)

Definition at line 70 of file EthereumPeer.cpp.

Here is the call graph for this function:

bool EthereumPeer::interpret ( unsigned  _id,
RLP const &  _r 
)
privatevirtual

Interpret an incoming message.

Packet layout: [ block: { P , B_32 }, maxHeaders: P, skip: P, reverse: P in { 0 , 1 } ]

Implements dev::p2p::Capability.

Definition at line 237 of file EthereumPeer.cpp.

Here is the call graph for this function:

bool EthereumPeer::isConversing ( ) const
private

Are we presently in the process of communicating with this peer?

Definition at line 227 of file EthereumPeer.cpp.

bool EthereumPeer::isCriticalSyncing ( ) const
private

Are we presently in a critical part of the syncing process with this peer?

Definition at line 232 of file EthereumPeer.cpp.

Here is the caller graph for this function:

bool EthereumPeer::isRude ( ) const

Check if this node is rude.

Definition at line 78 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static unsigned dev::eth::EthereumPeer::messageCount ( )
inlinestatic

How many message types do we have?

Definition at line 102 of file EthereumPeer.h.

static std::string dev::eth::EthereumPeer::name ( )
inlinestatic

What is our name?

Definition at line 96 of file EthereumPeer.h.

Here is the caller graph for this function:

bool dev::eth::EthereumPeer::needsSyncing ( ) const
inlineprivate

Do we presently need syncing with this peer?

Definition at line 155 of file EthereumPeer.h.

Here is the caller graph for this function:

void EthereumPeer::requestBlockBodies ( h256s const &  _blocks)

Request specified blocks from peer.

Definition at line 171 of file EthereumPeer.cpp.

Here is the call graph for this function:

void EthereumPeer::requestBlockHeaders ( h256 const &  _startHash,
unsigned  _count,
unsigned  _skip,
bool  _reverse 
)

Request hashes for given parent hash.

Definition at line 156 of file EthereumPeer.cpp.

Here is the call graph for this function:

void EthereumPeer::requestBlockHeaders ( unsigned  _startNumber,
unsigned  _count,
unsigned  _skip,
bool  _reverse 
)

Definition at line 142 of file EthereumPeer.cpp.

Here is the call graph for this function:

void EthereumPeer::requestByHashes ( h256s const &  _hashes,
Asking  _asking,
SubprotocolPacketType  _packetType 
)
private

Definition at line 186 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumPeer::requestNodeData ( h256s const &  _hashes)

Request values for specified keys from peer.

Definition at line 176 of file EthereumPeer.cpp.

Here is the call graph for this function:

void EthereumPeer::requestReceipts ( h256s const &  _blocks)

Request receipts for specified blocks from peer.

Definition at line 181 of file EthereumPeer.cpp.

Here is the call graph for this function:

void EthereumPeer::requestStatus ( u256  _hostNetworkId,
u256  _chainTotalDifficulty,
h256  _chainCurrentHash,
h256  _chainGenesisHash 
)
private

Request status. Called from constructor.

Definition at line 126 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumPeer::setAsking ( Asking  _g)
private

Update our asking state.

Definition at line 205 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumPeer::setIdle ( )

Abort sync and reset fetch.

Definition at line 121 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumPeer::setRude ( )

Set that it's a rude node.

Definition at line 98 of file EthereumPeer.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EthereumPeer::tick ( )
private

Runs period checks to check up on the peer.

Definition at line 218 of file EthereumPeer.cpp.

Here is the call graph for this function:

static u256 dev::eth::EthereumPeer::version ( )
inlinestatic

What is our version?

Definition at line 99 of file EthereumPeer.h.

Friends And Related Function Documentation

friend class BlockChainSync
friend

Definition at line 86 of file EthereumPeer.h.

friend class EthereumHost
friend

Definition at line 85 of file EthereumPeer.h.

Member Data Documentation

Asking dev::eth::EthereumPeer::m_asking = Asking::Nothing
private

What, if anything, we last asked the other peer for.

Definition at line 175 of file EthereumPeer.h.

h256 dev::eth::EthereumPeer::m_genesisHash
private

Peer's genesis hash.

Definition at line 182 of file EthereumPeer.h.

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

Definition at line 196 of file EthereumPeer.h.

unsigned dev::eth::EthereumPeer::m_hostProtocolVersion = 0
private

Definition at line 166 of file EthereumPeer.h.

h256Hash dev::eth::EthereumPeer::m_knownBlocks
private

Blocks that the peer already knows about (that don't need to be sent to them).

Definition at line 189 of file EthereumPeer.h.

h256Hash dev::eth::EthereumPeer::m_knownTransactions
private

Transactions that the peer already knows of.

Definition at line 191 of file EthereumPeer.h.

std::atomic<time_t> dev::eth::EthereumPeer::m_lastAsk
private

When we asked for it. Allows a time out.

Definition at line 177 of file EthereumPeer.h.

unsigned dev::eth::EthereumPeer::m_lastAskedHeaders = 0
private

Number of hashes asked.

Definition at line 193 of file EthereumPeer.h.

h256 dev::eth::EthereumPeer::m_latestHash
private

These are determined through either a Status message or from NewBlock.

Peer's latest block's hash that we know about or default null value if no need to sync.

Definition at line 180 of file EthereumPeer.h.

u256 dev::eth::EthereumPeer::m_networkId
private

Peer's network id.

Definition at line 172 of file EthereumPeer.h.

std::shared_ptr<EthereumPeerObserverFace> dev::eth::EthereumPeer::m_observer
private

Definition at line 195 of file EthereumPeer.h.

u256 const dev::eth::EthereumPeer::m_peerCapabilityVersion
private

Protocol version this peer supports received as capability.

Definition at line 184 of file EthereumPeer.h.

unsigned dev::eth::EthereumPeer::m_protocolVersion
private

Peer's protocol version.

Definition at line 169 of file EthereumPeer.h.

bool dev::eth::EthereumPeer::m_requireTransactions = false
private

Have we received a GetTransactions packet that we haven't yet answered?

Definition at line 186 of file EthereumPeer.h.

u256 dev::eth::EthereumPeer::m_totalDifficulty
private

Peer's latest block's total difficulty.

Definition at line 181 of file EthereumPeer.h.

unsigned dev::eth::EthereumPeer::m_unknownNewBlocks = 0
private

Number of unknown NewBlocks received from this peer.

Definition at line 192 of file EthereumPeer.h.

Mutex dev::eth::EthereumPeer::x_knownBlocks
private

Definition at line 188 of file EthereumPeer.h.

Mutex dev::eth::EthereumPeer::x_knownTransactions
private

Definition at line 190 of file EthereumPeer.h.


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