Skip to content

Commit

Permalink
use async resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
eaypek-tfh committed Jan 12, 2025
1 parent 741ed2e commit 1a3aefc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion deploy/stage/smpcv2-1-stage/values-iris-mpc.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
env:
- name: RUST_LOG
value: "info"
value: "debug"

- name: RUST_BACKTRACE
value: "full"
Expand Down
36 changes: 27 additions & 9 deletions iris-mpc/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ use aws_sdk_s3::{config::Builder as S3ConfigBuilder, Client as S3Client};
use aws_sdk_sns::{types::MessageAttributeValue, Client as SNSClient};
use aws_sdk_sqs::{config::Region, Client};
use aws_smithy_experimental::hyper_1_0::{CryptoMode, HyperClientBuilder};
use aws_smithy_runtime_api::client::dns::{DnsFuture, ResolveDns};
use aws_smithy_runtime_api::client::dns::{DnsFuture, ResolveDns, ResolveDnsError};
use axum::{response::IntoResponse, routing::get, Router};
use clap::Parser;
use eyre::{eyre, Context};
use futures::{stream::select_all, StreamExt, TryStreamExt};
use hickory_resolver::{
config::{ResolverConfig, ResolverOpts},
Resolver,
TokioAsyncResolver,
};
use iris_mpc_common::{
config::{Config, Opt},
Expand Down Expand Up @@ -56,7 +56,9 @@ use std::{
backtrace::Backtrace,
collections::{HashMap, HashSet},
fmt::{Debug, Formatter},
mem, panic,
mem,
net::IpAddr,
panic,
sync::{
atomic::{AtomicBool, Ordering},
Arc, LazyLock, Mutex,
Expand Down Expand Up @@ -670,13 +672,13 @@ async fn main() -> eyre::Result<()> {
}

struct StaticResolver {
resolver: Arc<Resolver>,
resolver: Arc<TokioAsyncResolver>,
}

impl StaticResolver {
fn new() -> Self {
let resolver = Resolver::new(ResolverConfig::default(), ResolverOpts::default())
.expect("Failed to create resolver");
let resolver =
TokioAsyncResolver::tokio(ResolverConfig::default(), ResolverOpts::default());
StaticResolver {
resolver: Arc::new(resolver),
}
Expand All @@ -701,9 +703,25 @@ impl Clone for StaticResolver {

impl ResolveDns for StaticResolver {
fn resolve_dns<'a>(&'a self, _name: &'a str) -> DnsFuture<'a> {
let lookup_result = self.resolver.lookup_ip(_name).unwrap();
let ip_addresses = lookup_result.iter().collect();
DnsFuture::ready(Ok(ip_addresses))
let resolver = Arc::clone(&self.resolver);
let hostname = _name.to_string();

// Create the async block that performs DNS resolution
let future = async move {
match resolver.lookup_ip(&hostname).await {
Ok(lookup_result) => {
let ips: Vec<IpAddr> = lookup_result.iter().collect();
Ok(ips)
}
Err(e) => Err(ResolveDnsError::new(format!(
"Failed to resolve {}: {}",
hostname, e
))),
}
};

// Wrap the future into DnsFuture
DnsFuture::new(Box::pin(future))
}
}

Expand Down

0 comments on commit 1a3aefc

Please sign in to comment.