pub async fn ping(
        &self,
    ) -> Result<(Option<TlsPayload>, Option<String>), Box<dyn std::error::Error>> {
        // structure JSON request using configuration
        let payload = {
            // find the tls_created_at field from the last ping info
            let last_ping = self.ping_info.load();
            let tls_created_at = last_ping
                .as_ref()
                .as_ref()
                .map(|x| x.tls.created_at.clone());

            PingRequest {
                secret: Secret::clone(&self.config.client_secret),
                disk_space: self.config.cache_size_mebibytes as u64 * 1024 * 1024,
                port: self.config.external_port.unwrap_or(self.config.port),
                network_speed: self
                    .config
                    .external_max_speed
                    .map(|x| x as u64 * 1000 / 8)
                    .unwrap_or(0),
                build_version: c::SPEC,
                ip_address: self.config.external_ip.clone(),
                tls_created_at,
            }
        };
        log::debug!("sending ping payload to server: {:?}", &payload);

        // format URL and make the request to the server (handling any errors that happen in the
        // process)
        let url = url::Url::options()
            .base_url(Some(&BASE_URL))
            .parse("/ping")?;
        let res = self
            .client
            .post(url)
            .json(&payload)
            .header("Content-Type", "application/json")
            .send()
            .await?;

        // obtain the body of the request
        let client_setup = match res.status() {
            // response was OK, parse JSON body
            reqwest::StatusCode::OK => res.json::<PingResponse>().await?,

            // error handling
            reqwest::StatusCode::UNAUTHORIZED => return Err(Box::new(BackendError::InvalidSecret)),
            status => {
                return Err(Box::new(BackendError::UnexpectedResponse(
                    status,
                    res.text().await.unwrap_or_else(|_| "NO BODY".to_string()),
                )))
            }
        };
        log::info!("received ping response from server: {:?}", &client_setup);

        // log some warning about compromised/paused
        if client_setup.paused {
            log::warn!("according to backend, your client is paused!");
        }
        if client_setup.compromised {
            log::warn!("according to backend, your client is compromised!");
        }

        // update internal structures based on response
        let new_token_key = self.update_from_response(&client_setup);

        // (crt, crt_new, token_key)
        Ok((client_setup.tls, new_token_key))
    }
