Skip to content

Update route stability and sequencing preferences for low latency #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
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
38 changes: 34 additions & 4 deletions src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,41 @@ impl Group {
let keypair = None;

let veilid = self.get_veilid_api();
let mut dht_record: Option<DHTRecordDescriptor> = None;
let mut retries = 6;

let dht_record = self
.routing_context
.open_dht_record(repo_id.clone(), keypair)
.await?;
while retries > 0 {
retries -= 1;
let dht_record_result = self
.routing_context
.open_dht_record(repo_id.clone(), keypair.clone())
.await;

match dht_record_result {
Ok(record) => {
dht_record = Some(record);
break;
}
Err(e) => {
eprintln!(
"Failed to open DHT record: {}. Retries left: {}",
e, retries
);
if retries == 0 {
return Err(anyhow!(
"Unable to open DHT record, reached max retries: {}",
e
));
}
}
}

// Add a delay before retrying (wit exponential backoff)
tokio::time::sleep(std::time::Duration::from_millis(100 * (7 - retries) as u64)).await;
}

// Ensure that `dht_record` is set before proceeding
let dht_record = dht_record.ok_or_else(|| anyhow!("DHT record retrieval failed"))?;

let repo = Repo {
dht_record,
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ mod tests {
let (route_id, route_id_blob) = veilid_api
.new_custom_private_route(
&VALID_CRYPTO_KINDS,
veilid_core::Stability::Reliable,
veilid_core::Sequencing::PreferOrdered,
veilid_core::Stability::LowLatency,
veilid_core::Sequencing::NoPreference,
)
.await
.expect("Failed to create route");
Expand Down Expand Up @@ -882,7 +882,7 @@ mod tests {
sleep(Duration::from_secs(2)).await;

// Download hash from peers
let mut retries = 5;
let mut retries = 10;
while retries > 0 {
if group2.download_hash_from_peers(&file_hash).await.is_ok() {
println!("Download success!");
Expand Down
Loading