-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
added wrapper type and todos #348
base: main
Are you sure you want to change the base?
Changes from 1 commit
2c05499
ea1b51f
9e6e101
f802b0f
edd1b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,10 +61,7 @@ impl<C>ConnectIpMode<C>{ | |
} | ||
} | ||
|
||
/* | ||
TODO - Using the wrapper types | ||
in the tcp_connect fn, update the dns type to use the DnsResolveIpMode | ||
*/ | ||
|
||
|
||
/// Trait used internally by [`tcp_connect`] and the `TcpConnector` | ||
/// to actually establish the [`TcpStream`.] | ||
|
@@ -197,8 +194,8 @@ async fn tcp_connect_inner<State, Dns, Connector>( | |
ctx: &Context<State>, | ||
domain: Domain, | ||
port: u16, | ||
dns: Dns, | ||
connector: Connector, | ||
dns: DnsResolveIpMode<Dns>, | ||
connector: ConnectIpMode<Connector>, | ||
) -> Result<(TcpStream, SocketAddr), OpaqueError> | ||
where | ||
State: Clone + Send + Sync + 'static, | ||
|
@@ -210,37 +207,41 @@ where | |
let connected = Arc::new(AtomicBool::new(false)); | ||
let sem = Arc::new(Semaphore::new(3)); | ||
|
||
// IPv6 | ||
let ipv6_tx = tx.clone(); | ||
let ipv6_domain = domain.clone(); | ||
let ipv6_connected = connected.clone(); | ||
let ipv6_sem = sem.clone(); | ||
ctx.spawn(tcp_connect_inner_branch( | ||
dns.clone(), | ||
connector.clone(), | ||
IpKind::Ipv6, | ||
ipv6_domain, | ||
port, | ||
ipv6_tx, | ||
ipv6_connected, | ||
ipv6_sem, | ||
)); | ||
|
||
// IPv4 | ||
let ipv4_tx = tx; | ||
let ipv4_domain = domain.clone(); | ||
let ipv4_connected = connected.clone(); | ||
let ipv4_sem = sem; | ||
ctx.spawn(tcp_connect_inner_branch( | ||
dns, | ||
connector, | ||
IpKind::Ipv4, | ||
ipv4_domain, | ||
port, | ||
ipv4_tx, | ||
ipv4_connected, | ||
ipv4_sem, | ||
)); | ||
match dns.mode { | ||
DnsResolveIpMode::SingleIpV4 | DnsResolveIpMode::DualPreferIpV4 | DnsResovleIpMode::Dual =>{ | ||
//IPV4 | ||
ctx.spawn(tcp_connect_inner_branch( | ||
dns.clone(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can add |
||
connector.clone(), | ||
IpKind::Ipv4, | ||
domain.clone(), | ||
port, | ||
tx.clone(), | ||
connected.clone(), | ||
sem.clone(), | ||
)); | ||
} | ||
_ => {} | ||
|
||
} | ||
|
||
match dns.mode { | ||
DnsResolveIpMode::SingleIpV6 | DnsResovleIpMode::Dual =>{ | ||
//IPV6 | ||
ctx.spawn(tcp_connect_inner_branch( | ||
dns.clone(), | ||
connector.clone(), | ||
IpKind::Ipv6, | ||
domain.clone(), | ||
port, | ||
tx.clone(), | ||
connected.clone(), | ||
sem.clone(), | ||
)); | ||
} | ||
_ => {} | ||
|
||
} | ||
|
||
// wait for the first connection to succeed, | ||
// ignore the rest of the connections (sorry, but not sorry) | ||
|
@@ -274,39 +275,31 @@ async fn tcp_connect_inner_branch<Dns, Connector>( | |
Dns: DnsResolver<Error: Into<BoxError>> + Clone, | ||
Connector: TcpStreamConnector<Error: Into<BoxError> + Send + 'static> + Clone, | ||
{ | ||
/*TODO | ||
modify the match to use dns.ip_mode and match for | ||
SingleIpv4 or DualPreferIpv4 or Dual | ||
*/ | ||
|
||
let ip_it = match ip_kind { | ||
IpKind::Ipv4 => match dns.ipv4_lookup(domain).await { | ||
IpKind::Ipv4 if matches!(dns.mode, DnsResolveIpMode::Dual |DnsResolveIpMode::SingleIpV4 |DnsResolveIpMode::DualPreferIpV4 ) =>{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to do:
This way we have a clear trace in our logs / spans |
||
match dns.ipv4_lookup(domain).await { | ||
Ok(ips) => Either::A(ips.into_iter().map(IpAddr::V4)), | ||
Err(err) => { | ||
let err = OpaqueError::from_boxed(err.into()); | ||
tracing::trace!(err = %err, "[{ip_kind:?}] failed to resolve domain to IPv4 addresses"); | ||
return; | ||
} | ||
}, | ||
/*TODO | ||
modify the match to use dns.ip_mode and match for | ||
SingleIpv6 or Dual | ||
*/ | ||
IpKind::Ipv6 => match dns.ipv6_lookup(domain).await { | ||
} | ||
}, | ||
IpKind::Ipv6 if matches!(dns.mode, DnsResolveIpMode::Dual |DnsResolveIpMode::SingleIpV6)=> { | ||
match dns.ipv6_lookup(domain).await { | ||
Ok(ips) => Either::B(ips.into_iter().map(IpAddr::V6)), | ||
Err(err) => { | ||
let err = OpaqueError::from_boxed(err.into()); | ||
tracing::trace!(err = ?err, "[{ip_kind:?}] failed to resolve domain to IPv6 addresses"); | ||
return; | ||
} | ||
}, | ||
} | ||
}, | ||
_ => return, | ||
}; | ||
|
||
/* | ||
TODO | ||
Not sure here, we need to get the matched ip type and | ||
use it | ||
*/ | ||
|
||
for (index, ip) in ip_it.enumerate() { | ||
let addr = (ip, port).into(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to provide utility methods to
DnsResolveIpMode
, such as:Is same-same, but easier to have to update such statements only in a single loc.