Skip to content

Commit b58af9c

Browse files
mess with quic
1 parent 426723a commit b58af9c

File tree

13 files changed

+647
-194
lines changed

13 files changed

+647
-194
lines changed

Cargo.lock

Lines changed: 16 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ apollo_proc_macros = { path = "crates/apollo_proc_macros", version = "0.0.0" }
183183
apollo_proc_macros_tests.path = "crates/apollo_proc_macros_tests"
184184
apollo_propeller.path = "crates/apollo_propeller"
185185
apollo_protobuf.path = "crates/apollo_protobuf"
186+
apollo_quic_datagrams = { path = "crates/apollo_quic_datagrams", features = ["tokio"] }
186187
apollo_reverts.path = "crates/apollo_reverts"
187188
apollo_rpc.path = "crates/apollo_rpc"
188189
apollo_rpc_execution.path = "crates/apollo_rpc_execution"

crates/apollo_network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ apollo_config.workspace = true
1313
apollo_metrics.workspace = true
1414
apollo_network_types.workspace = true
1515
apollo_propeller.workspace = true
16+
apollo_quic_datagrams = { path = "../apollo_quic_datagrams", features = ["tokio"] }
1617
async-stream.workspace = true
1718
async-trait.workspace = true
1819
bytes.workspace = true

crates/apollo_network/src/network_manager/mod.rs

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -798,9 +798,7 @@ fn send_now<Item>(
798798
}
799799
}
800800

801-
802-
use std::fs;
803-
use std::io;
801+
use std::{fs, io};
804802

