Skip to content

Commit 37dab7a

Browse files
mess with quic
1 parent a0d5a8c commit 37dab7a

File tree

13 files changed

+651
-199
lines changed

13 files changed

+651
-199
lines changed

Cargo.lock

Lines changed: 17 additions & 1 deletion
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
@@ -188,6 +188,7 @@ apollo_proc_macros = { path = "crates/apollo_proc_macros", version = "0.0.0" }
188188
apollo_proc_macros_tests.path = "crates/apollo_proc_macros_tests"
189189
apollo_propeller.path = "crates/apollo_propeller"
190190
apollo_protobuf.path = "crates/apollo_protobuf"
191+
apollo_quic_datagrams = { path = "crates/apollo_quic_datagrams", features = ["tokio"] }
191192
apollo_reverts.path = "crates/apollo_reverts"
192193
apollo_rpc.path = "crates/apollo_rpc"
193194
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: 54 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,7 @@ fn send_now<Item>(
796796
}
797797
}
798798

799-
800-
use std::fs;
801-
use std::io;
799+
use std::{fs, io};
802800

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

@@ -865,58 +873,44 @@ 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.latency_metrics.take()),
908-
metrics.as_mut()
909-
.and_then(|m| m.propeller_metrics.take()),
910-
key.clone(),
911-
bootstrap_peer_multiaddr,
912-
chain_id,
913-
node_version,
914-
prune_dead_connections_ping_interval,
915-
prune_dead_connections_ping_timeout,
916-
))
917-
.expect("Error while building the swarm")
918-
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(idle_connection_timeout))
919-
.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.latency_metrics.take()),
902+
metrics.as_mut().and_then(|m| m.propeller_metrics.take()),
903+
key.clone(),
904+
bootstrap_peer_multiaddr,
905+
chain_id,
906+
node_version,
907+
prune_dead_connections_ping_interval,
908+
prune_dead_connections_ping_timeout,
909+
)
910+
})
911+
.expect("Error while building the swarm")
912+
.with_swarm_config(|cfg| cfg.with_idle_connection_timeout(idle_connection_timeout))
913+
.build();
920914

921915
let _ = swarm.listen_on(listen_address.clone());
922916

crates/apollo_propeller/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tokio = { workspace = true, features = ["rt", "sync"] }
3232
tracing.workspace = true
3333

3434
[dev-dependencies]
35+
apollo_quic_datagrams.workspace = true
3536
libp2p = { workspace = true, features = ["macros", "plaintext", "quic", "tcp", "tokio", "yamux"] }
3637
libp2p-swarm-test.workspace = true
3738
quickcheck.workspace = true

crates/apollo_propeller/tests/e2e_handler.rs

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

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

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

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

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)