mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-27 13:52:16 +00:00
interfaces: drop traffic queued while a client's connection attempts fail
This commit is contained in:
1 parent
2e8fa290dc
commit
264b00eb3d
5 files changed
+57
-42
No files matched your search
+1
-1
@@ -14,7 +14,7 @@
|
||||
- After a restart, a hub no longer gives a previous client's saved paths to a new client that reuses its interface name, and it keeps saved tunnels that had no live interface, as in Python Reticulum.
|
||||
- Transport hubs now accept tunnel synthesis, so a Python client that reconnects gets its paths back without announcing again, and losing a tunnel's interface no longer drops paths the hub learned through other interfaces, as in Python Reticulum.
|
||||
- PLAIN and GROUP packets that arrive from more than one hop away, and announces typed PLAIN or GROUP, are dropped before deduplication, as in Python Reticulum.
|
||||
- TCP, Backbone and I2P client interfaces open every connection with a tunnel synthesis, so a transport hub restores their paths after a reconnect, and traffic queued while a connection was down is dropped when it returns, as in Python Reticulum.
|
||||
- TCP, Backbone and I2P client interfaces open every connection with a tunnel synthesis, so a transport hub restores their paths after a reconnect, and traffic queued while a connection was down or failing to open is dropped when it opens, as in Python Reticulum.
|
||||
- Python Reticulum 1.5 `rnstatus` and `rnpath` work against `rnsd-rs`, locally and with `-R`: interface stats carry every field they read, including announce and path request counts, violation counters and the transport instance, and remote management answers on the transport identity, as in Python Reticulum.
|
||||
- Announces held during an ingress burst on an IFAC interface are processed when released instead of being dropped, and released or replayed announces no longer count as received traffic again, as in Python Reticulum.
|
||||
- Interface discovery announces name this stack, `rsRNS`, and its version. `rnsd-rs` auto-connects only to Backbone interfaces announced by Python Reticulum 1.5.2 or later, or to any announced Backbone interface with `autoconnect_unverified_implementations`, and no longer stores or lists discovered TCP client interfaces, as in Python Reticulum.
|
||||
|
||||
@@ -708,9 +708,11 @@ pub async fn spawn_backbone_client(
|
||||
let read_task = tokio::spawn(async move {
|
||||
let max_tries = config.max_reconnect_tries;
|
||||
let mut tries: usize = 0;
|
||||
let mut connected_before = false;
|
||||
// Every attempt after the first follows a failure or an outage.
|
||||
let mut attempted = false;
|
||||
|
||||
loop {
|
||||
let after_outage = std::mem::replace(&mut attempted, true);
|
||||
let target = match tokio::time::timeout(
|
||||
Duration::from_secs(config.connect_timeout_secs),
|
||||
resolve_target(&config.target_host, config.target_port, config.prefer_ipv6),
|
||||
@@ -793,14 +795,7 @@ pub async fn spawn_backbone_client(
|
||||
.tunnel_identity
|
||||
.as_ref()
|
||||
.and_then(|identity| identity.synthesis(&python_name));
|
||||
open_client_connection(
|
||||
&rx,
|
||||
std::mem::replace(&mut connected_before, true),
|
||||
&transport_tx,
|
||||
synthesis,
|
||||
&online2,
|
||||
)
|
||||
.await;
|
||||
open_client_connection(&rx, after_outage, &transport_tx, synthesis, &online2).await;
|
||||
|
||||
let c_online = Arc::new(AtomicBool::new(true));
|
||||
let (reader, writer) = stream.into_split();
|
||||
|
||||
@@ -368,9 +368,11 @@ pub async fn spawn_i2p_client(
|
||||
let python_name = config.python_name();
|
||||
let read_task = tokio::spawn(async move {
|
||||
let mut pacer = ReconnectPacer::new(config.reconnect_delay, config.max_reconnect_tries);
|
||||
let mut connected_before = false;
|
||||
// Every attempt after the first follows a failure or an outage.
|
||||
let mut attempted = false;
|
||||
|
||||
loop {
|
||||
let after_outage = std::mem::replace(&mut attempted, true);
|
||||
let session_id = generate_session_id();
|
||||
|
||||
let session_stream = match connect_to_sam(&config.sam_host, config.sam_port).await {
|
||||
@@ -526,14 +528,7 @@ pub async fn spawn_i2p_client(
|
||||
.tunnel_identity
|
||||
.as_ref()
|
||||
.and_then(|identity| identity.synthesis(&python_name));
|
||||
open_client_connection(
|
||||
&rx,
|
||||
std::mem::replace(&mut connected_before, true),
|
||||
&transport_tx,
|
||||
synthesis,
|
||||
&online_task,
|
||||
)
|
||||
.await;
|
||||
open_client_connection(&rx, after_outage, &transport_tx, synthesis, &online_task).await;
|
||||
|
||||
// BufReader may have prefetched past the handshake; flush its tail first.
|
||||
let buffered = stream_buf_reader.buffer().to_vec();
|
||||
|
||||
@@ -341,9 +341,11 @@ pub async fn spawn_tcp_client(
|
||||
let max_tries = config.max_reconnect_tries;
|
||||
let mut tries: usize = 0;
|
||||
let mut backoff = RECONNECT_WAIT_INITIAL;
|
||||
let mut connected_before = false;
|
||||
// Every attempt after the first follows a failure or an outage.
|
||||
let mut attempted = false;
|
||||
|
||||
loop {
|
||||
let after_outage = std::mem::replace(&mut attempted, true);
|
||||
let addr = format!("{}:{}", config.target_host, config.target_port);
|
||||
let stream = match tokio::time::timeout(
|
||||
std::time::Duration::from_secs(config.connect_timeout_secs),
|
||||
@@ -405,14 +407,7 @@ pub async fn spawn_tcp_client(
|
||||
.as_ref()
|
||||
.filter(|_| !kiss_framing)
|
||||
.and_then(|identity| identity.synthesis(&python_name));
|
||||
open_client_connection(
|
||||
&rx,
|
||||
std::mem::replace(&mut connected_before, true),
|
||||
&transport_tx,
|
||||
synthesis,
|
||||
&online2,
|
||||
)
|
||||
.await;
|
||||
open_client_connection(&rx, after_outage, &transport_tx, synthesis, &online2).await;
|
||||
|
||||
let (reader, writer) = stream.into_split();
|
||||
|
||||
|
||||
@@ -691,34 +691,64 @@ async fn a_tcp_client_drops_traffic_queued_while_it_was_disconnected() {
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_tcp_client_keeps_traffic_queued_before_its_first_connection() {
|
||||
let port = unused_port().await;
|
||||
/// A failed connection attempt is an outage too: traffic queued while a
|
||||
/// client's first attempts fail is dropped, so however much was queued the
|
||||
/// synthesis opens the connection (Python drops traffic while offline,
|
||||
/// TCPInterface.py:314-315).
|
||||
async fn assert_failed_first_attempts_drop_their_backlog(tag: &str, port: u16, interface: &str) {
|
||||
let dir = config_dir(
|
||||
"tcp-first-backlog",
|
||||
&format!(
|
||||
"[reticulum]\n share_instance = No\n\n[interfaces]\n [[Uplink]]\n type = TCPClientInterface\n enabled = yes\n target_host = 127.0.0.1\n target_port = {port}\n"
|
||||
),
|
||||
tag,
|
||||
&format!("[reticulum]\n share_instance = No\n\n[interfaces]\n{interface}"),
|
||||
);
|
||||
let handle = start(&dir).await;
|
||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
||||
|
||||
let marker = send_plain_marker(&handle, "wp4.first.backlog").await;
|
||||
let mut markers = Vec::new();
|
||||
for n in 0..1100 {
|
||||
markers.push(send_plain_marker(&handle, &format!("backlog.{tag}.{n}")).await);
|
||||
}
|
||||
let hub = TcpListener::bind(("127.0.0.1", port)).await.unwrap();
|
||||
let mut first = Frames::accept(&hub, false).await;
|
||||
let frames = first.collect(Duration::from_secs(2)).await;
|
||||
let mut connection = Frames::accept(&hub, false).await;
|
||||
let first = connection
|
||||
.next(Duration::from_secs(5))
|
||||
.await
|
||||
.expect("the connection carries a frame");
|
||||
assert!(
|
||||
frames.iter().any(|frame| synthesis_in(frame).is_some()),
|
||||
"control: the first connection opens with its synthesis"
|
||||
synthesis_in(&first).is_some(),
|
||||
"the synthesis opens the connection despite the backlog"
|
||||
);
|
||||
let rest = connection.collect(Duration::from_secs(2)).await;
|
||||
assert!(
|
||||
frames.contains(&marker),
|
||||
"only an outage drops queued traffic; the first connection delivers it"
|
||||
!rest.iter().any(|frame| markers.contains(frame)),
|
||||
"traffic queued while the first attempts failed is dropped"
|
||||
);
|
||||
|
||||
handle.shutdown_and_wait().await;
|
||||
let _ = std::fs::remove_dir_all(dir);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_tcp_client_drops_traffic_queued_while_its_first_attempts_fail() {
|
||||
let port = unused_port().await;
|
||||
assert_failed_first_attempts_drop_their_backlog(
|
||||
"tcp-first-backlog",
|
||||
port,
|
||||
&format!(" [[Uplink]]\n type = TCPClientInterface\n enabled = yes\n target_host = 127.0.0.1\n target_port = {port}\n"),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_backbone_client_drops_traffic_queued_while_its_first_attempts_fail() {
|
||||
let port = unused_port().await;
|
||||
assert_failed_first_attempts_drop_their_backlog(
|
||||
"backbone-first-backlog",
|
||||
port,
|
||||
&format!(" [[Backbone Up]]\n type = BackboneInterface\n enabled = yes\n target_host = 127.0.0.1\n port = {port}\n"),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_shared_instance_client_never_synthesizes() {
|
||||
assert!(
|
||||
|
||||
Reference in new issue
Block a user