Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
fix(core): unpairing a device ends everything it was allowed
Bee1301bdb7e6dc
diff --git a/core/nectarlink-core/src/node.rs b/core/nectarlink-core/src/node.rsindex 4197c4c..3d785d5 100644--- a/core/nectarlink-core/src/node.rs+++ b/core/nectarlink-core/src/node.rs@@ -1021,6 +1021,12 @@ impl Shared {self.toggles.remove_peer(peer);self.deck.remove_peer(peer);self.stop_webcam(peer);+ // The session was removed above, so `on_session_end` won't clear these:+ // a one-time "show my screen" must not outlive the pairing.+ lock(&self.pc_mirror_sessions).remove(peer);+ lock(&self.watch_offers).remove(peer);+ self.stop_mic(peer);+ self.stop_showing_all(peer);if !dropped_queue.is_empty() {self.emit(NodeEvent::QueueChanged);if dropped_count > 0 {@@ -1052,6 +1058,12 @@ impl Shared {conn.close(VarInt::from_u32(CLOSE_NORMAL), b"away mode disabled");return None;}+ // Unpaired while the handshake ran (both sides check before it).+ if !self.store.is_paired(&peer).unwrap_or(false) {+ tracing::debug!(peer = %peer.short(), "refusing session: no longer paired");+ conn.close(VarInt::from_u32(ErrorCode::Unpaired.close_code()), b"unpaired");+ return None;+ }// Either side may have dialed: while the user has reconnecting off,// this device stays disconnected from that one.if !self.reconnects(&peer) {diff --git a/core/nectarlink-core/tests/two_devices.rs b/core/nectarlink-core/tests/two_devices.rsindex d7be4b4..ef06b20 100644--- a/core/nectarlink-core/tests/two_devices.rs+++ b/core/nectarlink-core/tests/two_devices.rs@@ -6374,3 +6374,42 @@ async fn a_reinstalled_phone_replaces_its_old_pairing() {pc.node.shutdown().await;new.node.shutdown().await;}++#[tokio::test(flavor = "multi_thread")]+async fn one_time_screen_consent_ends_with_the_pairing() {+ use nectarlink_core::{MIRROR_CAPTURE, MIRROR_INPUT, MIRROR_SCREEN, MirrorStart};++ let mut pc = device_with("Desktop", DeviceKind::Desktop, &[MIRROR_CAPTURE, MIRROR_INPUT]).await;+ let mut phone = device_with("Pixel", DeviceKind::Phone, &[nectarlink_core::MIRROR_VIEW]).await;+ pair_qr(&mut pc, &mut phone).await;+ let (pc_id, phone_id) = (pc.node.device_id(), phone.node.device_id());+ let options = MirrorStart {+ max_size: 1280,+ fps: 30,+ bitrate: 4_000_000,+ audio: false,+ session: MIRROR_SCREEN,+ app: None,+ stay_awake: false,+ screen_off: false,+ watch: None,+ };++ // "Allow once" lets the phone view the PC's screen during this connection+ // (granted here before the phone starts, so nothing else clears it).+ pc.node.set_pc_mirror_session_allowed(phone_id, true);++ // After unpairing and pairing again, the phone has to be allowed again.+ with_timeout("unpair", pc.node.unpair(phone_id)).await.unwrap();+ wait_for(&mut phone, "phone forgets the PC", |e| match e {+ NodeEvent::DeviceRemoved(device) if *device == pc_id => Some(()),+ _ => None,+ })+ .await;+ pair_qr(&mut pc, &mut phone).await;+ let again = phone.node.mirror_start(pc_id, options).await;+ assert!(matches!(again, Err(Error::Denied)), "expected Denied after re-pairing, got {again:?}");++ pc.node.shutdown().await;+ phone.node.shutdown().await;+}