Enforce outbound policy at each HTTP connection
This commit is contained in:
parent
be651d559c
commit
12c59ee70f
1 changed files with 1397 additions and 4 deletions
25
crates/remora-outbound/src/resolver.rs
Normal file
25
crates/remora-outbound/src/resolver.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
use std::{future::Future, io, net::IpAddr};
|
||||
|
||||
pub trait Resolver: Send + Sync {
|
||||
fn resolve(
|
||||
&self,
|
||||
host: &str,
|
||||
port: u16,
|
||||
) -> impl Future<Output = io::Result<Vec<IpAddr>>> + Send;
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
pub struct SystemResolver;
|
||||
|
||||
impl Resolver for SystemResolver {
|
||||
async fn resolve(&self, host: &str, port: u16) -> io::Result<Vec<IpAddr>> {
|
||||
let addresses = tokio::net::lookup_host((host, port)).await?;
|
||||
let mut unique = Vec::new();
|
||||
for address in addresses {
|
||||
if !unique.contains(&address.ip()) {
|
||||
unique.push(address.ip());
|
||||
}
|
||||
}
|
||||
Ok(unique)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue