Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions libs/gl-client/src/pairing/attestation_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,32 @@ impl<C: TlsConfigProvider + RuneProvider + NodeIdProvider> Client<Unconnected, C

impl<C: TlsConfigProvider + RuneProvider + NodeIdProvider> Client<Connected, C> {
pub async fn get_pairing_data(&self, device_id: &str) -> Result<GetPairingDataResponse> {
Ok(self
.inner
.0
.clone()
.get_pairing_data(GetPairingDataRequest {
device_id: device_id.to_string(),
})
.await?
.into_inner())
use tokio::time::{sleep, Duration, Instant};

// Retry for up to 10 seconds to handle the race condition where the
// attestation device receives the QR code before the new device's
// PairDevice request has been processed by the server.
let deadline = Instant::now() + Duration::from_secs(10);

loop {
let result = self
.inner
.0
.clone()
.get_pairing_data(GetPairingDataRequest {
device_id: device_id.to_string(),
})
.await;

match result {
Ok(response) => return Ok(response.into_inner()),
Err(_) if Instant::now() < deadline => {
sleep(Duration::from_millis(100)).await;
continue;
}
Err(e) => return Err(e.into()),
}
}
}

pub async fn approve_pairing(
Expand Down
Loading