/// Arrow Client main thread.
///
/// This function ensures maintaining connection with a remote Arrow Service.
Arrow Client main thread.
This function ensures maintaining connection with a remote Arrow Service.
Arrow Client main thread . This function ensures maintaining connection with a remote Arrow Service .
fn arrow_thread<L: Logger + Clone, Q: Sender<Command> + Clone>(
    mut logger: L,
    state_file: &str,
    mut ssl_context: SslContext,
    cmd_sender: Q,
    addr: &str,
    arrow_mac: &MacAddr,
    app_context: Shared<AppContext>) {
    let diagnostic_mode = app_context.lock()
        .unwrap()
        .diagnostic_mode;
    let t = time::precise_time_s();
    let mut unauthorized_timeout = t + 1200.0;
    let mut cur_addr = addr.to_string();
    let mut last_attempt;
    let verify_data = Shared::new(VerifyCallbackData::new(&cur_addr));
    ssl_context.set_verify_with_data(
        SSL_VERIFY_PEER,
        openssl_verify_callback,
        verify_data.clone());
    loop {
        log_info!(logger, "connecting to remote Arrow Service {}", cur_addr);
        let lgr = logger.clone();
        let ctx = app_context.clone();
        last_attempt = time::precise_time_s();
        utils::result_or_log(&mut logger, Severity::INFO,
            "unable to save current connection state",
            save_connection_state(CONN_STATE_CONNECTED, state_file));
        let res = connect(lgr, &ssl_context, cmd_sender.clone(),
            &cur_addr, arrow_mac, ctx);
        unauthorized_timeout = get_unauthorized_timeout(&res,
            last_attempt,
            unauthorized_timeout);
        if diagnostic_mode {
            diagnose_connection_result(&res);
        }
        match res {
            Ok(addr) => cur_addr = addr,
            Err(err) => {
                log_warn!(logger, "{}", err.description());
                let res = match err.kind() {
                    ErrorKind::Unauthorized =>
                         save_connection_state(CONN_STATE_UNAUTHORIZED, state_file),
                    _ => save_connection_state(CONN_STATE_DISCONNECTED, state_file)
                };
                utils::result_or_log(&mut logger, Severity::INFO,
                    "unable to save current connection state", res);
                let t = get_next_retry_timeout(err,
                    last_attempt,
                    unauthorized_timeout);
                if t > 0.5 {
                    log_info!(logger, "retrying in {:.3} seconds", t);
                    thread::sleep(Duration::from_millis((t * 1000.0) as u64));
                }
                cur_addr = addr.to_string();
            }
        }
        verify_data.lock()
            .unwrap()
            .set_cur_address(&cur_addr);
    }
}
fn arrow_thread < L : Logger + Clone , Q : Sender < Command > + Clone > ( mut logger : L , state_file : & str , mut ssl_context : SslContext , cmd_sender : Q , addr : & str , arrow_mac : & MacAddr , app_context : Shared < AppContext > ) { let diagnostic_mode = app_context . lock ( ) . unwrap ( ) . diagnostic_mode ; let t = time :: precise_time_s ( ) ; let mut unauthorized_timeout = t + 1200.0 ; let mut cur_addr = addr . to_string ( ) ; let mut last_attempt ; let verify_data = Shared :: new ( VerifyCallbackData :: new ( & cur_addr ) ) ; ssl_context . set_verify_with_data ( SSL_VERIFY_PEER , openssl_verify_callback , verify_data . clone ( ) ) ; loop { log_info ! ( logger " " cur_addr ) ; let lgr = logger . clone ( ) ; let ctx = app_context . clone ( ) ; last_attempt = time :: precise_time_s ( ) ; utils :: result_or_log ( & mut logger , Severity :: INFO , " " , save_connection_state ( CONN_STATE_CONNECTED , state_file ) ) ; let res = connect ( lgr , & ssl_context , cmd_sender . clone ( ) , & cur_addr , arrow_mac , ctx ) ; unauthorized_timeout = get_unauthorized_timeout ( & res , last_attempt , unauthorized_timeout ) ; if diagnostic_mode { diagnose_connection_result ( & res ) ; } match res { Ok ( addr ) => cur_addr = addr , Err ( err ) => { log_warn ! ( logger " " err description ( ) ) ; let res = match err . kind ( ) { ErrorKind :: Unauthorized => save_connection_state ( CONN_STATE_UNAUTHORIZED , state_file ) , _ => save_connection_state ( CONN_STATE_DISCONNECTED , state_file ) } ; utils :: result_or_log ( & mut logger , Severity :: INFO , " " , res ) ; let t = get_next_retry_timeout ( err , last_attempt , unauthorized_timeout ) ; if t > 0.5 { log_info ! ( logger " " t ) ; thread :: sleep ( Duration :: from_millis ( ( t * 1000.0 ) as u64 ) ) ; } cur_addr = addr . to_string ( ) ; } } verify_data . lock ( ) . unwrap ( ) . set_cur_address ( & cur_addr ) ; } }
Arrow Client main thread.
Arrow Client main thread .
logger
L
state_file
&str
ssl_context
SslContext
cmd_sender
Q
addr
&str
arrow_mac
&MacAddr
app_context
Shared<AppContext>