Skip to content

Commit 2d8e767

Browse files
committed
feat(quic): disable datagram for now
- QUIC example connects to broker.emqx.io - Disable datagram by default - Support static linking
1 parent d7515fb commit 2d8e767

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ rustls-native-certs = { version = "0.7", optional = true }
3333
rustls-pki-types = { version = "1", optional = true }
3434

3535
[features]
36-
default = ["strict-protocol-compliance", "tls"]
36+
default = ["strict-protocol-compliance"]
3737
# TLS/SSL transport support
3838
tls = ["dep:tokio-native-tls", "dep:native-tls"]
3939
# QUIC transport support
@@ -44,3 +44,8 @@ strict-protocol-compliance = []
4444
protocol-testing = []
4545

4646

47+
48+
# Force static linking of the C runtime
49+
[profile.release.build-override]
50+
[target.aarch64-unknown-linux-musl]
51+
rustflags = ["-C", "target-feature=+crt-static"]

examples/tokio_async_mqtt_quic_example.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
145145

146146
// Configure MQTT client options with quic:// scheme
147147
let mqtt_options = MqttClientOptions::builder()
148-
.peer("quic://192.168.64.17:14567") // Use quic:// scheme
148+
.peer("quic://broker.emqx.io:14567") // Use quic:// scheme
149149
.client_id("tokio_quic_example_client")
150150
.keep_alive(60)
151151
.clean_start(true)
@@ -160,6 +160,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
160160
// QUIC-specific configuration
161161
.quic_insecure_skip_verify(true) // ⚠️ For testing only! Use proper certs in production
162162
.quic_enable_0rtt(false) // Disable 0-RTT for security
163+
.quic_datagram_receive_buffer_size(0) // disable datagram
163164
// For production with custom CA:
164165
// let ca_pem = std::fs::read_to_string("ca.pem").unwrap();
165166
// .quic_custom_root_ca_pem(ca_pem)

src/mqtt_client/tokio_async_client.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,10 @@ pub struct TokioAsyncClientConfig {
10611061
/// Only used when connecting via quic:// URLs (requires `quic` feature)
10621062
#[cfg(feature = "quic")]
10631063
pub quic_client_key_pem: Option<String>,
1064+
/// QUIC transport: Datagram receive buffer size in bytes (0 = disable datagrams)
1065+
/// Only used when connecting via quic:// URLs (requires `quic` feature)
1066+
#[cfg(feature = "quic")]
1067+
pub quic_datagram_receive_buffer_size: usize,
10641068
}
10651069

10661070
impl Default for TokioAsyncClientConfig {
@@ -1095,6 +1099,8 @@ impl Default for TokioAsyncClientConfig {
10951099
quic_client_cert_pem: None, // No client cert by default
10961100
#[cfg(feature = "quic")]
10971101
quic_client_key_pem: None, // No client key by default
1102+
#[cfg(feature = "quic")]
1103+
quic_datagram_receive_buffer_size: 0, // Disable datagram
10981104
}
10991105
}
11001106
}
@@ -1557,6 +1563,12 @@ impl ConfigBuilder {
15571563
self.config.quic_client_key_pem = Some(pem);
15581564
self
15591565
}
1566+
1567+
#[cfg(feature = "quic")]
1568+
pub fn quic_datagram_receive_buffer_size(mut self, size: usize) -> Self {
1569+
self.config.quic_datagram_receive_buffer_size = size;
1570+
self
1571+
}
15601572
}
15611573

15621574
impl Default for ConfigBuilder {
@@ -3002,6 +3014,11 @@ impl TokioClientWorker {
30023014
})?;
30033015
}
30043016

3017+
if &self.config.quic_datagram_receive_buffer_size > &0 {
3018+
builder = builder.datagram_receive_buffer_size(
3019+
self.config.quic_datagram_receive_buffer_size,
3020+
);
3021+
}
30053022
let cfg = builder.build();
30063023

30073024
let transport = QuicTransport::connect_with_config(addr, cfg)

src/mqtt_client/transport/quic.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ mod imp {
8989
pub client_private_key: Option<Vec<u8>>,
9090
/// ⚠️ DANGEROUS: Skip TLS certificate verification (for testing only!)
9191
pub insecure_skip_verify: bool,
92+
pub datagram_receive_buffer_size: usize,
9293
}
9394

9495
/// Builder for `QuicConfig` to simplify ergonomic construction.
@@ -99,6 +100,7 @@ mod imp {
99100
client_cert_chain: Option<Vec<Vec<u8>>>,
100101
client_private_key: Option<Vec<u8>>,
101102
insecure_skip_verify: bool,
103+
datagram_receive_buffer_size: usize,
102104
}
103105

104106
impl QuicConfigBuilder {
@@ -210,6 +212,11 @@ mod imp {
210212
Ok(self)
211213
}
212214

215+
pub fn datagram_receive_buffer_size(mut self, size: usize) -> Self {
216+
self.datagram_receive_buffer_size = size;
217+
self
218+
}
219+
213220
/// Provide a client private key for mutual TLS (DER-encoded bytes)
214221
pub fn client_private_key(mut self, key: Vec<u8>) -> Self {
215222
self.client_private_key = Some(key);
@@ -273,6 +280,7 @@ mod imp {
273280
client_cert_chain: self.client_cert_chain,
274281
client_private_key: self.client_private_key,
275282
insecure_skip_verify: self.insecure_skip_verify,
283+
datagram_receive_buffer_size: self.datagram_receive_buffer_size,
276284
}
277285
}
278286
}
@@ -287,6 +295,7 @@ mod imp {
287295
client_cert_chain: None,
288296
client_private_key: None,
289297
insecure_skip_verify: false,
298+
datagram_receive_buffer_size: 0,
290299
}
291300
}
292301
}
@@ -418,7 +427,10 @@ mod imp {
418427
}
419428
};
420429

421-
let quinn_crypto = ClientConfig::new(Arc::new(quic_client_cfg));
430+
let mut quinn_crypto = ClientConfig::new(Arc::new(quic_client_cfg));
431+
let mut trpt_cfg = quinn::TransportConfig::default();
432+
trpt_cfg.datagram_receive_buffer_size(Some(cfg.datagram_receive_buffer_size));
433+
quinn_crypto.transport_config(Arc::new(trpt_cfg));
422434

423435
// Create an endpoint bound to an ephemeral UDP port
424436
let mut endpoint = Endpoint::client("0.0.0.0:0".parse().unwrap()).map_err(|e| {

0 commit comments

Comments
 (0)