sraft

simple raft implementation
git clone https://git.parazyd.org/sraft
Log | Files | Refs | README

method.rs (840B)


      1 use borsh::{BorshDeserialize, BorshSerialize};
      2 
      3 use crate::LogEntry;
      4 
      5 #[derive(BorshSerialize, BorshDeserialize, Debug)]
      6 pub enum RaftMethod {
      7     Vote(VoteArgs),
      8     Heartbeat(HeartbeatArgs),
      9 }
     10 
     11 #[derive(BorshSerialize, BorshDeserialize, Clone, Debug)]
     12 pub struct VoteArgs {
     13     pub term: u64,
     14     pub candidate_id: u64,
     15 }
     16 
     17 #[derive(BorshSerialize, BorshDeserialize, Debug)]
     18 pub struct VoteReply {
     19     pub term: u64,
     20     pub vote_granted: bool,
     21 }
     22 
     23 #[derive(BorshSerialize, BorshDeserialize, Debug)]
     24 pub struct HeartbeatArgs {
     25     pub term: u64,
     26     pub leader_id: u64,
     27 
     28     pub prev_log_index: u64,
     29     pub prev_log_term: u64,
     30 
     31     pub entries: Vec<LogEntry>,
     32     pub leader_commit: u64,
     33 }
     34 
     35 #[derive(BorshSerialize, BorshDeserialize, Debug)]
     36 pub struct HeartbeatReply {
     37     pub success: bool,
     38     pub term: u64,
     39     pub next_index: u64,
     40 }