/// Pings the backend with a created payload and returns a TLS payload (if it's new) and a
/// token key (if it's new)
///
/// This function will handle all mutability by using interior mutability that is thread safe
/// (using [`RwLock`]s). This is the only function in the entire implementation that will lock
/// the `RwLock`s.
///
/// # Panic
///
/// This function may panic if any of the `RwLock`s are considered poisoned, as this function
/// will unwrap all `RwLock`s that it is writing to or reading from
Pings the backend with a created payload and returns a TLS payload (if it's new) and a
token key (if it's new)

This function will handle all mutability by using interior mutability that is thread safe
(using [`RwLock`]s). This is the only function in the entire implementation that will lock
the `RwLock`s.
Pings the backend with a created payload and returns a TLS payload ( if it ' s new ) and a token key ( if it ' s new ) This function will handle all mutability by using interior mutability that is thread safe ( using [ ` RwLock ` ] s ) . This is the only function in the entire implementation that will lock the ` RwLock ` s .
pub async fn ping(
        &self,
    ) -> Result<(Option<TlsPayload>, Option<String>), Box<dyn std::error::Error>> {
        // structure JSON request using configuration
        let payload = {
            // find the tls_created_at field from the last ping info
            let last_ping = self.ping_info.load();
            let tls_created_at = last_ping
                .as_ref()
                .as_ref()
                .map(|x| x.tls.created_at.clone());
            PingRequest {
                secret: Secret::clone(&self.config.client_secret),
                disk_space: self.config.cache_size_mebibytes as u64 * 1024 * 1024,
                port: self.config.external_port.unwrap_or(self.config.port),
                network_speed: self
                    .config
                    .external_max_speed
                    .map(|x| x as u64 * 1000 / 8)
                    .unwrap_or(0),
                build_version: c::SPEC,
                ip_address: self.config.external_ip.clone(),
                tls_created_at,
            }
        };
        log::debug!("sending ping payload to server: {:?}", &payload);
        // format URL and make the request to the server (handling any errors that happen in the
        // process)
        let url = url::Url::options()
            .base_url(Some(&BASE_URL))
            .parse("/ping")?;
        let res = self
            .client
            .post(url)
            .json(&payload)
            .header("Content-Type", "application/json")
            .send()
            .await?;
        // obtain the body of the request
        let client_setup = match res.status() {
            // response was OK, parse JSON body
            reqwest::StatusCode::OK => res.json::<PingResponse>().await?,
            // error handling
            reqwest::StatusCode::UNAUTHORIZED => return Err(Box::new(BackendError::InvalidSecret)),
            status => {
                return Err(Box::new(BackendError::UnexpectedResponse(
                    status,
                    res.text().await.unwrap_or_else(|_| "NO BODY".to_string()),
                )))
            }
        };
        log::info!("received ping response from server: {:?}", &client_setup);
        // log some warning about compromised/paused
        if client_setup.paused {
            log::warn!("according to backend, your client is paused!");
        }
        if client_setup.compromised {
            log::warn!("according to backend, your client is compromised!");
        }
        // update internal structures based on response
        let new_token_key = self.update_from_response(&client_setup);
        // (crt, crt_new, token_key)
        Ok((client_setup.tls, new_token_key))
    }
pub async fn ping ( & self , ) -> Result < ( Option < TlsPayload > , Option < String > ) , Box < dyn std :: error :: Error > > { // structure JSON request using configuration let payload = { // find the tls_created_at field from the last ping info let last_ping = self . ping_info . load ( ) ; let tls_created_at = last_ping . as_ref ( ) . as_ref ( ) . map ( | x | x . tls . created_at . clone ( ) ) ; PingRequest { secret : Secret :: clone ( & self . config . client_secret ) , disk_space : self . config . cache_size_mebibytes as u64 * 1024 * 1024 , port : self . config . external_port . unwrap_or ( self . config . port ) , network_speed : self . config . external_max_speed . map ( | x | x as u64 * 1000 / 8 ) . unwrap_or ( 0 ) , build_version : c :: SPEC , ip_address : self . config . external_ip . clone ( ) , tls_created_at , } } ; log :: debug ! ( " " payload ) ; // format URL and make the request to the server (handling any errors that happen in the // process) let url = url :: Url :: options ( ) . base_url ( Some ( & BASE_URL ) ) . parse ( " " ) ? ; let res = self . client . post ( url ) . json ( & payload ) . header ( " " , " " ) . send ( ) . await ? ; // obtain the body of the request let client_setup = match res . status ( ) { // response was OK, parse JSON body reqwest :: StatusCode :: OK => res . json :: < PingResponse > ( ) . await ? , // error handling reqwest :: StatusCode :: UNAUTHORIZED => return Err ( Box :: new ( BackendError :: InvalidSecret ) ) , status => { return Err ( Box :: new ( BackendError :: UnexpectedResponse ( status , res . text ( ) . await . unwrap_or_else ( | _ | " " . to_string ( ) ) , ) ) ) } } ; log :: info ! ( " " client_setup ) ; // log some warning about compromised/paused if client_setup . paused { log :: warn ! ( " " ) ; } if client_setup . compromised { log :: warn ! ( " " ) ; } // update internal structures based on response let new_token_key = self . update_from_response ( & client_setup ) ; // (crt, crt_new, token_key) Ok ( ( client_setup . tls , new_token_key ) ) }
Pings the backend with a created payload and returns a TLS payload (if it's new) and a
token key (if it's new)
Pings the backend with a created payload and returns a TLS payload ( if it ' s new ) and a token key ( if it ' s new )
&self
panic
This function may panic if any of the `RwLock`s are considered poisoned, as this function
will unwrap all `RwLock`s that it is writing to or reading from
This function may panic if any of the ` RwLock ` s are considered poisoned as this function will unwrap all ` RwLock ` s that it is writing to or reading from