diff options
| -rw-r--r-- | src/discovery.rs | 13 | ||||
| -rw-r--r-- | src/main.rs | 8 |
2 files changed, 12 insertions, 9 deletions
diff --git a/src/discovery.rs b/src/discovery.rs index 430509d..fa2a198 100644 --- a/src/discovery.rs +++ b/src/discovery.rs | |||
| @@ -17,16 +17,13 @@ pub struct DiscoveredRepo { | |||
| 17 | pub async fn discover_repos_from_relays( | 17 | pub async fn discover_repos_from_relays( |
| 18 | client: &nostr_sdk::Client, | 18 | client: &nostr_sdk::Client, |
| 19 | npubs: &[PublicKey], | 19 | npubs: &[PublicKey], |
| 20 | relay_urls: &[String], | 20 | index_relays: &[String], |
| 21 | all_relay_urls: &[String], | ||
| 21 | ) -> Result<Vec<DiscoveredRepo>> { | 22 | ) -> Result<Vec<DiscoveredRepo>> { |
| 22 | for url in relay_urls { | 23 | for url in all_relay_urls { |
| 23 | if let Err(e) = client.add_relay(url).await { | 24 | let _ = client.add_relay(url).await; |
| 24 | tracing::warn!(relay = %url, error = %e, "failed to add relay"); | ||
| 25 | continue; | ||
| 26 | } | ||
| 27 | } | 25 | } |
| 28 | client.connect().await; | 26 | client.connect().await; |
| 29 | |||
| 30 | client | 27 | client |
| 31 | .wait_for_connection(std::time::Duration::from_secs(5)) | 28 | .wait_for_connection(std::time::Duration::from_secs(5)) |
| 32 | .await; | 29 | .await; |
| @@ -40,7 +37,7 @@ pub async fn discover_repos_from_relays( | |||
| 40 | .limit(50); | 37 | .limit(50); |
| 41 | 38 | ||
| 42 | let events = client | 39 | let events = client |
| 43 | .fetch_events(filter, std::time::Duration::from_secs(30)) | 40 | .fetch_events_from(index_relays, filter, std::time::Duration::from_secs(30)) |
| 44 | .await | 41 | .await |
| 45 | .context("failed to fetch events from relays")?; | 42 | .context("failed to fetch events from relays")?; |
| 46 | 43 | ||
diff --git a/src/main.rs b/src/main.rs index c7fa23a..d28fbe2 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -142,6 +142,7 @@ async fn run_daemon(config: config::ResolvedConfig, db: db::MirrorDb) -> Result< | |||
| 142 | let healthy = Arc::new(healthy); | 142 | let healthy = Arc::new(healthy); |
| 143 | 143 | ||
| 144 | let relay_urls = config.relay_urls(); | 144 | let relay_urls = config.relay_urls(); |
| 145 | let index_relays = config.discovery.index_relays.clone(); | ||
| 145 | let nostr_client = build_nostr_client(&relay_urls); | 146 | let nostr_client = build_nostr_client(&relay_urls); |
| 146 | nostr_client.connect().await; | 147 | nostr_client.connect().await; |
| 147 | 148 | ||
| @@ -149,6 +150,7 @@ async fn run_daemon(config: config::ResolvedConfig, db: db::MirrorDb) -> Result< | |||
| 149 | let nostr_mirror = nostr_mirror::NostrMirror::new(nostr_client.clone()); | 150 | let nostr_mirror = nostr_mirror::NostrMirror::new(nostr_client.clone()); |
| 150 | 151 | ||
| 151 | let nip46_client_ref: Option<Arc<nip46::Nip46Client>> = nip46_client.clone(); | 152 | let nip46_client_ref: Option<Arc<nip46::Nip46Client>> = nip46_client.clone(); |
| 153 | let index_relays_ref = Arc::new(index_relays); | ||
| 152 | 154 | ||
| 153 | let mut interval = tokio::time::interval(std::time::Duration::from_secs( | 155 | let mut interval = tokio::time::interval(std::time::Duration::from_secs( |
| 154 | config.discovery.poll_interval_secs, | 156 | config.discovery.poll_interval_secs, |
| @@ -168,6 +170,7 @@ async fn run_daemon(config: config::ResolvedConfig, db: db::MirrorDb) -> Result< | |||
| 168 | &config, | 170 | &config, |
| 169 | &db, | 171 | &db, |
| 170 | &nostr_client, | 172 | &nostr_client, |
| 173 | &index_relays_ref, | ||
| 171 | &mirror, | 174 | &mirror, |
| 172 | &nostr_mirror, | 175 | &nostr_mirror, |
| 173 | &healthy, | 176 | &healthy, |
| @@ -197,6 +200,7 @@ async fn mirror_cycle( | |||
| 197 | config: &Arc<config::ResolvedConfig>, | 200 | config: &Arc<config::ResolvedConfig>, |
| 198 | db: &Arc<db::MirrorDb>, | 201 | db: &Arc<db::MirrorDb>, |
| 199 | nostr_client: &nostr_sdk::Client, | 202 | nostr_client: &nostr_sdk::Client, |
| 203 | index_relays: &Arc<Vec<String>>, | ||
| 200 | mirror: &git_mirror::GitMirror, | 204 | mirror: &git_mirror::GitMirror, |
| 201 | nostr_mirror: &nostr_mirror::NostrMirror, | 205 | nostr_mirror: &nostr_mirror::NostrMirror, |
| 202 | servers: &Arc<Vec<health::GraspServer>>, | 206 | servers: &Arc<Vec<health::GraspServer>>, |
| @@ -205,7 +209,7 @@ async fn mirror_cycle( | |||
| 205 | tracing::info!("starting mirror cycle"); | 209 | tracing::info!("starting mirror cycle"); |
| 206 | 210 | ||
| 207 | let relay_urls = config.relay_urls(); | 211 | let relay_urls = config.relay_urls(); |
| 208 | let repos = discovery::discover_repos_from_relays(nostr_client, &config.npubs, &relay_urls) | 212 | let repos = discovery::discover_repos_from_relays(nostr_client, &config.npubs, index_relays, &relay_urls) |
| 209 | .await?; | 213 | .await?; |
| 210 | 214 | ||
| 211 | tracing::info!(count = repos.len(), "discovered repos"); | 215 | tracing::info!(count = repos.len(), "discovered repos"); |
| @@ -337,6 +341,7 @@ async fn run_mirror_once(config: config::ResolvedConfig, db: db::MirrorDb) -> Re | |||
| 337 | .collect(); | 341 | .collect(); |
| 338 | 342 | ||
| 339 | let relay_urls = config.relay_urls(); | 343 | let relay_urls = config.relay_urls(); |
| 344 | let index_relays = Arc::new(config.discovery.index_relays.clone()); | ||
| 340 | let nostr_client = build_nostr_client(&relay_urls); | 345 | let nostr_client = build_nostr_client(&relay_urls); |
| 341 | nostr_client.connect().await; | 346 | nostr_client.connect().await; |
| 342 | 347 | ||
| @@ -348,6 +353,7 @@ async fn run_mirror_once(config: config::ResolvedConfig, db: db::MirrorDb) -> Re | |||
| 348 | &config, | 353 | &config, |
| 349 | &db, | 354 | &db, |
| 350 | &nostr_client, | 355 | &nostr_client, |
| 356 | &index_relays, | ||
| 351 | &mirror, | 357 | &mirror, |
| 352 | &nostr_mirror, | 358 | &nostr_mirror, |
| 353 | &healthy, | 359 | &healthy, |