mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-19 19:46:50 +00:00
Show which relays we are connected to on the relays page (crude still)
This commit is contained in:
parent
84854af90a
commit
5b6fb97889
@ -52,6 +52,9 @@ pub struct Globals {
|
||||
/// All nostr relay records we have
|
||||
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
|
||||
/// waited for by the overlord)
|
||||
pub shutting_down: AtomicBool,
|
||||
@ -103,6 +106,7 @@ lazy_static! {
|
||||
desired_events: RwLock::new(HashMap::new()),
|
||||
people: RwLock::new(People::new()),
|
||||
relays: RwLock::new(HashMap::new()),
|
||||
relays_watching: RwLock::new(Vec::new()),
|
||||
shutting_down: AtomicBool::new(false),
|
||||
settings: RwLock::new(Settings::default()),
|
||||
signer: RwLock::new(Signer::default()),
|
||||
|
@ -283,7 +283,11 @@ impl Minion {
|
||||
};
|
||||
|
||||
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
|
||||
let (feed_since, special_since) = {
|
||||
|
@ -27,9 +27,6 @@ pub struct Overlord {
|
||||
|
||||
// Map from minion task::Id to Url
|
||||
minions_task_url: HashMap<task::Id, Url>,
|
||||
|
||||
// Vec of urls our minions are handling
|
||||
urls_watching: Vec<Url>,
|
||||
}
|
||||
|
||||
impl Overlord {
|
||||
@ -40,7 +37,6 @@ impl Overlord {
|
||||
inbox,
|
||||
minions: task::JoinSet::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 id = abort_handle.id();
|
||||
self.minions_task_url.insert(id, url.clone());
|
||||
self.urls_watching.push(url.clone());
|
||||
GLOBALS.relays_watching.write().await.push(url.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -325,7 +321,11 @@ impl Overlord {
|
||||
// Minion probably already logged failure in relay table
|
||||
|
||||
// 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
|
||||
self.minions_task_url.remove(&id);
|
||||
@ -342,7 +342,11 @@ impl Overlord {
|
||||
tracing::info!("Relay Task {} completed", &url);
|
||||
|
||||
// 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
|
||||
self.minions_task_url.remove(&id);
|
||||
@ -497,7 +501,12 @@ impl Overlord {
|
||||
|
||||
for person_relay in person_relays.iter() {
|
||||
// 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?;
|
||||
}
|
||||
|
||||
@ -543,7 +552,7 @@ impl Overlord {
|
||||
}
|
||||
|
||||
// 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
|
||||
self.start_minion(url.inner().to_owned()).await?;
|
||||
}
|
||||
@ -668,7 +677,12 @@ impl Overlord {
|
||||
|
||||
for relay in relays {
|
||||
// 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?;
|
||||
}
|
||||
|
||||
@ -776,7 +790,12 @@ impl Overlord {
|
||||
|
||||
for relay in relays {
|
||||
// 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?;
|
||||
}
|
||||
|
||||
@ -849,7 +868,12 @@ impl Overlord {
|
||||
|
||||
for relay in relays {
|
||||
// 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?;
|
||||
}
|
||||
|
||||
@ -884,7 +908,12 @@ impl Overlord {
|
||||
|
||||
for relay in relays {
|
||||
// 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?;
|
||||
}
|
||||
|
||||
|
@ -56,6 +56,16 @@ pub(super) fn update(app: &mut GossipUi, _ctx: &Context, _frame: &mut eframe::Fr
|
||||
|
||||
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| {
|
||||
if ui.button("SAVE CHANGES").clicked() {
|
||||
let _ = GLOBALS.to_overlord.send(ToOverlordMessage::SaveRelays);
|
||||
|
Loading…
Reference in New Issue
Block a user