From f41811b6695b231fef6aeca37ebc4bc74541c8b8 Mon Sep 17 00:00:00 2001 From: Lee Smet Date: Wed, 29 May 2024 09:56:04 +0200 Subject: [PATCH] Kill peer connection if router appears to be gone If the router is gone (or the receiver of the packet forward channels, at least), peers got stuck repeatedly trying to forward packets to said router. Signed-off-by: Lee Smet --- CHANGELOG.md | 2 ++ mycelium/src/peer.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eba96dd..ed18c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Only do the periodic route announcement every 5 minutes instead of every minute. - Mycelium binary is no longer part of the workspace, and no longer contains private network functionality. +- If a packet received from a peer can't be forwarded to the router, terminate the + connection to the peer. ### Fixed diff --git a/mycelium/src/peer.rs b/mycelium/src/peer.rs index 875c8ee..6322e3e 100644 --- a/mycelium/src/peer.rs +++ b/mycelium/src/peer.rs @@ -98,13 +98,19 @@ impl Peer { Some(Ok(packet)) => { match packet { Packet::DataPacket(packet) => { + // An error here means the receiver is dropped/closed, + // this is not recoverable. if let Err(error) = router_data_tx.send(packet).await{ error!("Error sending to to_routing_data: {}", error); + break } } Packet::ControlPacket(packet) => { if let Err(error) = router_control_tx.send((packet, peer.clone())) { + // An error here means the receiver is dropped/closed, + // this is not recoverable. error!("Error sending to to_routing_control: {}", error); + break } }