diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-21 11:11:49 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-21 11:14:30 +0100 |
| commit | 25e58e52624210f5852a9183495821526add5928 (patch) | |
| tree | c53deb3b5e4a6becf34feb1b53c099259bf354ed /src | |
| parent | d4bc948bfd06a8d61b3deb072db8a70b5ef8a775 (diff) | |
fix: use relays & git servers from all maintainer
but other details from trusted maintainer.
This maximises the likelihood that all git servers and relays
have the correct state.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/client.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/lib/client.rs b/src/lib/client.rs index 3f2ae68..9eef777 100644 --- a/src/lib/client.rs +++ b/src/lib/client.rs | |||
| @@ -858,6 +858,8 @@ pub async fn save_event_in_global_cache( | |||
| 858 | } | 858 | } |
| 859 | } | 859 | } |
| 860 | 860 | ||
| 861 | // use annoucement from trusted maintainer but recursively add maintainers, git | ||
| 862 | // servers and relays | ||
| 861 | pub async fn get_repo_ref_from_cache( | 863 | pub async fn get_repo_ref_from_cache( |
| 862 | git_repo_path: Option<&Path>, | 864 | git_repo_path: Option<&Path>, |
| 863 | repo_coordinate: &Nip19Coordinate, | 865 | repo_coordinate: &Nip19Coordinate, |
| @@ -907,7 +909,8 @@ pub async fn get_repo_ref_from_cache( | |||
| 907 | repo_events.sort_by_key(|e| e.created_at); | 909 | repo_events.sort_by_key(|e| e.created_at); |
| 908 | let repo_ref = RepoRef::try_from(( | 910 | let repo_ref = RepoRef::try_from(( |
| 909 | repo_events | 911 | repo_events |
| 910 | .first() | 912 | .iter() |
| 913 | .find(|e| e.pubkey == repo_coordinate.public_key) | ||
| 911 | .context("no repo announcement event found at specified Nip19Coordinates. if you are the repository maintainer consider running `ngit init` to create one")? | 914 | .context("no repo announcement event found at specified Nip19Coordinates. if you are the repository maintainer consider running `ngit init` to create one")? |
| 912 | .clone(), | 915 | .clone(), |
| 913 | Some(repo_coordinate.public_key), | 916 | Some(repo_coordinate.public_key), |
| @@ -930,10 +933,24 @@ pub async fn get_repo_ref_from_cache( | |||
| 930 | } | 933 | } |
| 931 | } | 934 | } |
| 932 | 935 | ||
| 936 | // use relays and git servers from all maintainer announcement event | ||
| 937 | let mut relays: HashSet<RelayUrl> = HashSet::from_iter(repo_ref.relays.iter().cloned()); | ||
| 938 | let mut git_servers: HashSet<String> = HashSet::from_iter(repo_ref.git_server.iter().cloned()); | ||
| 939 | for m in &maintainers { | ||
| 940 | if let Some(event) = repo_events.iter().find(|e| e.pubkey == *m) { | ||
| 941 | if let Ok(m_repo_ref) = RepoRef::try_from((event.clone(), None)) { | ||
| 942 | relays.extend(m_repo_ref.relays); | ||
| 943 | git_servers.extend(m_repo_ref.git_server); | ||
| 944 | } | ||
| 945 | } | ||
| 946 | } | ||
| 947 | |||
| 933 | Ok(RepoRef { | 948 | Ok(RepoRef { |
| 934 | // use all maintainers from all events found, not just maintainers in the most | 949 | // use all maintainers from all events found, not just maintainers in the most |
| 935 | // recent event | 950 | // recent event |
| 936 | maintainers: maintainers.iter().copied().collect::<Vec<PublicKey>>(), | 951 | maintainers: maintainers.iter().copied().collect::<Vec<PublicKey>>(), |
| 952 | relays: relays.into_iter().collect(), | ||
| 953 | git_server: git_servers.into_iter().collect(), | ||
| 937 | events, | 954 | events, |
| 938 | ..repo_ref | 955 | ..repo_ref |
| 939 | }) | 956 | }) |