pub fn start(
        s: Sender<BftMsg>,
        r: Receiver<BftMsg>,
        f: Arc<T>,
        local_address: Address,
        wal_path: &str,
    ) {
        // define message channel and timeout channel
        let (bft2timer, timer4bft) = unbounded();
        let (timer2bft, bft4timer) = unbounded();

        let mut engine = Bft::new(
            s,
            r,
            bft2timer,
            bft4timer,
            f,
            local_address.clone(),
            wal_path,
        );

        // start timer module.
        let _timer_thread = thread::Builder::new()
            .name("bft_timer".to_string())
            .spawn(move || {
                let timer = WaitTimer::new(timer2bft, timer4bft);
                timer.start();
            })
            .unwrap_or_else(|_| panic!("Node {:?} starts time-thread failed!", local_address));

        // start main loop module.
        let _main_thread = thread::Builder::new()
            .name("main_loop".to_string())
            .spawn(move || {
                engine.load_wal_log();

                loop {
                    let mut get_timer_msg = Err(RecvError);
                    let mut get_msg = Err(RecvError);

                    select! {
                        recv(engine.timer_notity) -> msg => get_timer_msg = msg,
                        recv(engine.msg_receiver) -> msg => get_msg = msg,
                    }

                    if let Ok(msg) = get_timer_msg {
                        handle_err(engine.timeout_process(msg, true), &engine.params.address);
                    }
                    if let Ok(msg) = get_msg {
                        match msg {
                            BftMsg::Kill => {
                                break;
                            }
                            _ => {
                                handle_err(engine.process(msg, true), &engine.params.address);
                            }
                        }
                    }
                }
            })
            .unwrap_or_else(|_| panic!("Node {:?} starts main-thread failed!", local_address));
    }
/// A function to start a BFT state machine.
A function to start a BFT state machine.
A function to start a BFT state machine .
pub fn start(
        s: Sender<BftMsg>,
        r: Receiver<BftMsg>,
        f: Arc<T>,
        local_address: Address,
        wal_path: &str,
    ) {
        // define message channel and timeout channel
        let (bft2timer, timer4bft) = unbounded();
        let (timer2bft, bft4timer) = unbounded();
        let mut engine = Bft::new(
            s,
            r,
            bft2timer,
            bft4timer,
            f,
            local_address.clone(),
            wal_path,
        );
        // start timer module.
        let _timer_thread = thread::Builder::new()
            .name("bft_timer".to_string())
            .spawn(move || {
                let timer = WaitTimer::new(timer2bft, timer4bft);
                timer.start();
            })
            .unwrap_or_else(|_| panic!("Node {:?} starts time-thread failed!", local_address));
        // start main loop module.
        let _main_thread = thread::Builder::new()
            .name("main_loop".to_string())
            .spawn(move || {
                engine.load_wal_log();
                loop {
                    let mut get_timer_msg = Err(RecvError);
                    let mut get_msg = Err(RecvError);
                    select! {
                        recv(engine.timer_notity) -> msg => get_timer_msg = msg,
                        recv(engine.msg_receiver) -> msg => get_msg = msg,
                    }
                    if let Ok(msg) = get_timer_msg {
                        handle_err(engine.timeout_process(msg, true), &engine.params.address);
                    }
                    if let Ok(msg) = get_msg {
                        match msg {
                            BftMsg::Kill => {
                                break;
                            }
                            _ => {
                                handle_err(engine.process(msg, true), &engine.params.address);
                            }
                        }
                    }
                }
            })
            .unwrap_or_else(|_| panic!("Node {:?} starts main-thread failed!", local_address));
    }
pub fn start ( s : Sender < BftMsg > , r : Receiver < BftMsg > , f : Arc < T > , local_address : Address , wal_path : & str , ) { // define message channel and timeout channel let ( bft2timer , timer4bft ) = unbounded ( ) ; let ( timer2bft , bft4timer ) = unbounded ( ) ; let mut engine = Bft :: new ( s , r , bft2timer , bft4timer , f , local_address . clone ( ) , wal_path , ) ; // start timer module. let _timer_thread = thread :: Builder :: new ( ) . name ( " " . to_string ( ) ) . spawn ( move | | { let timer = WaitTimer :: new ( timer2bft , timer4bft ) ; timer . start ( ) ; } ) . unwrap_or_else ( | _ | panic ! ( " " local_address ) ) ; // start main loop module. let _main_thread = thread :: Builder :: new ( ) . name ( " " . to_string ( ) ) . spawn ( move | | { engine . load_wal_log ( ) ; loop { let mut get_timer_msg = Err ( RecvError ) ; let mut get_msg = Err ( RecvError ) ; select ! { recv ( engine timer_notity ) msg get_timer_msg msg recv ( engine msg_receiver ) msg get_msg msg } if let Ok ( msg ) = get_timer_msg { handle_err ( engine . timeout_process ( msg , true ) , & engine . params . address ) ; } if let Ok ( msg ) = get_msg { match msg { BftMsg :: Kill => { break ; } _ => { handle_err ( engine . process ( msg , true ) , & engine . params . address ) ; } } } } } ) . unwrap_or_else ( | _ | panic ! ( " " local_address ) ) ; }
A function to start a BFT state machine.
A function to start a BFT state machine .
s
Sender<BftMsg>
r
Receiver<BftMsg>
f
Arc<T>
local_address
Address
wal_path
&str
s
Sender<BftMsg>
r
Receiver<BftMsg>
f
Arc<T>
local_address
Address
wal_path
&str