use std::net::SocketAddr;
use std::time::SystemTime;
use crypto::{Hash, PublicKey};
use blockchain;
use helpers::{Height, Round, ValidatorId};
use super::{ServiceMessage, RawMessage, BitVec};
pub const CONSENSUS: u16 = 0;
pub const CONNECT_MESSAGE_ID: u16 = Connect::MESSAGE_ID;
pub const STATUS_MESSAGE_ID: u16 = Status::MESSAGE_ID;
pub const PROPOSE_MESSAGE_ID: u16 = Propose::MESSAGE_ID;
pub const PREVOTE_MESSAGE_ID: u16 = Prevote::MESSAGE_ID;
pub const PRECOMMIT_MESSAGE_ID: u16 = Precommit::MESSAGE_ID;
pub const BLOCK_RESPONSE_MESSAGE_ID: u16 = BlockResponse::MESSAGE_ID;
pub const PROPOSE_REQUEST_MESSAGE_ID: u16 = ProposeRequest::MESSAGE_ID;
pub const TRANSACTIONS_REQUEST_MESSAGE_ID: u16 = TransactionsRequest::MESSAGE_ID;
pub const PREVOTES_REQUEST_MESSAGE_ID: u16 = PrevotesRequest::MESSAGE_ID;
pub const PEERS_REQUEST_MESSAGE_ID: u16 = PeersRequest::MESSAGE_ID;
pub const BLOCK_REQUEST_MESSAGE_ID: u16 = BlockRequest::MESSAGE_ID;
messages! {
const SERVICE_ID = CONSENSUS;
struct Connect {
pub_key: &PublicKey,
addr: SocketAddr,
time: SystemTime,
user_agent: &str,
}
struct Status {
from: &PublicKey,
height: Height,
last_hash: &Hash,
}
struct Propose {
validator: ValidatorId,
height: Height,
round: Round,
prev_hash: &Hash,
transactions: &[Hash],
}
struct Prevote {
validator: ValidatorId,
height: Height,
round: Round,
propose_hash: &Hash,
locked_round: Round,
}
struct Precommit {
validator: ValidatorId,
height: Height,
round: Round,
propose_hash: &Hash,
block_hash: &Hash,
time: SystemTime,
}
struct BlockResponse {
from: &PublicKey,
to: &PublicKey,
block: blockchain::Block,
precommits: Vec<Precommit>,
transactions: Vec<RawMessage>,
}
struct ProposeRequest {
from: &PublicKey,
to: &PublicKey,
height: Height,
propose_hash: &Hash,
}
struct TransactionsRequest {
from: &PublicKey,
to: &PublicKey,
txs: &[Hash],
}
struct PrevotesRequest {
from: &PublicKey,
to: &PublicKey,
height: Height,
round: Round,
propose_hash: &Hash,
validators: BitVec,
}
struct PeersRequest {
from: &PublicKey,
to: &PublicKey,
}
struct BlockRequest {
from: &PublicKey,
to: &PublicKey,
height: Height,
}
}