Skip to content

Commit 8a042d4

Browse files
committed
feat: merge with TcpTls
2 parents e2a2d22 + 3e280aa commit 8a042d4

File tree

23 files changed

+1089
-20
lines changed

23 files changed

+1089
-20
lines changed

Cargo.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ msg-sim = { path = "./msg-sim" }
4545
async-trait = "0.1"
4646
tokio = { version = "1", features = ["full"] }
4747
tokio-util = { version = "0.7", features = ["codec"] }
48-
futures = "0.3"
4948
tokio-stream = { version = "0.1", features = ["sync"] }
49+
tokio-openssl = { version = "0.6" }
50+
futures = "0.3"
5051
parking_lot = "0.12"
5152

5253
# general
@@ -56,10 +57,19 @@ tracing = "0.1"
5657
rustc-hash = "1"
5758
rand = "0.8"
5859
libc = "0.2"
60+
derive_more = { version = "2.0.1", features = [
61+
"from",
62+
"into",
63+
"deref",
64+
"deref_mut",
65+
] }
5966

6067
# networking
6168
quinn = "0.11.9"
6269
rcgen = "0.14"
70+
# (rustls needs to be the same version as the one used by quinn)
71+
rustls = { version = "0.21", features = ["quic", "dangerous_configuration"] }
72+
openssl = { version = "0.10" }
6373

6474
# benchmarking & profiling
6575
criterion = { version = "0.5", features = ["async_tokio"] }

msg-common/src/lib.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
55
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
66

7-
use std::time::SystemTime;
7+
use std::{
8+
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
9+
time::SystemTime,
10+
};
811

912
use futures::future::BoxFuture;
1013

@@ -33,3 +36,47 @@ pub mod constants {
3336
pub const MiB: u32 = 1024 * KiB;
3437
pub const GiB: u32 = 1024 * MiB;
3538
}
39+
40+
/// Extension trait for `SocketAddr`.
41+
pub trait SocketAddrExt: Sized {
42+
/// Returns the unspecified IPv4 socket address, bound to port 0.
43+
fn unspecified_v4() -> Self;
44+
45+
/// Returns the unspecified IPv6 socket address, bound to port 0.
46+
fn unspecified_v6() -> Self;
47+
48+
/// Returns the unspecified socket address of the same family as `other`, bound to port 0.
49+
fn as_unspecified(&self) -> Self;
50+
}
51+
52+
impl SocketAddrExt for SocketAddr {
53+
fn unspecified_v4() -> Self {
54+
Self::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0))
55+
}
56+
57+
fn unspecified_v6() -> Self {
58+
Self::V6(SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 0, 0, 0))
59+
}
60+
61+
fn as_unspecified(&self) -> Self {
62+
match self {
63+
Self::V4(_) => Self::unspecified_v4(),
64+
Self::V6(_) => Self::unspecified_v6(),
65+
}
66+
}
67+
}
68+
69+
/// Extension trait for IP addresses.
70+
pub trait IpAddrExt: Sized {
71+
/// Returns the localhost address of the same family as `other`.
72+
fn as_localhost(&self) -> Self;
73+
}
74+
75+
impl IpAddrExt for IpAddr {
76+
fn as_localhost(&self) -> Self {
77+
match self {
78+
Self::V4(_) => Self::V4(Ipv4Addr::LOCALHOST),
79+
Self::V6(_) => Self::V6(Ipv6Addr::LOCALHOST),
80+
}
81+
}
82+
}

msg-socket/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ parking_lot.workspace = true
2828

2929
[dev-dependencies]
3030
rand.workspace = true
31-
msg-transport = { workspace = true, features = ["quic"] }
31+
msg-transport = { workspace = true, features = ["quic", "tcp-tls"] }
32+
openssl.workspace = true
3233

3334
msg-sim.workspace = true
3435

msg-socket/src/sub/socket.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
collections::HashSet,
3-
net::{IpAddr, Ipv4Addr, SocketAddr},
3+
net::SocketAddr,
44
path::PathBuf,
55
pin::Pin,
66
sync::Arc,
@@ -14,7 +14,7 @@ use tokio::{
1414
sync::mpsc,
1515
};
1616

17-
use msg_common::JoinMap;
17+
use msg_common::{IpAddrExt, JoinMap};
1818
use msg_transport::{Address, Transport};
1919

2020
// ADDED: Import the specific SubStats struct for the API
@@ -61,8 +61,7 @@ where
6161
// Some transport implementations (e.g. Quinn) can't dial an unspecified
6262
// IP address, so replace it with localhost.
6363
if endpoint.ip().is_unspecified() {
64-
// TODO: support IPv6
65-
endpoint.set_ip(IpAddr::V4(Ipv4Addr::LOCALHOST));
64+
endpoint.set_ip(endpoint.ip().as_localhost());
6665
}
6766

6867
self.connect_inner(endpoint).await
@@ -76,8 +75,7 @@ where
7675
// Some transport implementations (e.g. Quinn) can't dial an unspecified
7776
// IP address, so replace it with localhost.
7877
if endpoint.ip().is_unspecified() {
79-
// TODO: support IPv6
80-
endpoint.set_ip(IpAddr::V4(Ipv4Addr::LOCALHOST));
78+
endpoint.set_ip(endpoint.ip().as_localhost());
8179
}
8280

8381
self.try_connect_inner(endpoint)

0 commit comments

Comments
 (0)