Show which relays we are connected to on the relays page (crude still)

This commit is contained in:
Mike Dilger 2023-01-11 07:14:16 +13:00
parent 84854af90a
commit 5b6fb97889
4 changed files with 61 additions and 14 deletions

View File

@ -52,6 +52,9 @@ pub struct Globals {
/// All nostr relay records we have /// All nostr relay records we have
pub relays: RwLock<HashMap<Url, DbRelay>>, pub relays: RwLock<HashMap<Url, DbRelay>>,
/// The relays we are currently connected to
pub relays_watching: RwLock<Vec<Url>>,
/// Whether or not we are shutting down. For the UI (minions will be signaled and /// Whether or not we are shutting down. For the UI (minions will be signaled and
/// waited for by the overlord) /// waited for by the overlord)
pub shutting_down: AtomicBool, pub shutting_down: AtomicBool,
@ -103,6 +106,7 @@ lazy_static! {
desired_events: RwLock::new(HashMap::new()), desired_events: RwLock::new(HashMap::new()),
people: RwLock::new(People::new()), people: RwLock::new(People::new()),
relays: RwLock::new(HashMap::new()), relays: RwLock::new(HashMap::new()),
relays_watching: RwLock::new(Vec::new()),
shutting_down: AtomicBool::new(false), shutting_down: AtomicBool::new(false),
settings: RwLock::new(Settings::default()), settings: RwLock::new(Settings::default()),
signer: RwLock::new(Signer::default()), signer: RwLock::new(Signer::default()),

View File

@ -283,7 +283,11 @@ impl Minion {
}; };
let followed_pubkeys = GLOBALS.people.read().await.get_followed_pubkeys(); let followed_pubkeys = GLOBALS.people.read().await.get_followed_pubkeys();
tracing::debug!("Following {} people at {}", followed_pubkeys.len(), &self.url); tracing::debug!(
"Following {} people at {}",
followed_pubkeys.len(),
&self.url
);
// Compute how far to look back // Compute how far to look back
let (feed_since, special_since) = { let (feed_since, special_since) = {

View File

@ -27,9 +27,6 @@ pub struct Overlord {
// Map from minion task::Id to Url // Map from minion task::Id to Url
minions_task_url: HashMap<task::Id, Url>, minions_task_url: HashMap<task::Id, Url>,
// Vec of urls our minions are handling
urls_watching: Vec<Url>,
} }
impl Overlord { impl Overlord {
@ -40,7 +37,6 @@ impl Overlord {
inbox, inbox,
minions: task::JoinSet::new(), minions: task::JoinSet::new(),
minions_task_url: HashMap::new(), minions_task_url: HashMap::new(),
urls_watching: Vec::new(),
} }
} }
@ -262,7 +258,7 @@ impl Overlord {
let abort_handle = self.minions.spawn(async move { minion.handle().await }); let abort_handle = self.minions.spawn(async move { minion.handle().await });
let id = abort_handle.id(); let id = abort_handle.id();
self.minions_task_url.insert(id, url.clone()); self.minions_task_url.insert(id, url.clone());
self.urls_watching.push(url.clone()); GLOBALS.relays_watching.write().await.push(url.clone());
Ok(()) Ok(())
} }
@ -325,7 +321,11 @@ impl Overlord {
// Minion probably already logged failure in relay table // Minion probably already logged failure in relay table
// Remove from our urls_watching vec // Remove from our urls_watching vec
self.urls_watching.retain(|value| value != url); GLOBALS
.relays_watching
.write()
.await
.retain(|value| value != url);
// Remove from our hashmap // Remove from our hashmap
self.minions_task_url.remove(&id); self.minions_task_url.remove(&id);
@ -342,7 +342,11 @@ impl Overlord {
tracing::info!("Relay Task {} completed", &url); tracing::info!("Relay Task {} completed", &url);
// Remove from our urls_watching vec // Remove from our urls_watching vec
self.urls_watching.retain(|value| value != url); GLOBALS
.relays_watching
.write()
.await
.retain(|value| value != url);
// Remove from our hashmap // Remove from our hashmap
self.minions_task_url.remove(&id); self.minions_task_url.remove(&id);
@ -497,7 +501,12 @@ impl Overlord {
for person_relay in person_relays.iter() { for person_relay in person_relays.iter() {
// Start a minion for this relay if there is none // Start a minion for this relay if there is none
if !self.urls_watching.contains(&Url::new(&person_relay.relay)) { if !GLOBALS
.relays_watching
.read()
.await
.contains(&Url::new(&person_relay.relay))
{
self.start_minion(person_relay.relay.clone()).await?; self.start_minion(person_relay.relay.clone()).await?;
} }
@ -543,7 +552,7 @@ impl Overlord {
} }
// If we don't have such a minion, start one // If we don't have such a minion, start one
if !self.urls_watching.contains(url) { if !GLOBALS.relays_watching.read().await.contains(url) {
// Start a minion // Start a minion
self.start_minion(url.inner().to_owned()).await?; self.start_minion(url.inner().to_owned()).await?;
} }
@ -668,7 +677,12 @@ impl Overlord {
for relay in relays { for relay in relays {
// Start a minion for it, if there is none // Start a minion for it, if there is none
if !self.urls_watching.contains(&Url::new(&relay.url)) { if !GLOBALS
.relays_watching
.read()
.await
.contains(&Url::new(&relay.url))
{
self.start_minion(relay.url.clone()).await?; self.start_minion(relay.url.clone()).await?;
} }
@ -776,7 +790,12 @@ impl Overlord {
for relay in relays { for relay in relays {
// Start a minion for it, if there is none // Start a minion for it, if there is none
if !self.urls_watching.contains(&Url::new(&relay.url)) { if !GLOBALS
.relays_watching
.read()
.await
.contains(&Url::new(&relay.url))
{
self.start_minion(relay.url.clone()).await?; self.start_minion(relay.url.clone()).await?;
} }
@ -849,7 +868,12 @@ impl Overlord {
for relay in relays { for relay in relays {
// Start a minion for it, if there is none // Start a minion for it, if there is none
if !self.urls_watching.contains(&Url::new(&relay.url)) { if !GLOBALS
.relays_watching
.read()
.await
.contains(&Url::new(&relay.url))
{
self.start_minion(relay.url.clone()).await?; self.start_minion(relay.url.clone()).await?;
} }
@ -884,7 +908,12 @@ impl Overlord {
for relay in relays { for relay in relays {
// Start a minion for it, if there is none // Start a minion for it, if there is none
if !self.urls_watching.contains(&Url::new(&relay.url)) { if !GLOBALS
.relays_watching
.read()
.await
.contains(&Url::new(&relay.url))
{
self.start_minion(relay.url.clone()).await?; self.start_minion(relay.url.clone()).await?;
} }

View File

@ -56,6 +56,16 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
ui.add_space(32.0); ui.add_space(32.0);
ui.heading("Connected to:");
for url in GLOBALS.relays_watching.blocking_read().iter() {
ui.label(url.inner());
}
ui.add_space(10.0);
ui.separator();
ui.add_space(10.0);
ui.with_layout(Layout::bottom_up(Align::Center), |ui| { ui.with_layout(Layout::bottom_up(Align::Center), |ui| {
if ui.button("SAVE CHANGES").clicked() { if ui.button("SAVE CHANGES").clicked() {
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::SaveRelays); let _ = GLOBALS.to_overlord.send(ToOverlordMessage::SaveRelays);