Skip to content

Commit

Permalink
fix linting + mistakes of PR #348
Browse files Browse the repository at this point in the history
- couple of linting issues
- but also the IP/Dns mode wasn't used yet from context

Both are resolved now :)

Thx again to 53R3N17Y for his amazing spirit and work on this one,
he has shown true persistence!

Also close #406

this turns out to be already possible given we allow a connector to be passed
in https://docs.rs/rama/latest/rama/tcp/client/service/struct.TcpConnector.html

this allows one to make their own raw socket2 socket,
turned into a tokio TcpSocket and than finally into
a TcpStream
  • Loading branch information
GlenDC committed Feb 8, 2025
1 parent caf3a0d commit 23e9211
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 20 deletions.
4 changes: 2 additions & 2 deletions rama-net/src/mode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
/// Enum representing the IP modes that can be used by the DNS resolver.
pub enum DnsResolveIpMode {
#[default]
Expand Down Expand Up @@ -30,7 +30,7 @@ impl DnsResolveIpMode {
}
}
///Mode for establishing a connection
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
pub enum ConnectIpMode {
#[default]
Dual,
Expand Down
26 changes: 8 additions & 18 deletions rama-tcp/src/client/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ where
Dns: DnsResolver<Error: Into<BoxError>> + Clone,
Connector: TcpStreamConnector<Error: Into<BoxError> + Send + 'static> + Clone,
{
let ip_mode = ctx.get().copied().unwrap_or_default();
let dns_mode = ctx.get().copied().unwrap_or_default();

let (host, port) = authority.into_parts();
let domain = match host {
Host::Name(domain) => domain,
Host::Address(ip) => {
let mode = ConnectIpMode::Dual;
//check if IP Version is allowed
match (ip, mode) {
match (ip, ip_mode) {
(IpAddr::V4(_), ConnectIpMode::Ipv6) => {
return Err(OpaqueError::from_display("IPv4 address is not allowed"));
}
Expand All @@ -163,10 +165,10 @@ where
ctx,
domain.clone(),
port,
DnsResolveIpMode::Dual, // Use the mode from the overwrite
dns_overwrite.deref().clone(), // Convert DnsOverwrite to a DnsResolver
dns_mode,
dns_overwrite.deref().clone(), // Convert DnsOverwrite to a DnsResolver
connector.clone(),
ConnectIpMode::Dual,
ip_mode,
)
.await
{
Expand All @@ -175,20 +177,10 @@ where
}
}


//... otherwise we'll try to establish a connection,
// with dual-stack parallel connections...

tcp_connect_inner(
ctx,
domain,
port,
DnsResolveIpMode::Dual,
dns,
connector,
ConnectIpMode::Dual,
)
.await
tcp_connect_inner(ctx, domain, port, dns_mode, dns, connector, ip_mode).await
}

async fn tcp_connect_inner<State, Dns, Connector>(
Expand Down Expand Up @@ -224,7 +216,6 @@ where
));
}


if dns_mode.ipv6_supported() {
ctx.spawn(tcp_connect_inner_branch(
dns_mode,
Expand All @@ -250,7 +241,6 @@ where
)))
}


#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
enum IpKind {
Ipv4,
Expand Down

0 comments on commit 23e9211

Please sign in to comment.