805803
fn read_sysctl_value(path: &str) -> io::Result<u64> {
806804
// Read the file's content into a string
@@ -822,11 +820,21 @@ fn read_sysctl_value(path: &str) -> io::Result<u64> {
822820
fn check_udp_buffer_size(desired_buffer_size: u32) {
823821
let rmem_max = read_sysctl_value("/proc/sys/net/core/rmem_max").unwrap();
824822
let wmem_max = read_sysctl_value("/proc/sys/net/core/wmem_max").unwrap();
825-
assert!(rmem_max >= desired_buffer_size.into(), "rmem_max is {rmem_max} less than {desired_buffer_size}");
826-
assert!(wmem_max >= desired_buffer_size.into(), "wmem_max is {wmem_max} less than {desired_buffer_size}");
827-
828-
if rmem_max < desired_buffer_size.into() || wmem_max < desired_buffer_size.into() {
829-
panic!("UDP buffer size is less than desired buffer size. rmem_max: {rmem_max}, wmem_max: {wmem_max}, desired_buffer_size: {desired_buffer_size}. This runs the risk of packet loss in high latency lines");
823+
assert!(
824+
rmem_max >= desired_buffer_size.into(),
825+
"rmem_max is {rmem_max} less than {desired_buffer_size}"
826+
);
827+
assert!(
828+
wmem_max >= desired_buffer_size.into(),
829+
"wmem_max is {wmem_max} less than {desired_buffer_size}"
830+
);
831+
832+
if rmem_max < desired_buffer_size.into() || wmem_max < desired_buffer_size.into() {
833+
panic!(
834+
"UDP buffer size is less than desired buffer size. rmem_max: {rmem_max}, wmem_max: \
835+
{wmem_max}, desired_buffer_size: {desired_buffer_size}. This runs the risk of packet \
836+
loss in high latency lines"
837+
);
830838
}
831839
}
832840

@@ -865,54 +873,41 @@ impl NetworkManager {
865873
const BYTES_IN_THE_AIR: u32 = 1 << 30;
866874
// check_udp_buffer_size(BYTES_IN_THE_AIR);
867875

868-
let mut swarm = SwarmBuilder::with_existing_identity(key_pair)
869-
.with_tokio()
870-
// TODO(AndrewL): .with_quic()
871-
.with_quic_config( |mut quic_config| {
872-
// HIGH THROUGHPUT, HIGH LATENCY OPTIMIZATION:
873-
// Maximize data flow and minimize waiting for acknowledgements
874-
875-
// Set maximum data per stream and connection to allow unlimited flow
876-
quic_config.send_window = Some(BYTES_IN_THE_AIR.into());
877-
quic_config.max_stream_data = BYTES_IN_THE_AIR;
878-
quic_config.max_connection_data = BYTES_IN_THE_AIR;
879-
quic_config.congestion_controller = Some(libp2p::quic::CongestionController::Bbr {
880-
initial_window: Some(BYTES_IN_THE_AIR.into())
881-
});
882-
883-
// // Set handshake timeout to allow time for DNS resolution and connection establishment
884-
// quic_config.handshake_timeout = std::time::Duration::from_secs(10);
885-
886-
// // Reduce idle timeout to prevent connections from lingering
887-
// // but still allow for high-latency scenarios
888-
// quic_config.max_idle_timeout = 30000; // 30 seconds instead of 3000
889-
890-
// // Set aggressive keep-alive to maintain connections over high-latency links
891-
// quic_config.keep_alive_interval = std::time::Duration::from_secs(10);
892-
893-
// // Allow maximum concurrent streams for parallel data transmission
894-
// quic_config.max_concurrent_stream_limit = u32::MAX;
895-
896-
quic_config
897-
})
898-
.with_dns()
899-
.expect("Error building DNS transport")
900-
.with_behaviour(|key| mixed_behaviour::MixedBehaviour::new(
901-
sqmr::Config { session_timeout },
902-
discovery_config,
903-
peer_manager_config,
904-
metrics.as_mut()
905-
.and_then(|m| m.event_metrics.take()),
906-
metrics.as_mut()
907-
.and_then(|m| m.propeller_metrics.take()),
908-
key.clone(),
909-
bootstrap_peer_multiaddr,
910-
chain_id,
911-
node_version
912-
))
913-
.expect("Error while building the swarm")
914-
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(idle_connection_timeout))
915-
.build();
876+
// Configure custom QUIC transport with apollo_quic_datagrams
877+
// HIGH THROUGHPUT, HIGH LATENCY OPTIMIZATION:
878+
// Maximize data flow and minimize waiting for acknowledgements
879+
let quic_config = apollo_quic_datagrams::Config::new(&key_pair)
880+
.with_send_window(BYTES_IN_THE_AIR as u64)
881+
.with_max_stream_data(BYTES_IN_THE_AIR)
882+
.with_max_connection_data(BYTES_IN_THE_AIR)
883+
.with_congestion_controller(apollo_quic_datagrams::CongestionController::Bbr {
884+
initial_window: Some(BYTES_IN_THE_AIR as u64),
885+
});
886+
887+
let quic_transport = apollo_quic_datagrams::tokio::Transport::new(quic_config);
888+
889+
let mut swarm = SwarmBuilder::with_existing_identity(key_pair.clone())
890+
.with_tokio()
891+
.with_other_transport(|_key| quic_transport)
892+
.expect("Error building QUIC transport")
893+
.with_dns()
894+
.expect("Error building DNS transport")
895+
.with_behaviour(|key| {
896+
mixed_behaviour::MixedBehaviour::new(
897+
sqmr::Config { session_timeout },
898+
discovery_config,
899+
peer_manager_config,
900+
metrics.as_mut().and_then(|m| m.event_metrics.take()),
901+
metrics.as_mut().and_then(|m| m.propeller_metrics.take()),
902+
key.clone(),
903+
bootstrap_peer_multiaddr,
904+
chain_id,
905+
node_version,
906+
)
907+
})
908+
.expect("Error while building the swarm")
909+
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(idle_connection_timeout))
910+
.build();
916911

917912
let _ = swarm.listen_on(listen_address.clone());
918913

crates/apollo_propeller/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ strum_macros.workspace = true
2929
tracing.workspace = true
3030

3131
[dev-dependencies]
32+
apollo_quic_datagrams.workspace = true
3233
libp2p = { workspace = true, features = ["macros", "plaintext", "quic", "tcp", "tokio", "yamux"] }
3334
libp2p-swarm-test.workspace = true
3435
quickcheck.workspace = true

crates/apollo_propeller/tests/e2e_handler.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn create_swarm(
187187

188188
let identity = Keypair::generate_ed25519();
189189

190-
let builder = libp2p::SwarmBuilder::with_existing_identity(identity).with_tokio();
190+
let builder = libp2p::SwarmBuilder::with_existing_identity(identity.clone()).with_tokio();
191191

192192
match transport_type {
193193
TransportType::Memory => builder
@@ -212,16 +212,25 @@ fn create_swarm(
212212
c.with_idle_connection_timeout(Duration::from_secs(3600)) // 1 hour
213213
})
214214
.build(),
215-
TransportType::Quic => builder
216-
.with_quic()
217-
.with_behaviour(|_| HandlerTestBehaviour::new(max_wire_message_size))
218-
.expect("Failed to create behaviour")
219-
.with_swarm_config(|c| {
220-
// Use a much longer idle connection timeout to prevent disconnections during long
221-
// tests
222-
c.with_idle_connection_timeout(Duration::from_secs(3600)) // 1 hour
223-
})
224-
.build(),
215+
TransportType::Quic => {
216+
// Use custom apollo_quic_datagrams implementation
217+
let quic_config = apollo_quic_datagrams::Config::new(&identity);
218+
let quic_transport = apollo_quic_datagrams::tokio::Transport::new(quic_config);
219+
220+
builder
221+
.with_other_transport(|_key| quic_transport)
222+
.expect("Failed to build QUIC transport")
223+
.with_dns()
224+
.expect("Failed to build DNS transport")
225+
.with_behaviour(|_| HandlerTestBehaviour::new(max_wire_message_size))
226+
.expect("Failed to create behaviour")
227+
.with_swarm_config(|c| {
228+
// Use a much longer idle connection timeout to prevent disconnections during
229+
// long tests
230+
c.with_idle_connection_timeout(Duration::from_secs(3600)) // 1 hour
231+
})
232+
.build()
233+
}
225234
}
226235
}
227236

crates/apollo_quic_datagrams/CHANGELOG.md

Lines changed: 0 additions & 118 deletions
This file was deleted.

crates/apollo_quic_datagrams/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ libp2p = { workspace = true, features = [
2626
"yamux",
2727
] }
2828
quinn = { version = "0.11.6", default-features = false, features = ["futures-io", "rustls"] }
29+
quinn-proto = "0.11.13"
2930
rand = { workspace = true }
3031
rustls = { version = "0.23.9", default-features = false }
3132
thiserror = { workspace = true }

0 commit comments

Comments
 (0)