.
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m19s

This commit is contained in:
2026-02-13 14:00:43 +07:00
parent ecd7f6aa9b
commit 7e4d42b967
3 changed files with 125 additions and 204 deletions

View File

@@ -1,107 +0,0 @@
use std::collections::{HashMap, HashSet};
use nostr_sdk::prelude::*;
/// Gossip
#[derive(Debug, Clone, Default)]
pub struct Gossip {
/// Gossip relays for each public key
relays: HashMap<PublicKey, HashSet<(RelayUrl, Option<RelayMetadata>)>>,
/// Messaging relays for each public key
messaging_relays: HashMap<PublicKey, HashSet<RelayUrl>>,
}
impl Gossip {
/// Get read relays for a given public key
pub fn read_relays(&self, public_key: &PublicKey) -> Vec<RelayUrl> {
self.relays
.get(public_key)
.map(|relays| {
relays
.iter()
.filter_map(|(url, metadata)| {
if metadata.is_none() || metadata == &Some(RelayMetadata::Read) {
Some(url.to_owned())
} else {
None
}
})
.collect()
})
.unwrap_or_default()
}
/// Get write relays for a given public key
pub fn write_relays(&self, public_key: &PublicKey) -> Vec<RelayUrl> {
self.relays
.get(public_key)
.map(|relays| {
relays
.iter()
.filter_map(|(url, metadata)| {
if metadata.is_none() || metadata == &Some(RelayMetadata::Write) {
Some(url.to_owned())
} else {
None
}
})
.collect()
})
.unwrap_or_default()
}
/// Insert gossip relays for a public key
pub fn insert_relays(&mut self, event: &Event) {
self.relays.entry(event.pubkey).or_default().extend(
event
.tags
.iter()
.filter_map(|tag| {
if let Some(TagStandard::RelayMetadata {
relay_url,
metadata,
}) = tag.clone().to_standardized()
{
Some((relay_url, metadata))
} else {
None
}
})
.take(3),
);
log::info!("Updating gossip relays for: {}", event.pubkey);
}
/// Get messaging relays for a given public key
pub fn messaging_relays(&self, public_key: &PublicKey) -> Vec<RelayUrl> {
self.messaging_relays
.get(public_key)
.cloned()
.unwrap_or_default()
.into_iter()
.collect()
}
/// Insert messaging relays for a public key
pub fn insert_messaging_relays(&mut self, event: &Event) {
self.messaging_relays
.entry(event.pubkey)
.or_default()
.extend(
event
.tags
.iter()
.filter_map(|tag| {
if let Some(TagStandard::Relay(url)) = tag.as_standardized() {
Some(url.to_owned())
} else {
None
}
})
.take(3),
);
log::info!("Updating messaging relays for: {}", event.pubkey);
}
}

View File

@@ -107,9 +107,16 @@ impl NostrRegistry {
let client = ClientBuilder::default()
.signer(signer.clone())
.gossip(NostrGossipMemory::unbounded())
.gossip_config(
GossipConfig::default()
.fetch_timeout(Duration::from_secs(TIMEOUT))
.sync_initial_timeout(Duration::from_secs(2))
.sync_idle_timeout(Duration::from_secs(TIMEOUT)),
)
.database(lmdb)
.automatic_authentication(false)
.verify_subscriptions(false)
.connect_timeout(Duration::from_secs(TIMEOUT))
.sleep_when_idle(SleepWhenIdle::Enabled {
timeout: Duration::from_secs(600),
})
@@ -174,6 +181,15 @@ impl NostrRegistry {
// Update the state
this.update(cx, |this, cx| {
this.set_connected(cx);
})?;
// Small delay
cx.background_executor()
.timer(Duration::from_millis(200))
.await;
// Update the state
this.update(cx, |this, cx| {
this.get_signer(cx);
})?;
@@ -655,8 +671,11 @@ impl NostrRegistry {
// Publish relay list event
let event = EventBuilder::relay_list(relay_list).sign(signer).await?;
let output = client.send_event(&event).broadcast().await?;
log::info!("Published relay list event: {:?}", output.id());
client
.send_event(&event)
.broadcast()
.ok_timeout(Duration::from_secs(TIMEOUT))
.await?;
// Construct the default metadata
let name = petname::petname(2, "-").unwrap_or("Cooper".to_string());
@@ -665,24 +684,33 @@ impl NostrRegistry {
// Publish metadata event
let event = EventBuilder::metadata(&metadata).sign(signer).await?;
let output = client.send_event(&event).broadcast().await?;
log::info!("Published metadata event: {:?}", output.id());
client
.send_event(&event)
.broadcast()
.ok_timeout(Duration::from_secs(TIMEOUT))
.await?;
// Construct the default contact list
let contacts = vec![Contact::new(PublicKey::parse(COOP_PUBKEY).unwrap())];
// Publish contact list event
let event = EventBuilder::contact_list(contacts).sign(signer).await?;
let output = client.send_event(&event).broadcast().await?;
log::info!("Published contact list event: {:?}", output.id());
client
.send_event(&event)
.broadcast()
.ok_timeout(Duration::from_secs(TIMEOUT))
.await?;
// Construct the default messaging relay list
let relays = default_messaging_relays();
// Publish messaging relay list event
let event = EventBuilder::nip17_relay_list(relays).sign(signer).await?;
let output = client.send_event(&event).to_nip65().await?;
log::info!("Published messaging relay list event: {:?}", output.id());
client
.send_event(&event)
.to_nip65()
.ok_timeout(Duration::from_secs(TIMEOUT))
.await?;
// Write user's credentials to the system keyring
write_credential.await?;