Struct exonum::node::NodeHandler
[−]
[src]
pub struct NodeHandler { pub state: State, pub api_state: SharedNodeState, pub system_state: Box<SystemStateProvider>, pub channel: NodeSender, pub blockchain: Blockchain, pub peer_discovery: Vec<SocketAddr>, // some fields omitted }
Handler that that performs consensus algorithm.
Fields
state: State
State of the NodeHandler
.
api_state: SharedNodeState
Shared api state.
system_state: Box<SystemStateProvider>
System state.
channel: NodeSender
Channel for messages and timeouts.
blockchain: Blockchain
Blockchain.
peer_discovery: Vec<SocketAddr>
Known peer addresses.
Methods
impl NodeHandler
[src]
pub fn handle_message(&mut self, raw: RawMessage)
[src]
Redirects message to the corresponding handle_...
function.
pub fn handle_connected(&mut self, addr: SocketAddr, connect: Connect)
[src]
Handles the Connected
event. Node's Connect
message is sent as response
if received Connect
message is correct.
pub fn handle_disconnected(&mut self, addr: SocketAddr)
[src]
Handles the Disconnected
event. Node will try to connect to that address again if it was
in the validators list.
pub fn handle_unable_to_connect(&mut self, addr: SocketAddr)
[src]
Handles the UnableConnectToPeer
event. Node will try to connect to that address again
if it was in the validators list.
pub fn handle_connect(&mut self, message: Connect)
[src]
Handles the Connect
message and connects to a peer as result.
pub fn handle_status(&mut self, msg: &Status)
[src]
Handles the Status
message. Node sends BlockRequest
as response if height in the
message is higher than node's height.
pub fn handle_request_peers(&mut self, msg: &PeersRequest)
[src]
Handles the PeersRequest
message. Node sends Connect
messages of other peers as result.
pub fn handle_status_timeout(&mut self, height: Height)
[src]
Handles NodeTimeout::Status
, broadcasts the Status
message if it isn't outdated as
result.
pub fn handle_peer_exchange_timeout(&mut self)
[src]
Handles NodeTimeout::PeerExchange
. Node sends the PeersRequest
to a random peer.
pub fn handle_update_api_state_timeout(&mut self)
[src]
Handles NodeTimeout::UpdateApiState
.
Node update internal ApiState
.
pub fn broadcast_status(&mut self)
[src]
Broadcasts the Status
message to all peers.
impl NodeHandler
[src]
pub fn handle_consensus(&mut self, msg: ConsensusMessage)
[src]
Validates consensus message, then redirects it to the corresponding handle_...
function.
pub fn handle_propose(&mut self, from: PublicKey, msg: &Propose)
[src]
Handles the Propose
message. For details see the message documentation.
pub fn handle_block(&mut self, msg: &BlockResponse)
[src]
Handles the Block
message. For details see the message documentation.
pub fn has_full_propose(&mut self, hash: Hash, propose_round: Round)
[src]
Executes and commits block. This function is called when node has full propose information.
pub fn handle_prevote(&mut self, from: PublicKey, msg: &Prevote)
[src]
Handles the Prevote
message. For details see the message documentation.
pub fn has_majority_prevotes(
&mut self,
prevote_round: Round,
propose_hash: &Hash
)
[src]
&mut self,
prevote_round: Round,
propose_hash: &Hash
)
Locks to the propose by calling lock
. This function is called when node receives
+2/3 pre-votes.
pub fn has_majority_precommits(
&mut self,
round: Round,
propose_hash: &Hash,
block_hash: &Hash
)
[src]
&mut self,
round: Round,
propose_hash: &Hash,
block_hash: &Hash
)
Executes and commits block. This function is called when the node has +2/3 pre-commits.
pub fn lock(&mut self, prevote_round: Round, propose_hash: Hash)
[src]
Locks node to the specified round, so pre-votes for the lower round will be ignored.
pub fn handle_precommit(&mut self, from: PublicKey, msg: &Precommit)
[src]
Handles the Precommit
message. For details see the message documentation.
pub fn commit<'a, I: Iterator<Item = &'a Precommit>>(
&mut self,
block_hash: Hash,
precommits: I,
round: Option<Round>
)
[src]
&mut self,
block_hash: Hash,
precommits: I,
round: Option<Round>
)
Commits block, so new height is achieved.
pub fn handle_tx(&mut self, msg: RawTransaction)
[src]
Handles raw transaction. Transaction is ignored if it is already known, otherwise it is added to the transactions pool.
pub fn handle_incoming_tx(&mut self, msg: Box<Transaction>)
[src]
Handles external boxed transaction. Additionally transaction will be broadcast to the Node's peers.
pub fn handle_new_round(&mut self, height: Height, round: Round)
[src]
Handle new round, after jump.
pub fn handle_round_timeout(&mut self, height: Height, round: Round)
[src]
Handles round timeout. As result node sends Propose
if it is a leader or Prevote
if it
is locked to some round.
pub fn handle_propose_timeout(&mut self, height: Height, round: Round)
[src]
Handles propose timeout. Node sends Propose
and Prevote
if it is a leader as result.
pub fn handle_request_timeout(
&mut self,
data: &RequestData,
peer: Option<PublicKey>
)
[src]
&mut self,
data: &RequestData,
peer: Option<PublicKey>
)
Handles request timeout by sending the corresponding request message to a peer.
pub fn create_block(
&mut self,
proposer_id: ValidatorId,
height: Height,
tx_hashes: &[Hash]
) -> (Hash, Patch)
[src]
&mut self,
proposer_id: ValidatorId,
height: Height,
tx_hashes: &[Hash]
) -> (Hash, Patch)
Creates block with given transaction and returns its hash and corresponding changes.
pub fn execute(&mut self, propose_hash: &Hash) -> Hash
[src]
Calls create_block
with transactions from the corresponding Propose
and returns the
block hash.
pub fn request_propose_or_txs(
&mut self,
propose_hash: &Hash,
key: PublicKey
) -> bool
[src]
&mut self,
propose_hash: &Hash,
key: PublicKey
) -> bool
Returns true
if propose and all transactions are known, otherwise requests needed data
and returns false
.
pub fn request_next_block(&mut self)
[src]
Requests a block for the next height from all peers with a bigger height. Called when the node tries to catch up with other nodes' height.
pub fn remove_request(&mut self, data: &RequestData) -> HashSet<PublicKey>
[src]
Removes the specified request from the pending request list.
pub fn broadcast_prevote(&mut self, round: Round, propose_hash: &Hash) -> bool
[src]
Broadcasts the Prevote
message to all peers.
pub fn broadcast_precommit(
&mut self,
round: Round,
propose_hash: &Hash,
block_hash: &Hash
)
[src]
&mut self,
round: Round,
propose_hash: &Hash,
block_hash: &Hash
)
Broadcasts the Precommit
message to all peers.
impl NodeHandler
[src]
pub fn handle_request(&mut self, msg: RequestMessage)
[src]
Validates request, then redirects it to the corresponding handle_...
function.
pub fn handle_request_propose(&mut self, msg: &ProposeRequest)
[src]
Handles ProposeRequest
message. For details see the message documentation.
pub fn handle_request_txs(&mut self, msg: &TransactionsRequest)
[src]
Handles TransactionsRequest
message. For details see the message documentation.
pub fn handle_request_prevotes(&mut self, msg: &PrevotesRequest)
[src]
Handles PrevotesRequest
message. For details see the message documentation.
pub fn handle_request_block(&mut self, msg: &BlockRequest)
[src]
Handles BlockRequest
message. For details see the message documentation.
impl NodeHandler
[src]
pub fn new(
blockchain: Blockchain,
external_address: SocketAddr,
sender: NodeSender,
system_state: Box<SystemStateProvider>,
config: Configuration,
api_state: SharedNodeState
) -> Self
[src]
blockchain: Blockchain,
external_address: SocketAddr,
sender: NodeSender,
system_state: Box<SystemStateProvider>,
config: Configuration,
api_state: SharedNodeState
) -> Self
Creates NodeHandler
using specified Configuration
.
pub fn api_state(&self) -> &SharedNodeState
[src]
Return internal SharedNodeState
pub fn round_timeout(&self) -> Milliseconds
[src]
Returns value of the round_timeout
field from the current ConsensusConfig
.
pub fn status_timeout(&self) -> Milliseconds
[src]
Returns value of the status_timeout
field from the current ConsensusConfig
.
pub fn peers_timeout(&self) -> Milliseconds
[src]
Returns value of the peers_timeout
field from the current ConsensusConfig
.
pub fn txs_block_limit(&self) -> u32
[src]
Returns value of the txs_block_limit
field from the current ConsensusConfig
.
pub fn state(&self) -> &State
[src]
Returns State
of the node.
pub fn initialize(&mut self)
[src]
Performs node initialization, so it starts consensus process from the first round.
pub fn send_to_validator(&mut self, id: u32, message: &RawMessage)
[src]
Sends the given message to a peer by its id.
pub fn send_to_peer(&mut self, public_key: PublicKey, message: &RawMessage)
[src]
Sends the given message to a peer by its public key.
pub fn send_to_addr(&mut self, address: &SocketAddr, message: &RawMessage)
[src]
Sends RawMessage
to the specified address.
pub fn broadcast(&mut self, message: &RawMessage)
[src]
Broadcasts given message to all peers.
pub fn connect(&mut self, address: &SocketAddr)
[src]
Performs connection to the specified network address.
pub fn add_timeout(&mut self, timeout: NodeTimeout, time: SystemTime)
[src]
Add timeout request.
pub fn request(&mut self, data: RequestData, peer: PublicKey)
[src]
Adds request timeout if it isn't already requested.
pub fn add_round_timeout(&mut self)
[src]
Adds NodeTimeout::Round
timeout to the channel.
pub fn add_propose_timeout(&mut self)
[src]
Adds NodeTimeout::Propose
timeout to the channel.
pub fn add_status_timeout(&mut self)
[src]
Adds NodeTimeout::Status
timeout to the channel.
pub fn add_request_timeout(
&mut self,
data: RequestData,
peer: Option<PublicKey>
)
[src]
&mut self,
data: RequestData,
peer: Option<PublicKey>
)
Adds NodeTimeout::Request
timeout with RequestData
to the channel.
pub fn add_peer_exchange_timeout(&mut self)
[src]
Adds NodeTimeout::PeerExchange
timeout to the channel.
pub fn add_update_api_state_timeout(&mut self)
[src]
Adds NodeTimeout::UpdateApiState
timeout to the channel.
pub fn last_block_hash(&self) -> Hash
[src]
Returns hash of the last block.
pub fn round_start_time(&self, round: Round) -> SystemTime
[src]
Returns start time of the requested round.