pub(super) fn recover_get(result: GetRecordResult) -> Result<Vec<PeerRecord>, ResolveError> {
        let err = match result {
            Err(err) => err,
            Ok(GetRecordOk { records }) if records.is_empty() => {
                unreachable!("It should be GetRecordError::NotFound")
            }
            Ok(GetRecordOk { records }) => return Ok(records),
        };

        #[rustfmt::skip]
        let (found, quorum, reason, key) = match err {
            GetRecordError::QuorumFailed { records, quorum, key, .. } => (records, quorum.get(), ResolveErrorKind::QuorumFailed, key),
            GetRecordError::Timeout { records, quorum, key, .. } => (records, quorum.get(), ResolveErrorKind::Timeout, key),
            GetRecordError::NotFound { key, .. } => (vec![], 0, ResolveErrorKind::NotFound, key)
        };

        // TODO: is 50% a reasonable number?
        // TODO: move to config
        // Recover if found more than 50% of required quorum
        if found.len() * 2 > quorum {
            #[rustfmt::skip]
            log::warn!("DHT.get almost failed, got {} of {} replicas, but it is good enough", found.len(), quorum);
            return Ok(found);
        }

        #[rustfmt::skip]
        let err_msg = format!("Error while resolving key {:?}: DHT.get failed ({}/{} replies): {:?}", key, found.len(), quorum, reason);
        log::warn!("{}", err_msg);

        Err(ResolveError { key, kind: reason })
    }
/// Returns either a non-empty vector of `PeerRecord`, or an error
Returns either a non-empty vector of `PeerRecord`, or an error
Returns either a non - empty vector of ` PeerRecord ` or an error
pub(super) fn recover_get(result: GetRecordResult) -> Result<Vec<PeerRecord>, ResolveError> {
        let err = match result {
            Err(err) => err,
            Ok(GetRecordOk { records }) if records.is_empty() => {
                unreachable!("It should be GetRecordError::NotFound")
            }
            Ok(GetRecordOk { records }) => return Ok(records),
        };
        #[rustfmt::skip]
        let (found, quorum, reason, key) = match err {
            GetRecordError::QuorumFailed { records, quorum, key, .. } => (records, quorum.get(), ResolveErrorKind::QuorumFailed, key),
            GetRecordError::Timeout { records, quorum, key, .. } => (records, quorum.get(), ResolveErrorKind::Timeout, key),
            GetRecordError::NotFound { key, .. } => (vec![], 0, ResolveErrorKind::NotFound, key)
        };
        // TODO: is 50% a reasonable number?
        // TODO: move to config
        // Recover if found more than 50% of required quorum
        if found.len() * 2 > quorum {
            #[rustfmt::skip]
            log::warn!("DHT.get almost failed, got {} of {} replicas, but it is good enough", found.len(), quorum);
            return Ok(found);
        }
        #[rustfmt::skip]
        let err_msg = format!("Error while resolving key {:?}: DHT.get failed ({}/{} replies): {:?}", key, found.len(), quorum, reason);
        log::warn!("{}", err_msg);
        Err(ResolveError { key, kind: reason })
    }
pub ( super ) fn recover_get ( result : GetRecordResult ) -> Result < Vec < PeerRecord > , ResolveError > { let err = match result { Err ( err ) => err , Ok ( GetRecordOk { records } ) if records . is_empty ( ) => { unreachable ! ( " " ) } Ok ( GetRecordOk { records } ) => return Ok ( records ) , } ; # [ rustfmt :: skip ] let ( found , quorum , reason , key ) = match err { GetRecordError :: QuorumFailed { records , quorum , key , .. } => ( records , quorum . get ( ) , ResolveErrorKind :: QuorumFailed , key ) , GetRecordError :: Timeout { records , quorum , key , .. } => ( records , quorum . get ( ) , ResolveErrorKind :: Timeout , key ) , GetRecordError :: NotFound { key , .. } => ( vec ! [ ] , 0 , ResolveErrorKind :: NotFound , key ) } ; // TODO: is 50% a reasonable number? // TODO: move to config // Recover if found more than 50% of required quorum if found . len ( ) * 2 > quorum { # [ rustfmt :: skip ] log :: warn ! ( " " found len ( ) quorum ) ; return Ok ( found ) ; } # [ rustfmt :: skip ] let err_msg = format ! ( " " key found len ( ) quorum reason ) ; log :: warn ! ( " " err_msg ) ; Err ( ResolveError { key , kind : reason } ) }
Returns either a non-empty vector of `PeerRecord`, or an error
Returns either a non - empty vector of ` PeerRecord ` or an error
result
GetRecordResult