gui: NodeSlot for the shared P2P node, in place of Arc<Mutex<Option<Arc<NodeRuntime>>>>

The type was spelled out 29 times and read through 29 .lock().unwrap()s (a
poison-panic each), 17 of them the same .as_ref().map(|rt| rt.p2p.endpoint()).
network_task::NodeSlot wraps the same cell with get/endpoint/set and recovers
a poisoned lock; the embedded daemon socket still gets the raw cell
(shared()), since syn-daemon reads it per request. A watch channel ticks on
every set, so the scheduler's startup wait is NodeSlot::ready under a timeout
instead of a sleep-poll loop (audit gui-core T1). Also drops the stale
"inferred iroh Endpoint, so this crate avoids a direct iroh dep" comments —
the type is the lib's EnsembleEndpoint — and moves comics' fetch_page_remote
doc back onto it from fetch_page_for_reader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Greg ShuflinandClaude Opus 5.5 committed 2026-09-28 13:36:49 -07:00
1 parent 71948f5db2
commit e610f1f06c
20 files changed
+216 -166

No files matched your search

+16 -19
View File
@@ -32,7 +32,7 @@
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use gpui::{
BackgroundExecutor, Context, Entity, FocusHandle, Focusable, IntoElement, KeyDownEvent,
@@ -50,7 +50,7 @@ use synchronicity::agents::comics::{
use synchronicity::documents::DocumentID;
use synchronicity::documents::import::COMIC_FILE_TYPES;
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::stores::Store;
use synchronicity::stores::blob_store::BlobStoreError;
use tokio::runtime::Handle;
@@ -70,7 +70,7 @@ use crate::components::remote_fetch::{RemoteFetch, cancel_label, remote_fetch_ov
use crate::components::screen_header::{header_spacer, screen_header, screen_title};
use crate::components::zoomable_image::{ZoomableImage, render_zoom_controls};
use crate::import_job;
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::{control, font, icon, scaled, shape};
use crate::store_watch;
use crate::theme::{ActiveTheme, Theme};
@@ -214,11 +214,10 @@ pub struct ComicsView {
/// The imports running right now, shown under the header. Its own view
/// because it keeps itself current; see [`ImportsInProgress`].
imports: Entity<ImportsInProgress>,
/// Inferred iroh `Endpoint` (so this crate avoids a direct iroh dep) —
/// same pattern as `ensemble.rs`/`settings.rs`/`music.rs`. Only used by
/// the remote-fetch fallback in `go_to_page`/`open_comic` and the page
/// prefetch queue, if a page isn't stored locally.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
/// The P2P node, only used by the remote-fetch fallback in
/// `go_to_page`/`open_comic` and the page prefetch queue, if a page isn't
/// stored locally.
node_runtime: NodeSlot,
rt: Handle,
/// The shared library browser (tabs + cards/list + breadcrumbs); owns
/// its own view state.
@@ -279,7 +278,7 @@ impl ComicsView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
nav_sidebar: &Entity<AgentSidebar>,
job_runner: Arc<JobRunner>,
@@ -836,14 +835,6 @@ impl ComicsView {
// ── Reader ────────────────────────────────────────────────────────────────────
/// The remote-fetch fallback for a comic page: its whole blob, off
/// whichever ensemble peer holds it. Built here, which is where the
/// inferred iroh `Endpoint` can be read off `node_runtime` (this crate
/// has no direct `iroh` dependency and never names that type), and called
/// per page — by [`load_page_bytes`] for the page being opened, and by
/// [`Self::prefetch_upcoming_pages`] for the read-ahead window. The wait
/// runs on the tokio runtime; see [`crate::network_task`] for why it must
/// not run on a gpui worker thread.
/// The reader's own page fetch — the page the user turned to and is
/// waiting on. Tracked, so it gets a job row, a byte counter, and a cancel.
fn fetch_page_for_reader(&self) -> impl AsyncFn(DocumentID) -> Result<Vec<u8>, String> + use<> {
@@ -860,11 +851,17 @@ impl ComicsView {
self.fetch_page_remote(None)
}
/// The remote-fetch fallback for a comic page: its whole blob, off
/// whichever ensemble peer holds it, called per page — by
/// [`load_page_bytes`] for the page being opened, and by
/// [`Self::prefetch_upcoming_pages`] for the read-ahead window. The wait
/// runs on the tokio runtime; see [`crate::network_task`] for why it must
/// not run on a gpui worker thread.
fn fetch_page_remote(
&self,
job_runner: Option<Arc<JobRunner>>,
) -> impl AsyncFn(DocumentID) -> Result<Vec<u8>, String> + use<> {
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
let store = Arc::clone(&self.store);
async move |page_id: DocumentID| {
@@ -1078,7 +1075,7 @@ impl ComicsView {
current_index: usize,
cx: &mut Context<Self>,
) {
if self.node_runtime.lock().unwrap().is_none() {
if self.node_runtime.get().is_none() {
return;
}
let store = Arc::clone(&self.store);
@@ -468,7 +468,7 @@ impl DocumentsView {
self.active_jobs.refresh(&self.job_runner);
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let store = Arc::clone(&self.store);
let rt = self.rt.clone();
let local_node = self.node;
@@ -570,7 +570,7 @@ impl DocumentsView {
self.active_jobs.refresh(&self.job_runner);
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let store = Arc::clone(&self.store);
let rt = self.rt.clone();
let fetch_asset = asset.clone();
@@ -726,7 +726,7 @@ impl DocumentsView {
self.active_jobs.refresh(&self.job_runner);
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let store = Arc::clone(&self.store);
let rt = self.rt.clone();
let local_node = self.node;
@@ -802,7 +802,7 @@ impl DocumentsView {
}
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
let result = network_task::run_msg(&rt, async move {
@@ -873,8 +873,7 @@ impl DocumentsView {
let doc_id = detail.id.clone();
cx.notify();
let gossip_sender =
self.node_runtime.lock().unwrap().as_ref().and_then(|rt| rt.p2p.gossip_sender());
let gossip_sender = self.node_runtime.get().and_then(|rt| rt.p2p.gossip_sender());
let store = Arc::clone(&self.store);
let local_node = self.node;
let rt = self.rt.clone();
@@ -968,7 +967,7 @@ impl DocumentsView {
let doc_id = detail.id.clone();
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let store = Arc::clone(&self.store);
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
+5 -5
View File
@@ -13,7 +13,7 @@ mod presence_view;
use std::collections::{HashMap, HashSet};
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::time::Duration;
use gpui::{
@@ -31,7 +31,7 @@ use synchronicity::documents::{DocumentID, DocumentType, PropertyKind, PropertyV
use synchronicity::eviction::EvictionPlan;
use synchronicity::jobs::runner::JobRunner;
use synchronicity::jobs::{JobKind, JobSubject};
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::node_status::NodePresence;
use synchronicity::stores::Store;
use synchronicity::stores::blob_store::StoreProgress;
@@ -55,7 +55,7 @@ use crate::components::text_input::{InputEvent, TextInput};
use crate::components::tooltip::text_tooltip;
use crate::import_job;
use crate::job_binding::ActiveJobs;
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::{font, icon, scaled, shape};
use crate::store_watch;
use crate::theme::{ActiveTheme, Theme};
@@ -422,7 +422,7 @@ const DATE_FILTERS: &[DateFilter] = &[
pub struct DocumentsView {
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
job_runner: Arc<JobRunner>,
state: LoadState,
@@ -524,7 +524,7 @@ impl DocumentsView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
job_runner: Arc<JobRunner>,
nav_sidebar: &Entity<AgentSidebar>,
+7 -8
View File
@@ -41,7 +41,7 @@ use synchronicity::documents::import::{MUSIC_FILE_TYPES, import_directory_tree};
use synchronicity::documents::{ArtifactKind, DocumentID, DocumentType};
use synchronicity::jobs::runner::JobRunner;
use synchronicity::jobs::{JobKind, JobOrigin, JobSubject};
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::stores::Store;
use synchronicity::stores::blob_store::BlobStoreError;
use tokio::runtime::Handle;
@@ -66,7 +66,7 @@ use crate::components::screen_header::{header_spacer, screen_header, screen_titl
use crate::components::truncate::TruncateMiddle;
use crate::import_job;
use crate::job_binding::{ActiveJobs, JobControl};
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::font;
use crate::store_watch;
use crate::theme::{ActiveTheme, Theme};
@@ -111,7 +111,7 @@ pub struct MusicView {
/// fetch fallback (`docs/sync-management.md` phase 6) when a selected
/// track's audio isn't stored locally; `None` before the node is online,
/// in which case that fallback simply can't reach a peer.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
/// The selected track resolved down to playable audio. Not a transport —
/// it holds no player and drives nothing; the bar below asks it for a
@@ -198,7 +198,7 @@ impl MusicView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
nav_sidebar: &Entity<AgentSidebar>,
media: Entity<MediaSession>,
@@ -635,10 +635,9 @@ impl MusicView {
let store = Arc::clone(&self.store);
let player = Arc::clone(&self.selected);
// Inferred iroh `Endpoint` (so this crate avoids a direct iroh dep) —
// same pattern as ensemble.rs/settings.rs. Only used by the
// Stream-policy fallback below, if the local load needs it.
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
// Only used by the Stream-policy fallback below, if the local load
// needs it.
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
let job_runner = Arc::clone(&self.job_runner);
+12 -18
View File
@@ -37,7 +37,7 @@ use synchronicity::agents::pdf::{
use synchronicity::documents::import::{PDF_FILE_TYPES, import_directory_tree};
use synchronicity::documents::{DocumentAvailability, DocumentID};
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::stores::Store;
use synchronicity::stores::blob_store::BlobStoreError;
use tokio::runtime::Handle;
@@ -66,7 +66,7 @@ use crate::components::zoomable_image::{
FitResized, ModeChanged, ZoomMode, ZoomableImage, render_zoom_controls,
};
use crate::import_job;
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::layout::DIALOG_NARROW_WIDTH;
use crate::sizing::{control, font, icon, scaled, shape};
use crate::store_watch;
@@ -460,13 +460,10 @@ impl RenderDispatch {
/// comment), so there's no partial-buffer playback step: `fetch_remote`
/// resolves only once the whole blob is in hand.
///
/// Takes a closure (rather than an `Endpoint` parameter) because this crate
/// has no direct `iroh` dependency and never names that type — see
/// `music.rs`'s "Inferred iroh `Endpoint`" comment for the same constraint;
/// the caller builds `fetch_remote` from an `Endpoint` it only ever holds
/// via inference, and hands the network wait to the tokio runtime through
/// [`crate::network_task`]. The local read is blocking, so it goes to the
/// background executor; the fetch is a wait, so it must not.
/// The caller builds `fetch_remote`, handing the network wait to the tokio
/// runtime through [`crate::network_task`]. The local read is blocking, so
/// it goes to the background executor; the fetch is a wait, so it must
/// not.
async fn load_bytes(
&self,
document_id: &DocumentID,
@@ -667,11 +664,9 @@ pub struct PdfViewerView {
/// The imports running right now, shown under the header. Its own view
/// because it keeps itself current; see [`ImportsInProgress`].
imports: Entity<ImportsInProgress>,
/// Inferred iroh `Endpoint` (so this crate avoids a direct iroh dep) —
/// same pattern as `ensemble.rs`/`settings.rs`/`music.rs`. Only used by
/// the remote-fetch fallback below, if a page/document isn't stored
/// locally.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
/// The P2P node, only used by the remote-fetch fallback below, if a
/// page/document isn't stored locally.
node_runtime: NodeSlot,
rt: Handle,
/// The library browser; owns its own tab/layout/keyboard-cursor state.
library: Entity<MediaLibrary>,
@@ -756,7 +751,7 @@ impl PdfViewerView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
nav_sidebar: &Entity<AgentSidebar>,
job_runner: Arc<JobRunner>,
@@ -1047,8 +1042,7 @@ impl PdfViewerView {
}
/// The remote-fetch fallback for `id`: the whole blob, off whichever
/// ensemble peer holds it. Built here, which is where the inferred iroh
/// `Endpoint` can be read off `node_runtime`, and awaited by
/// ensemble peer holds it. Awaited by
/// [`RenderDispatch::load_bytes`] only if the blob turns out not to be
/// stored on this node. The wait itself happens on the tokio runtime —
/// see [`crate::network_task`] for why it must not happen on a gpui
@@ -1057,7 +1051,7 @@ impl PdfViewerView {
&self,
id: &DocumentID,
) -> impl AsyncFnOnce() -> Result<Vec<u8>, String> + use<> {
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
let store = Arc::clone(&self.store);
let job_runner = Arc::clone(&self.job_runner);
+8 -10
View File
@@ -12,7 +12,7 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use gpui::{
AnyElement, Context, Entity, FontWeight, IntoElement, Render, RenderImage, SharedString,
@@ -28,7 +28,7 @@ use synchronicity::copy::{action, content_fetch, library_empty, picture_absent};
use synchronicity::documents::import::{IMAGE_FILE_TYPES, import_directory_tree};
use synchronicity::documents::{DocumentAvailability, DocumentID};
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::stores::Store;
use synchronicity::stores::blob_store::BlobStoreError;
use tokio::runtime::Handle;
@@ -51,7 +51,7 @@ use crate::components::screen_header::{header_spacer, screen_header, screen_titl
use crate::components::text_input::{InputEvent, TextInput};
use crate::components::zoomable_image::{ZoomableImage, render_zoom_controls};
use crate::import_job;
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::layout::{DIALOG_WIDTH, SIDEBAR_MAX_WIDTH, SIDEBAR_MIN_WIDTH, SIDEBAR_WIDTH};
use crate::sizing::{control, font, icon, scaled, shape};
use crate::store_watch;
@@ -83,7 +83,7 @@ pub struct PicturesView {
/// The p2p runtime, read for its iroh `Endpoint` when an image has to come
/// off a peer. Behind a `Mutex<Option<..>>` because the node can start,
/// stop and restart under a screen that stays composed.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
/// The app's tokio runtime. Waiting on a peer runs there, never on a gpui
/// worker thread — see [`crate::network_task`].
rt: Handle,
@@ -130,7 +130,7 @@ impl PicturesView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
nav_sidebar: &Entity<AgentSidebar>,
job_runner: Arc<JobRunner>,
@@ -401,15 +401,13 @@ impl PicturesView {
.ok();
}
/// Fetch an image's bytes from whichever ensemble peer holds them. Built
/// here, which is where the inferred iroh `Endpoint` can be read off
/// `node_runtime` (this crate has no direct `iroh` dependency and never
/// names that type). The wait runs on the tokio runtime; see
/// Fetch an image's bytes from whichever ensemble peer holds them. The
/// wait runs on the tokio runtime; see
/// [`crate::network_task`] for why it must not run on a gpui worker thread.
fn fetch_image_remote(
&self,
) -> impl AsyncFn(DocumentID) -> Result<Vec<u8>, FetchFailure> + use<> {
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
let store = Arc::clone(&self.store);
let job_runner = Arc::clone(&self.job_runner);
+7 -6
View File
@@ -2,7 +2,7 @@
//! that shows a dummy placeholder for whichever agent the sidebar has selected.
use std::collections::{BTreeMap, HashMap, HashSet};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use gpui::{
AnyElement, AnyView, Context, DismissEvent, Entity, FocusHandle, FontWeight, IntoElement,
@@ -11,7 +11,7 @@ use gpui::{
};
use synchronicity::agents::{AgentId, AgentMetadata, AgentRegistry};
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::stores::Store;
use synchronicity::stores::settings::WindowGeometry;
use tokio::runtime::Handle;
@@ -35,6 +35,7 @@ use crate::components::command_palette::{CommandPalette, PaletteEvent, TogglePal
use crate::components::media_session::MediaSession;
use crate::components::menu::{PopupMenu, PopupMenuItem};
use crate::nav_status::NavStatus;
use crate::network_task::NodeSlot;
use crate::popout::{self, PopoutWindow};
use crate::settings::{SettingsView, Tab, TabSelected, TeardownRequested};
use crate::sizing::font;
@@ -51,7 +52,7 @@ pub struct SynchronicityView {
/// the node off the network before it deletes the store — see
/// [`Self::begin_teardown`]. Every other use lives in the per-agent
/// screens, which each hold their own clone.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
/// Held for the same reason: a teardown cancels every in-flight job
/// before the wipe, so nothing is still writing into the directory that is
/// about to go.
@@ -118,7 +119,7 @@ impl SynchronicityView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
cx: &mut Context<Self>,
) -> Self {
@@ -128,7 +129,7 @@ impl SynchronicityView {
let store_for_self = Arc::clone(&store);
// Teardown needs all three, and is built long after this — see
// [`Self::begin_teardown`].
let node_runtime_for_self = Arc::clone(&node_runtime);
let node_runtime_for_self = node_runtime.clone();
let rt_for_self = rt.clone();
let registry = AgentRegistry::default();
// App-wide "now playing" coordinator, shared by the media agents (which
@@ -323,7 +324,7 @@ impl SynchronicityView {
.map(SharedString::from)
.unwrap_or_else(|| "this node".into());
let store = Arc::clone(&self.store);
let node_runtime = Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
let job_runner = Arc::clone(&self.job_runner);
let rt = self.rt.clone();
self.teardown = Some(cx.new(|cx| {
+11 -6
View File
@@ -10,14 +10,15 @@
//! state the GUI already owns (`Arc<Store>`, the shared `node_runtime`
//! handle) instead of opening the store or daemonizing a second time.
use std::sync::{Arc, Mutex, OnceLock};
use std::sync::{Arc, OnceLock};
use syn_daemon::pairing::PairingState;
use synchronicity::node::NodeRuntime;
use synchronicity::stores::Store;
use tokio::runtime::Handle;
use tokio::task::JoinHandle;
use crate::network_task::NodeSlot;
/// The one daemon-socket task this process ever spawns — see [`spawn`]. A
/// bare `OnceLock` (no surrounding `Mutex`) is enough because `abort_on_quit`
/// only needs `&self` on the handle, never ownership.
@@ -58,12 +59,16 @@ pub fn pairing_state() -> Arc<PairingState> {
/// A failure to bind (e.g. a stale socket somehow still answering) is
/// logged, not fatal — the GUI works fine with no command socket, CLI/TUI
/// commands just fall back to their usual "store in use" error.
pub fn spawn(rt: &Handle, store: Arc<Store>, node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>) {
pub fn spawn(rt: &Handle, store: Arc<Store>, node_runtime: NodeSlot) {
let handle = rt.spawn(async move {
let socket_path = store.path.join(syn_daemon::DAEMON_SOCK_FILE);
if let Err(e) =
syn_daemon::server::serve_embedded(&socket_path, store, node_runtime, pairing_state())
.await
if let Err(e) = syn_daemon::server::serve_embedded(
&socket_path,
store,
node_runtime.shared(),
pairing_state(),
)
.await
{
log::warn!("daemon command socket stopped: {e:#}");
}
+7 -7
View File
@@ -12,7 +12,7 @@ use gpui::{
BackgroundExecutor, ClipboardItem, Context, Entity, EventEmitter, FontWeight, IntoElement,
Render, SharedString, Task, Window, div, prelude::*,
};
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::time::Duration;
use synchronicity::ensemble::init::join_existing_ensemble;
use synchronicity::ensemble::secret::{EnsembleSecret, Secret};
@@ -23,7 +23,7 @@ use tokio::runtime::Handle;
use crate::components::button::button;
use crate::components::progress_bar::indeterminate_progress_bar;
use crate::components::text_input::{InputEvent, TextInput};
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::layout::{DIALOG_NARROW_WIDTH, DIALOG_WIDTH};
use crate::sizing::{font, scaled, shape};
use crate::theme::{ActiveTheme, Theme};
@@ -51,7 +51,7 @@ pub(crate) struct InitializationScreen {
rt: Handle,
/// Holds the started [`NodeRuntime`] alive for the session. Shared with the
/// root view so it survives this screen being torn down after init.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
screen: Screen,
/// The freshly generated ensemble keyphrase. `Some` switches to the
@@ -76,7 +76,7 @@ impl InitializationScreen {
pub(crate) fn new(
store: Arc<Store>,
rt: Handle,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
cx: &mut Context<Self>,
) -> Self {
let join_phrase = cx.new(|cx| TextInput::new(cx, "word1-word2 word3-word4 …"));
@@ -190,7 +190,7 @@ impl InitializationScreen {
let store = Arc::clone(&self.store);
let rt = self.rt.clone();
let node_runtime = Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
cx.spawn(async move |this, cx| {
// The join touches the database and the network, and each half runs
@@ -355,7 +355,7 @@ impl InitializationScreen {
async fn join_ensemble(
store: Arc<Store>,
rt: Handle,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
phrase: String,
node_name: Option<String>,
executor: BackgroundExecutor,
@@ -396,7 +396,7 @@ async fn join_ensemble(
// re-reads per request, so P2P-backed commands start working the
// moment this assignment lands. See `daemon_socket`.
Ok(node) => {
*node_runtime.lock().unwrap() = Some(Arc::new(node));
node_runtime.set(Some(Arc::new(node)));
log::info!("P2P node started after joining ensemble");
}
Err(e) => log::warn!("P2P node failed to start after joining (gossip disabled): {e}"),
+8 -7
View File
@@ -58,6 +58,7 @@ mod typeface;
mod zoom;
use assets::Assets;
use network_task::NodeSlot;
use root::Root;
/// The shared tokio runtime that drives async store/network work (gossip, P2P,
@@ -155,7 +156,7 @@ fn main() {
// Holds the P2P runtime once started — either here (already initialized) or by
// the onboarding screen after a successful join.
let node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>> = Arc::new(Mutex::new(None));
let node_runtime = NodeSlot::default();
// Holds the in-flight P2P shutdown task spawned on app quit, so the code
// after `.run()` returns can wait for it to actually finish. iroh's
@@ -171,18 +172,18 @@ fn main() {
// finishes and after a failed `NodeRuntime::start` — the states where a
// user is most likely to reach for the CLI to find out what went wrong.
// See `daemon_socket`.
daemon_socket::spawn(&rt_handle, Arc::clone(&store), Arc::clone(&node_runtime));
daemon_socket::spawn(&rt_handle, Arc::clone(&store), node_runtime.clone());
// If the node is already initialized, bring the P2P runtime up in the
// background so the window can appear immediately; gossip comes online after.
if initialized {
let node_runtime = Arc::clone(&node_runtime);
let node_runtime = node_runtime.clone();
let store = Arc::clone(&store);
rt_handle.spawn(async move {
match NodeRuntime::start(store).await {
Ok(rt) => {
log::info!("NodeRuntime started in background");
*node_runtime.lock().unwrap() = Some(Arc::new(rt));
node_runtime.set(Some(Arc::new(rt)));
}
Err(e) => log::warn!("NodeRuntime failed to start (gossip disabled): {e}"),
}
@@ -203,14 +204,14 @@ fn main() {
// it starts running on the tokio runtime immediately, regardless of
// whether gpui's own 100ms quit-observer budget elapses first; the
// code after `.run()` returns then waits on `shutdown_task` for real.
let quit_node_runtime = Arc::clone(&node_runtime);
let quit_node_runtime = node_runtime.clone();
let quit_rt_handle = rt_handle.clone();
let quit_shutdown_task = Arc::clone(&shutdown_task);
cx.on_app_quit(move |_cx| {
// Stop serving the daemon command socket before releasing the
// P2P runtime it dispatches into (see `daemon_socket`).
daemon_socket::abort_on_quit();
let runtime = quit_node_runtime.lock().unwrap().take();
let runtime = quit_node_runtime.set(None);
// `daemon_socket`'s task holds its own `Arc<NodeRuntime>` clone
// only while a request is in flight — aborting it above means
// this is normally the sole reference, so `try_unwrap` succeeds
@@ -305,7 +306,7 @@ fn main() {
node,
initialized,
rt_handle.clone(),
Arc::clone(&node_runtime),
node_runtime.clone(),
window,
cx,
)
+69
View File
@@ -41,8 +41,12 @@
//! frame, so it owns its `Arc<Store>`, endpoint clone and ids.
use std::future::Future;
use std::sync::{Arc, Mutex, MutexGuard, PoisonError};
use synchronicity::node::NodeRuntime;
use synchronicity::p2p::admission::EnsembleEndpoint;
use tokio::runtime::Handle;
use tokio::sync::watch;
/// The task didn't run to completion: it panicked, or the runtime shut down
/// under it. Distinct from the task's *own* error, which [`run`] passes
@@ -72,3 +76,68 @@ where
{
run(rt, future).await.unwrap_or_else(|e| Err(e.to_string()))
}
/// The app's P2P node, shared by every screen that reaches the network: empty
/// until `NodeRuntime::start` finishes (it runs after the window is up, or
/// after joining an ensemble) and again once teardown drops it.
///
/// Cheap to clone. A poisoned lock is recovered rather than propagated: the
/// cell only ever holds a finished `Option<Arc<_>>`, so there is no torn state
/// for a panic elsewhere to have left behind.
#[derive(Clone)]
pub struct NodeSlot {
runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
/// Ticks on every [`set`](Self::set), for [`ready`](Self::ready).
changed: Arc<watch::Sender<()>>,
}
impl Default for NodeSlot {
fn default() -> Self {
Self { runtime: Arc::default(), changed: Arc::new(watch::Sender::new(())) }
}
}
impl NodeSlot {
/// The running node, if there is one.
pub fn get(&self) -> Option<Arc<NodeRuntime>> {
self.lock().clone()
}
/// The node's endpoint, if P2P is running.
pub fn endpoint(&self) -> Option<EnsembleEndpoint> {
self.lock().as_ref().map(|rt| rt.p2p.endpoint())
}
/// Install (or, with `None`, drop) the node, returning the one it replaces.
pub fn set(&self, runtime: Option<Arc<NodeRuntime>>) -> Option<Arc<NodeRuntime>> {
let previous = std::mem::replace(&mut *self.lock(), runtime);
self.changed.send_replace(());
previous
}
/// Wait until a node is running, and return it.
pub async fn ready(&self) -> Arc<NodeRuntime> {
// Subscribed before the check, so a `set` landing between the two is
// still seen as a change.
let mut changed = self.changed.subscribe();
loop {
if let Some(runtime) = self.get() {
return runtime;
}
// Only errs once every sender is gone, and `self` holds one.
if changed.changed().await.is_err() {
std::future::pending::<()>().await;
}
}
}
/// The cell itself, for the embedded daemon socket, which re-reads it on
/// every request (see `daemon_socket`).
pub fn shared(&self) -> Arc<Mutex<Option<Arc<NodeRuntime>>>> {
Arc::clone(&self.runtime)
}
fn lock(&self) -> MutexGuard<'_, Option<Arc<NodeRuntime>>> {
self.runtime.lock().unwrap_or_else(PoisonError::into_inner)
}
}
+9 -13
View File
@@ -8,20 +8,21 @@
//! window-level concerns (rem size/typeface/focus-traversal for both states,
//! and persisting the main window's own position/size).
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::time::Duration;
use gpui::{
App, Bounds, Context, Entity, IntoElement, Render, Window, WindowBounds, WindowId, div, point,
prelude::*, px, size,
};
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::stores::Store;
use synchronicity::stores::settings::WindowGeometry;
use tokio::runtime::Handle;
use crate::app::SynchronicityView;
use crate::initialization::{InitializationScreen, Initialized};
use crate::network_task::NodeSlot;
use crate::{focus, typeface, zoom};
/// What the root view is currently showing.
@@ -42,7 +43,7 @@ pub(crate) struct Root {
/// view that needs it. This is also the one `Arc` clone that outlives the
/// background startup task and the (transient) onboarding screen, so dropping
/// it would shut P2P down.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
/// Shared tokio runtime handle, passed to views that drive async work.
rt: Handle,
/// Bumped on every window move/resize; a debounced save whose generation
@@ -57,21 +58,16 @@ impl Root {
node: NodePubkey,
initialized: bool,
rt: Handle,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
cx.observe_window_bounds(window, Self::on_bounds_changed).detach();
let state = if initialized {
Self::ready_state(&store, node, Arc::clone(&node_runtime), rt.clone(), cx)
Self::ready_state(&store, node, node_runtime.clone(), rt.clone(), cx)
} else {
let screen = cx.new(|cx| {
InitializationScreen::new(
Arc::clone(&store),
rt.clone(),
Arc::clone(&node_runtime),
cx,
)
InitializationScreen::new(Arc::clone(&store), rt.clone(), node_runtime.clone(), cx)
});
cx.subscribe(&screen, |this, _screen, _: &Initialized, cx| this.on_initialized(cx))
.detach();
@@ -106,7 +102,7 @@ impl Root {
fn on_initialized(&mut self, cx: &mut Context<Self>) {
let store = Arc::clone(&self.store);
let node = crate::resolve_local_node(&store).unwrap_or(NodePubkey([0u8; 32]));
let node_runtime = Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
let rt = self.rt.clone();
self.state = Self::ready_state(&store, node, node_runtime, rt, cx);
cx.notify();
@@ -124,7 +120,7 @@ impl Root {
fn ready_state(
store: &Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
cx: &mut Context<Self>,
) -> RootState {
+15 -22
View File
@@ -12,21 +12,22 @@
//! Wi-Fi-only/charging are satisfied — something a hand-rolled loop like this
//! one could only poll for. See `docs/sync-management.md` phase 3.
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use std::time::Duration;
use synchronicity::jobs::JobOrigin;
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::scheduler;
use synchronicity::stores::Store;
use tokio::runtime::Handle;
/// How long to poll for the P2P endpoint to come up before giving the
use crate::network_task::NodeSlot;
/// How long to wait for the P2P endpoint to come up before giving the
/// startup trigger up for this run (the periodic loop will pick it up on its
/// own first tick regardless).
const STARTUP_WAIT: Duration = Duration::from_secs(30);
const STARTUP_POLL_INTERVAL: Duration = Duration::from_secs(1);
/// Floor under a user-configured interval, so a fat-fingered tiny value
/// can't turn this into a busy loop.
const MIN_INTERVAL: Duration = Duration::from_secs(60);
@@ -37,7 +38,7 @@ const MIN_INTERVAL: Duration = Duration::from_secs(60);
pub fn spawn(
rt: Handle,
store: Arc<Store>,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
job_runner: Arc<JobRunner>,
local_node: NodePubkey,
) {
@@ -52,7 +53,7 @@ pub fn spawn(
// track whether it's already wired; this also covers the case
// where the node joins an ensemble after this task's initial
// `wait_for_endpoint` gave up.
if let Some(node) = node_runtime.lock().unwrap().as_ref() {
if let Some(node) = node_runtime.get() {
node.p2p.set_job_runner(Arc::clone(&job_runner));
}
@@ -61,9 +62,7 @@ pub fn spawn(
.batch(|tx| store.settings_store.scheduler_settings(tx))
.unwrap_or_default();
if settings.enabled {
// Inferred iroh `Endpoint` (so this crate avoids a direct iroh
// dep) — same pattern as ensemble.rs/settings.rs.
let endpoint = node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = node_runtime.endpoint();
match endpoint {
Some(ep) => {
let summary = scheduler::run_all_passes(
@@ -103,18 +102,12 @@ pub fn spawn(
});
}
/// Poll briefly for the P2P endpoint to exist, so the "on startup" trigger
/// Wait briefly for the P2P node to exist, so the "on startup" trigger
/// actually runs close to startup rather than waiting a full interval — the
/// endpoint is populated by a separate async `NodeRuntime::start` call that
/// may not have finished by the time this task starts (see `main.rs`). Gives
/// up silently after [`STARTUP_WAIT`]; the periodic loop's own first tick
/// will pick it up regardless.
async fn wait_for_endpoint(node_runtime: &Mutex<Option<Arc<NodeRuntime>>>) {
let deadline = tokio::time::Instant::now() + STARTUP_WAIT;
while node_runtime.lock().unwrap().is_none() {
if tokio::time::Instant::now() >= deadline {
return;
}
tokio::time::sleep(STARTUP_POLL_INTERVAL).await;
}
/// node is installed by a separate async `NodeRuntime::start` call that may not
/// have finished by the time this task starts (see `main.rs`). Gives up
/// silently after [`STARTUP_WAIT`]; the periodic loop's own first tick will
/// pick it up regardless.
async fn wait_for_endpoint(node_runtime: &NodeSlot) {
let _ = tokio::time::timeout(STARTUP_WAIT, node_runtime.ready()).await;
}
+6 -4
View File
@@ -1,27 +1,29 @@
//! Building the ensemble snapshot off the UI thread.
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use synchronicity::copy::peer_health;
use synchronicity::documents::Timestamp;
use synchronicity::ensemble::screen::{RosterCounts, build_ensemble_status};
use synchronicity::jobs::runner::JobRunner;
use synchronicity::jobs::{JobKind, JobSubject};
use synchronicity::node::{NodePubkey, NodeRuntime, do_bootstrap_retry};
use synchronicity::node::{NodePubkey, do_bootstrap_retry};
use synchronicity::stores::Store;
use tokio::runtime::Handle;
use super::{ActionState, LastAction, Loaded, MemberRow};
use crate::network_task::NodeSlot;
/// Build the ensemble snapshot, kicking off a best-effort gossip bootstrap retry.
pub(super) fn load_blocking(
store: &Arc<Store>,
node_runtime: &Mutex<Option<Arc<NodeRuntime>>>,
node_runtime: &NodeSlot,
rt: &Handle,
job_runner: &JobRunner,
) -> Result<Loaded, String> {
let (gossip_neighbor_count, known_registry_members, registry_cache, gossip_sender) = {
let guard = node_runtime.lock().unwrap();
let guard = node_runtime.get();
let count = guard.as_ref().map(|rt| rt.p2p.gossip_neighbor_count() as u32).unwrap_or(0);
let registry_members =
guard.as_ref().map(|rt| rt.p2p.known_registry_members()).unwrap_or_default();
+10 -13
View File
@@ -10,7 +10,7 @@
mod load;
mod row;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use gpui::{
Context, Entity, EventEmitter, IntoElement, Render, SharedString, Task, Window, div,
@@ -25,7 +25,7 @@ use synchronicity::ensemble::retire;
use synchronicity::ensemble::screen::RosterCounts;
use synchronicity::jobs::runner::JobRunner;
use synchronicity::jobs::{JobKind, JobOrigin, JobSubject};
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::p2p::{P2PNode, gossip};
use synchronicity::scheduler;
use synchronicity::stores::Store;
@@ -42,7 +42,7 @@ use crate::components::section::section_heading;
use crate::components::text_input::{InputEvent, TextInput};
use crate::components::truncate::TruncateMiddle;
use crate::job_binding::ActiveJobs;
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::layout::{CONTENT_MAX_WIDTH, DIALOG_NARROW_WIDTH};
use crate::sizing::{control, font, scaled};
use crate::store_watch;
@@ -190,7 +190,7 @@ pub(crate) struct ManageSyncRequested(pub(crate) NodePubkey);
pub struct EnsembleView {
store: Arc<Store>,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
job_runner: Arc<JobRunner>,
/// Every job running on this node, so a member row's Sync button reflects
@@ -259,7 +259,7 @@ fn self_revoked_banner(theme: &Theme) -> impl IntoElement + use<> {
impl EnsembleView {
pub fn new(
store: Arc<Store>,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
job_runner: Arc<JobRunner>,
nav_sidebar: &Entity<AgentSidebar>,
@@ -326,7 +326,7 @@ impl EnsembleView {
cx.notify();
let store = Arc::clone(&self.store);
let node_runtime = Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
let rt = self.rt.clone();
let job_runner = Arc::clone(&self.job_runner);
@@ -360,7 +360,7 @@ impl EnsembleView {
/// read, so nobody is waiting to be told it failed.
fn refresh(&mut self, cx: &mut Context<Self>) {
let store = Arc::clone(&self.store);
let node_runtime = Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
let rt = self.rt.clone();
let job_runner = Arc::clone(&self.job_runner);
@@ -418,8 +418,7 @@ impl EnsembleView {
}
cx.notify();
// Inferred iroh `Endpoint` (so this crate avoids a direct iroh dep).
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
let probe = target.clone();
cx.spawn(async move |this, cx| {
@@ -470,8 +469,7 @@ impl EnsembleView {
}
cx.notify();
// Inferred iroh `Endpoint` (so this crate avoids a direct iroh dep).
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
let store = Arc::clone(&self.store);
let job_runner = Arc::clone(&self.job_runner);
@@ -674,8 +672,7 @@ impl EnsembleView {
cx.notify();
let store = Arc::clone(&self.store);
let sender =
self.node_runtime.lock().unwrap().as_ref().and_then(|rt| rt.p2p.gossip_sender());
let sender = self.node_runtime.get().and_then(|rt| rt.p2p.gossip_sender());
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
+6 -5
View File
@@ -27,7 +27,7 @@ mod system;
mod widgets;
use std::collections::BTreeMap;
use std::sync::{Arc, Mutex};
use std::sync::Arc;
use gpui::{
Context, Entity, EventEmitter, IntoElement, Render, SharedString, Window, div, prelude::*, px,
@@ -39,7 +39,7 @@ use synchronicity::credentials::{CredentialStatus, ServiceId, credential_status}
use synchronicity::documents::DocumentType;
use synchronicity::eviction::EvictionPlan;
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::{NodePubkey, NodeRuntime};
use synchronicity::node::NodePubkey;
use synchronicity::p2p::node_admin;
use synchronicity::stores::Store;
use synchronicity::stores::settings::{SchedulerSettings, SettingsStore};
@@ -52,6 +52,7 @@ use crate::components::tabs::{tab_bar, tab_pill};
use crate::components::text_input::{InputEvent, TextInput};
use crate::job_binding::ActiveJobs;
use crate::linkages::LinkagesView;
use crate::network_task::NodeSlot;
use crate::store_watch;
use crate::teardown::Ending;
use crate::theme::ActiveTheme;
@@ -163,7 +164,7 @@ pub struct SettingsView {
settings: SettingsStore,
/// The live P2P runtime, if started. Used to re-announce a renamed node over
/// gossip; `None` before the node is online.
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
node: NodePubkey,
rt: Handle,
job_runner: Arc<JobRunner>,
@@ -250,7 +251,7 @@ impl SettingsView {
pub fn new(
store: Arc<Store>,
node: NodePubkey,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
rt: Handle,
job_runner: Arc<JobRunner>,
nav_sidebar: &Entity<AgentSidebar>,
@@ -260,7 +261,7 @@ impl SettingsView {
let ensemble = cx.new(|cx| {
EnsembleView::new(
Arc::clone(&store),
Arc::clone(&node_runtime),
node_runtime.clone(),
rt.clone(),
Arc::clone(&job_runner),
nav_sidebar,
+1 -1
View File
@@ -37,7 +37,7 @@ impl SettingsView {
self.reclaim = Some(ReclaimFlow { doc_type, state: ReclaimState::Evaluating });
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let store = std::sync::Arc::clone(&self.store);
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
+5 -6
View File
@@ -125,7 +125,7 @@ impl SettingsView {
/// mutation answers with the same [`node_admin::SyncConfig`] shape, so
/// this doubles as "apply the response").
fn load_remote_config(&mut self, pubkey: NodePubkey, cx: &mut Context<Self>) {
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
let result = network_task::run_msg(&rt, async move {
@@ -240,7 +240,7 @@ impl SettingsView {
self.remote_trigger = RemoteTriggerState::Pending;
cx.notify();
let endpoint = self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
let result = network_task::run_msg(&rt, async move {
@@ -394,13 +394,13 @@ impl SettingsView {
cx.notify();
let store = std::sync::Arc::clone(&self.store);
let node_runtime = std::sync::Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
let job_runner = std::sync::Arc::clone(&self.job_runner);
let rt = self.rt.clone();
let local_node = self.node;
cx.spawn(async move |this, cx| {
let endpoint = node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = node_runtime.endpoint();
let result = network_task::run_msg(&rt, async move {
let ep = endpoint.ok_or_else(|| "P2P not running".to_string())?;
let summary = scheduler::run_all_passes(
@@ -570,8 +570,7 @@ impl SettingsView {
self.remote_config = Some(RemoteConfigState::Loading);
cx.notify();
let endpoint =
self.node_runtime.lock().unwrap().as_ref().map(|rt| rt.p2p.endpoint());
let endpoint = self.node_runtime.endpoint();
let rt = self.rt.clone();
cx.spawn(async move |this, cx| {
let result = network_task::run_msg(&rt, async move {
+1 -1
View File
@@ -84,7 +84,7 @@ impl SettingsView {
return;
}
// Re-announce the new name over gossip if the P2P node is running.
if let Some(rt) = self.node_runtime.lock().unwrap().as_ref()
if let Some(rt) = self.node_runtime.get()
&& let Err(e) = rt.p2p.update_node_name(stored)
{
log::warn!("Node name saved but gossip re-announce failed: {e}");
+7 -8
View File
@@ -44,21 +44,20 @@
//! `Store::remove_lock_file` — so the next launch finds a genuinely empty
//! store directory and offers onboarding, which is exactly the truth.
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use synchronicity::ensemble::SignedRecord;
use gpui::{Context, IntoElement, Render, SharedString, Task, Window, div, prelude::*, px};
use synchronicity::copy::revocation::{self, RetirementDelivery};
use synchronicity::ensemble::retirement::{self, Started};
use synchronicity::jobs::runner::JobRunner;
use synchronicity::node::NodeRuntime;
use synchronicity::stores::Store;
use tokio::runtime::Handle;
use crate::components::button::{button, danger_button};
use crate::components::hash_chip::hash_chip;
use crate::network_task;
use crate::network_task::{self, NodeSlot};
use crate::sizing::layout::CONTENT_MAX_WIDTH;
use crate::sizing::{font, shape};
use crate::theme::{ActiveTheme, Theme};
@@ -117,7 +116,7 @@ struct Attempt {
pub(crate) struct TeardownScreen {
store: Arc<Store>,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
job_runner: Arc<JobRunner>,
rt: Handle,
node_name: SharedString,
@@ -139,7 +138,7 @@ impl TeardownScreen {
/// this — reaching here *is* the decision.
pub(crate) fn new(
store: Arc<Store>,
node_runtime: Arc<Mutex<Option<Arc<NodeRuntime>>>>,
node_runtime: NodeSlot,
job_runner: Arc<JobRunner>,
rt: Handle,
node_name: SharedString,
@@ -174,12 +173,12 @@ impl TeardownScreen {
/// come back.
fn start(&self, cx: &mut Context<Self>) -> Task<()> {
let store = Arc::clone(&self.store);
let node_runtime = Arc::clone(&self.node_runtime);
let node_runtime = self.node_runtime.clone();
let rt = self.rt.clone();
let stopped = Arc::clone(&self.stopped);
cx.spawn(async move |this, cx| {
let Some(runtime) = node_runtime.lock().unwrap().clone() else {
let Some(runtime) = node_runtime.get() else {
this.update(cx, |this, cx| {
this.phase = Phase::Failed(
"P2P is not running, so this node cannot hand its revocation to \
@@ -306,7 +305,7 @@ impl TeardownScreen {
// go before the delete: a node still answering every ALPN against a
// database file that no longer exists is the state this ordering
// exists to avoid.
*self.node_runtime.lock().unwrap() = None;
self.node_runtime.set(None);
let canceled = self.job_runner.cancel_all();
if canceled > 0 {
log::info!("Teardown: canceled {canceled} in-flight job(s)");