Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

Transfers: NewReno congestion control, and settings to measure it (#46)

Thtbee_6e06b9b9904c
diff --git a/Cargo.lock b/Cargo.lock
index b9a2115..50051c6 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2359,6 +2359,7 @@ dependencies = [
"n0-future",
"nectarlink-adb",
"nectarlink-protocol",
+ "noq-proto",
"rand",
"ring",
"rusqlite",
diff --git a/Cargo.toml b/Cargo.toml
index 524ac0d..de83ce3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -46,6 +46,7 @@ dirs = "7"
hostname = "0.4"
hmac = "0.13"
iroh = "1.3"
+noq-proto = { version = "1.3", default-features = false }
iroh-mdns-address-lookup = "0.6"
material-colors = { version = "0.5", default-features = false, features = ["std", "quantize"] }
n0-future = "0.3"
diff --git a/core/nectarlink-core/Cargo.toml b/core/nectarlink-core/Cargo.toml
index 16036d2..9458b73 100644
--- a/core/nectarlink-core/Cargo.toml
+++ b/core/nectarlink-core/Cargo.toml
@@ -12,6 +12,7 @@ repository.workspace = true
nectarlink-adb.workspace = true
nectarlink-protocol.workspace = true
iroh.workspace = true
+noq-proto.workspace = true
iroh-mdns-address-lookup.workspace = true
material-colors.workspace = true
n0-future.workspace = true
diff --git a/core/nectarlink-core/src/config.rs b/core/nectarlink-core/src/config.rs
index d641b94..4d483ac 100644
--- a/core/nectarlink-core/src/config.rs
+++ b/core/nectarlink-core/src/config.rs
@@ -44,6 +44,78 @@ pub struct NodeConfig {
/// ADB server address on a PC (`127.0.0.1:5037`) for automatic USB
/// detection, port forwarding, and USB auto-pairing.
pub adb_server: Option<std::net::SocketAddr>,
+ /// How connections pace bulk data (file transfers): the congestion
+ /// controller and the flow-control windows.
+ pub transport: TransportTuning,
+}
+
+/// The congestion controller for connections.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Congestion {
+ /// Loss-based (RFC 9438), noq's default: grows fast until the network
+ /// drops packets, filling router buffers on the way.
+ Cubic,
+ /// Model-based (BBRv3): sends at the measured bottleneck rate and keeps
+ /// the queue short.
+ Bbr3,
+ /// Loss-based (RFC 9002, the QUIC specification's own), with gentler
+ /// growth than Cubic. The default: on a Wi-Fi 6 network it moved files
+ /// as fast as Cubic with about half the added delay for other traffic,
+ /// and without the dropped packets Cubic caused (2026-10-23).
+ NewReno,
+}
+
+/// Transport settings for bulk data. The defaults are what ships; the
+/// environment can override them for measurements on real networks:
+/// `NECTARLINK_CONGESTION` (`cubic`, `bbr3`, `newreno`) and
+/// `NECTARLINK_WINDOW_MB` (the per-stream window; the connection gets twice it).
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct TransportTuning {
+ pub congestion: Congestion,
+ /// Bytes a single stream may have in flight.
+ pub stream_window: u32,
+ /// Bytes all streams of a connection may have in flight together.
+ pub connection_window: u32,
+}
+
+impl Default for TransportTuning {
+ fn default() -> Self {
+ // Room for a file transfer to keep the link busy through Wi-Fi's
+ // latency spikes (the QUIC defaults suit ~100 Mbit/s at 100 ms).
+ TransportTuning {
+ congestion: Congestion::NewReno,
+ stream_window: 16 << 20,
+ connection_window: 32 << 20,
+ }
+ }
+}
+
+impl TransportTuning {
+ /// The defaults, with any `NECTARLINK_CONGESTION` / `NECTARLINK_WINDOW_MB` override.
+ pub fn from_env() -> Self {
+ Self::parse(
+ std::env::var("NECTARLINK_CONGESTION").ok().as_deref(),
+ std::env::var("NECTARLINK_WINDOW_MB").ok().as_deref(),
+ )
+ }
+
+ /// The defaults with the given overrides; unknown values keep the default.
+ pub fn parse(congestion: Option<&str>, window_mb: Option<&str>) -> Self {
+ let mut tuning = TransportTuning::default();
+ match congestion.map(|c| c.trim().to_ascii_lowercase()).as_deref() {
+ Some("cubic") => tuning.congestion = Congestion::Cubic,
+ Some("bbr" | "bbr3") => tuning.congestion = Congestion::Bbr3,
+ Some("newreno" | "reno") => tuning.congestion = Congestion::NewReno,
+ _ => {}
+ }
+ if let Some(mb) =
+ window_mb.and_then(|w| w.trim().parse::<u32>().ok()).filter(|mb| (1..=1024).contains(mb))
+ {
+ tuning.stream_window = mb << 20;
+ tuning.connection_window = (mb << 20).saturating_mul(2);
+ }
+ tuning
+ }
}
impl NodeConfig {
@@ -66,6 +138,7 @@ impl NodeConfig {
localsend_port,
usb_port: None,
adb_server: None,
+ transport: TransportTuning::from_env(),
}
}
}
@@ -83,6 +156,7 @@ impl fmt::Debug for NodeConfig {
.field("localsend_port", &self.localsend_port)
.field("usb_port", &self.usb_port)
.field("adb_server", &self.adb_server)
+ .field("transport", &self.transport)
.field("downloads_dir", &self.downloads_dir)
.finish_non_exhaustive()
}
@@ -481,3 +555,24 @@ pub trait Platform: Send + Sync + 'static {
pub struct NoopPlatform;
impl Platform for NoopPlatform {}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn transport_overrides_parse_and_bad_values_keep_the_defaults() {
+ let default = TransportTuning::default();
+ assert_eq!(TransportTuning::parse(None, None), default);
+ assert_eq!(default.congestion, Congestion::NewReno);
+ assert_eq!(TransportTuning::parse(Some("cubic"), None).congestion, Congestion::Cubic);
+ assert_eq!(TransportTuning::parse(Some(" BBR3 "), None).congestion, Congestion::Bbr3);
+ assert_eq!(TransportTuning::parse(Some("bbr"), None).congestion, Congestion::Bbr3);
+ assert_eq!(TransportTuning::parse(Some("newreno"), None).congestion, Congestion::NewReno);
+ assert_eq!(TransportTuning::parse(Some("vegas"), None), default, "unknown controller");
+ let small = TransportTuning::parse(None, Some("4"));
+ assert_eq!((small.stream_window, small.connection_window), (4 << 20, 8 << 20));
+ assert_eq!(TransportTuning::parse(None, Some("0")), default, "a zero window would stall");
+ assert_eq!(TransportTuning::parse(None, Some("lots")), default);
+ }
+}
diff --git a/core/nectarlink-core/src/lib.rs b/core/nectarlink-core/src/lib.rs
index 0002ecb..a5b5328 100644
--- a/core/nectarlink-core/src/lib.rs
+++ b/core/nectarlink-core/src/lib.rs
@@ -50,7 +50,7 @@ pub use clip_kind::{
pub use clipboard_history::{
ClipboardHistoryEntry, ClipboardItemKind, MAX_CLIPBOARD_AGE_SECS, MAX_CLIPBOARD_HISTORY,
};
-pub use config::{NodeConfig, NoopPlatform, Platform};
+pub use config::{Congestion, NodeConfig, NoopPlatform, Platform, TransportTuning};
pub use deck::{
COMMANDS_TOGGLE as DECK_COMMANDS_TOGGLE, DECK_ACTIONS, DeckAction, DeckConfig, DeckLayout, DeckPage,
DeckPageConfig, DeckPress, DeckState, DeckTile, DeckTileConfig, INPUT_TOGGLE as DECK_INPUT_TOGGLE,
diff --git a/core/nectarlink-core/src/node.rs b/core/nectarlink-core/src/node.rs
index 70fbd39..ffa28de 100644
--- a/core/nectarlink-core/src/node.rs
+++ b/core/nectarlink-core/src/node.rs
@@ -58,9 +58,6 @@ const EVENT_CAPACITY: usize = 2048;
/// instead of after QUIC's default of 30 s.
const KEEP_ALIVE_INTERVAL: Duration = Duration::from_millis(1000);
const IDLE_TIMEOUT: Duration = Duration::from_secs(8);
-/// Flow-control windows: how much may be in flight per stream and in all.
-const STREAM_WINDOW: u32 = 16 * 1024 * 1024;
-const CONNECTION_WINDOW: u32 = 32 * 1024 * 1024;
/// How long opening a stream the PC asked for (its screen, an app window)
/// waits for the connection to come back if it just dropped or was replaced.
const STREAM_RECONNECT_WAIT: Duration = Duration::from_secs(10);
@@ -3726,15 +3723,31 @@ async fn bind_endpoint(
secret: iroh::SecretKey,
ports: Option<Ports>,
) -> Result<Endpoint> {
+ let tuning = config.transport;
+ let controller: std::sync::Arc<dyn iroh::endpoint::ControllerFactory + Send + Sync> = match tuning
+ .congestion
+ {
+ crate::config::Congestion::Cubic => {
+ std::sync::Arc::new(noq_proto::congestion::CubicConfig::default())
+ }
+ crate::config::Congestion::Bbr3 => std::sync::Arc::new(noq_proto::congestion::Bbr3Config::default()),
+ crate::config::Congestion::NewReno => {
+ std::sync::Arc::new(noq_proto::congestion::NewRenoConfig::default())
+ }
+ };
+ tracing::info!(
+ congestion = ?tuning.congestion,
+ stream_window = tuning.stream_window,
+ connection_window = tuning.connection_window,
+ "transport"
+ );
let transport = QuicTransportConfig::builder()
.keep_alive_interval(KEEP_ALIVE_INTERVAL)
.max_idle_timeout(Some(IDLE_TIMEOUT.try_into().expect("the idle timeout fits a QUIC varint")))
- // Room for a file transfer to keep the link busy through Wi-Fi's
- // latency spikes (the defaults suit ~100 Mbit/s at 100 ms; a phone
- // on Wi-Fi 6 does several times that, with bursts of delay).
- .stream_receive_window(VarInt::from_u32(STREAM_WINDOW))
- .receive_window(VarInt::from_u32(CONNECTION_WINDOW))
- .send_window(u64::from(CONNECTION_WINDOW))
+ .stream_receive_window(VarInt::from_u32(tuning.stream_window))
+ .receive_window(VarInt::from_u32(tuning.connection_window))
+ .send_window(u64::from(tuning.connection_window))
+ .congestion_controller_factory(controller)
.build();
let mut builder = Endpoint::builder(presets::Minimal)
.secret_key(secret)