JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Add more aggressive key caching

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨5bc92ad

⁨giterated-daemon/src/keys.rs⁩ - ⁨697⁩ bytes
Raw
1 use std::collections::HashMap;
2
3 use anyhow::Error;
4 use giterated_models::model::instance::Instance;
5
6 #[derive(Default)]
7 pub struct PublicKeyCache {
8 pub keys: HashMap<Instance, String>,
9 }
10
11 impl PublicKeyCache {
12 pub async fn get(&mut self, instance: &Instance) -> Result<String, Error> {
13 if let Some(key) = self.keys.get(instance) {
14 return Ok(key.clone());
15 } else {
16 let key = reqwest::get(format!("https://{}/.giterated/pubkey.pem", instance.url))
17 .await?
18 .text()
19 .await?;
20
21 self.keys.insert(instance.clone(), key);
22
23 Ok(self.keys.get(instance).unwrap().clone())
24 }
25 }
26 }
27