Loading doh/config.rs +13 −13 Original line number Original line Diff line number Diff line Loading @@ -137,7 +137,7 @@ impl Cache { /// Behaves as `Config::from_cert_path`, but with a cache. /// Behaves as `Config::from_cert_path`, but with a cache. /// If any object previously given out by this cache is still live, /// If any object previously given out by this cache is still live, /// a duplicate will not be made. /// a duplicate will not be made. pub fn from_key(&self, key: &Key) -> Result<Config> { pub fn get(&self, key: &Key) -> Result<Config> { // Fast path - read-only access to state retrieves config // Fast path - read-only access to state retrieves config if let Some(config) = self.state.read().unwrap().get_config(key) { if let Some(config) = self.state.read().unwrap().get_config(key) { return Ok(config); return Ok(config); Loading Loading @@ -191,9 +191,9 @@ fn create_quiche_config() { fn shared_cache() { fn shared_cache() { let cache_a = Cache::new(); let cache_a = Cache::new(); let cache_b = cache_a.clone(); let cache_b = cache_a.clone(); let config_a = cache_a.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let config_a = cache_a.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 2); assert_eq!(Arc::strong_count(&config_a.0), 2); let _config_b = cache_b.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let _config_b = cache_b.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 3); assert_eq!(Arc::strong_count(&config_a.0), 3); } } Loading @@ -203,11 +203,11 @@ fn different_keys() { let key_a = Key { cert_path: None, max_idle_timeout: 1000 }; let key_a = Key { cert_path: None, max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_c = Key { cert_path: Some("a".to_string()), max_idle_timeout: 5000 }; let key_c = Key { cert_path: Some("a".to_string()), max_idle_timeout: 5000 }; let config_a = cache.from_key(&key_a).unwrap(); let config_a = cache.get(&key_a).unwrap(); let config_b = cache.from_key(&key_b).unwrap(); let config_b = cache.get(&key_b).unwrap(); let _config_b = cache.from_key(&key_b).unwrap(); let _config_b = cache.get(&key_b).unwrap(); let config_c = cache.from_key(&key_c).unwrap(); let config_c = cache.get(&key_c).unwrap(); let _config_c = cache.from_key(&key_c).unwrap(); let _config_c = cache.get(&key_c).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 1); assert_eq!(Arc::strong_count(&config_a.0), 1); assert_eq!(Arc::strong_count(&config_b.0), 2); assert_eq!(Arc::strong_count(&config_b.0), 2); Loading @@ -222,9 +222,9 @@ fn lifetimes() { let cache = Cache::new(); let cache = Cache::new(); let key_a = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_a = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("b".to_string()), max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("b".to_string()), max_idle_timeout: 1000 }; let config_none = cache.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let config_none = cache.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let config_a = cache.from_key(&key_a).unwrap(); let config_a = cache.get(&key_a).unwrap(); let config_b = cache.from_key(&key_b).unwrap(); let config_b = cache.get(&key_b).unwrap(); // The first two we created should have a strong count of one - those handles are the only // The first two we created should have a strong count of one - those handles are the only // thing keeping them alive. // thing keeping them alive. Loading @@ -232,7 +232,7 @@ fn lifetimes() { assert_eq!(Arc::strong_count(&config_a.0), 1); assert_eq!(Arc::strong_count(&config_a.0), 1); // If we try to get another handle we already have, it should be the same one. // If we try to get another handle we already have, it should be the same one. let _config_a2 = cache.from_key(&key_a).unwrap(); let _config_a2 = cache.get(&key_a).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 2); assert_eq!(Arc::strong_count(&config_a.0), 2); // config_b was most recently created, so it should have a keep-alive // config_b was most recently created, so it should have a keep-alive Loading @@ -256,7 +256,7 @@ fn lifetimes() { // If we try to get a config which is still kept alive by the cache, we should get the same // If we try to get a config which is still kept alive by the cache, we should get the same // one. // one. let _config_b2 = cache.from_key(&key_b).unwrap(); let _config_b2 = cache.get(&key_b).unwrap(); assert_eq!(config_b_weak.strong_count(), 2); assert_eq!(config_b_weak.strong_count(), 2); // We broke None, but "a" and "b" should still both be alive. Check that // We broke None, but "a" and "b" should still both be alive. Check that Loading doh/connection/driver.rs +6 −9 Original line number Original line Diff line number Diff line Loading @@ -264,15 +264,12 @@ impl H3Driver { async fn drive(mut self) -> Result<Driver> { async fn drive(mut self) -> Result<Driver> { let _ = self.driver.status_tx.send(Status::H3); let _ = self.driver.status_tx.send(Status::H3); loop { loop { match self.drive_once().await { if let Err(e) = self.drive_once().await { Err(e) => { let _ = self let _ = self .driver .driver .status_tx .status_tx .send(Status::Dead { session: self.driver.quiche_conn.session() }); .send(Status::Dead { session: self.driver.quiche_conn.session() }); return Err(e); return Err(e) } Ok(()) => (), } } } } } } Loading doh/dispatcher/driver.rs +1 −1 Original line number Original line Diff line number Diff line Loading @@ -118,7 +118,7 @@ impl Driver { cert_path: info.cert_path.clone(), cert_path: info.cert_path.clone(), max_idle_timeout: info.idle_timeout_ms, max_idle_timeout: info.idle_timeout_ms, }; }; let config = self.config_cache.from_key(&key)?; let config = self.config_cache.get(&key)?; vacant.insert( vacant.insert( Network::new(info, config, self.validation.clone(), self.tagger.clone()) Network::new(info, config, self.validation.clone(), self.tagger.clone()) .await?, .await?, Loading doh/dispatcher/mod.rs +1 −4 Original line number Original line Diff line number Diff line Loading @@ -87,10 +87,7 @@ impl Dispatcher { .build()?; .build()?; let join_handle = runtime.spawn(async { let join_handle = runtime.spawn(async { let result = Driver::new(cmd_receiver, validation, tagger).drive().await; let result = Driver::new(cmd_receiver, validation, tagger).drive().await; match result { if let Err(ref e) = result { error!("Dispatcher driver exited due to {:?}", e) } Err(ref e) => error!("Dispatcher driver exited due to {:?}", e), Ok(()) => (), } result result }); }); Ok(Dispatcher { cmd_sender, join_handle, runtime }) Ok(Dispatcher { cmd_sender, join_handle, runtime }) Loading doh/network/driver.rs +4 −8 Original line number Original line Diff line number Diff line Loading @@ -113,14 +113,10 @@ impl Driver { pub async fn drive(mut self) -> Result<()> { pub async fn drive(mut self) -> Result<()> { while let Some(cmd) = self.command_rx.recv().await { while let Some(cmd) = self.command_rx.recv().await { match cmd { match cmd { Command::Probe(duration) => match self.probe(duration).await { Command::Probe(duration) => Err(e) => self.status_tx.send(Status::Failed(Arc::new(e)))?, if let Err(e) = self.probe(duration).await { self.status_tx.send(Status::Failed(Arc::new(e)))? }, Ok(()) => (), Command::Query(query) => }, if let Err(e) = self.send_query(query).await { debug!("Unable to send query: {:?}", e) }, Command::Query(query) => match self.send_query(query).await { Err(e) => debug!("Unable to send query: {:?}", e), Ok(()) => (), }, }; }; } } Ok(()) Ok(()) Loading Loading
doh/config.rs +13 −13 Original line number Original line Diff line number Diff line Loading @@ -137,7 +137,7 @@ impl Cache { /// Behaves as `Config::from_cert_path`, but with a cache. /// Behaves as `Config::from_cert_path`, but with a cache. /// If any object previously given out by this cache is still live, /// If any object previously given out by this cache is still live, /// a duplicate will not be made. /// a duplicate will not be made. pub fn from_key(&self, key: &Key) -> Result<Config> { pub fn get(&self, key: &Key) -> Result<Config> { // Fast path - read-only access to state retrieves config // Fast path - read-only access to state retrieves config if let Some(config) = self.state.read().unwrap().get_config(key) { if let Some(config) = self.state.read().unwrap().get_config(key) { return Ok(config); return Ok(config); Loading Loading @@ -191,9 +191,9 @@ fn create_quiche_config() { fn shared_cache() { fn shared_cache() { let cache_a = Cache::new(); let cache_a = Cache::new(); let cache_b = cache_a.clone(); let cache_b = cache_a.clone(); let config_a = cache_a.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let config_a = cache_a.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 2); assert_eq!(Arc::strong_count(&config_a.0), 2); let _config_b = cache_b.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let _config_b = cache_b.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 3); assert_eq!(Arc::strong_count(&config_a.0), 3); } } Loading @@ -203,11 +203,11 @@ fn different_keys() { let key_a = Key { cert_path: None, max_idle_timeout: 1000 }; let key_a = Key { cert_path: None, max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_c = Key { cert_path: Some("a".to_string()), max_idle_timeout: 5000 }; let key_c = Key { cert_path: Some("a".to_string()), max_idle_timeout: 5000 }; let config_a = cache.from_key(&key_a).unwrap(); let config_a = cache.get(&key_a).unwrap(); let config_b = cache.from_key(&key_b).unwrap(); let config_b = cache.get(&key_b).unwrap(); let _config_b = cache.from_key(&key_b).unwrap(); let _config_b = cache.get(&key_b).unwrap(); let config_c = cache.from_key(&key_c).unwrap(); let config_c = cache.get(&key_c).unwrap(); let _config_c = cache.from_key(&key_c).unwrap(); let _config_c = cache.get(&key_c).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 1); assert_eq!(Arc::strong_count(&config_a.0), 1); assert_eq!(Arc::strong_count(&config_b.0), 2); assert_eq!(Arc::strong_count(&config_b.0), 2); Loading @@ -222,9 +222,9 @@ fn lifetimes() { let cache = Cache::new(); let cache = Cache::new(); let key_a = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_a = Key { cert_path: Some("a".to_string()), max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("b".to_string()), max_idle_timeout: 1000 }; let key_b = Key { cert_path: Some("b".to_string()), max_idle_timeout: 1000 }; let config_none = cache.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let config_none = cache.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); let config_a = cache.from_key(&key_a).unwrap(); let config_a = cache.get(&key_a).unwrap(); let config_b = cache.from_key(&key_b).unwrap(); let config_b = cache.get(&key_b).unwrap(); // The first two we created should have a strong count of one - those handles are the only // The first two we created should have a strong count of one - those handles are the only // thing keeping them alive. // thing keeping them alive. Loading @@ -232,7 +232,7 @@ fn lifetimes() { assert_eq!(Arc::strong_count(&config_a.0), 1); assert_eq!(Arc::strong_count(&config_a.0), 1); // If we try to get another handle we already have, it should be the same one. // If we try to get another handle we already have, it should be the same one. let _config_a2 = cache.from_key(&key_a).unwrap(); let _config_a2 = cache.get(&key_a).unwrap(); assert_eq!(Arc::strong_count(&config_a.0), 2); assert_eq!(Arc::strong_count(&config_a.0), 2); // config_b was most recently created, so it should have a keep-alive // config_b was most recently created, so it should have a keep-alive Loading @@ -256,7 +256,7 @@ fn lifetimes() { // If we try to get a config which is still kept alive by the cache, we should get the same // If we try to get a config which is still kept alive by the cache, we should get the same // one. // one. let _config_b2 = cache.from_key(&key_b).unwrap(); let _config_b2 = cache.get(&key_b).unwrap(); assert_eq!(config_b_weak.strong_count(), 2); assert_eq!(config_b_weak.strong_count(), 2); // We broke None, but "a" and "b" should still both be alive. Check that // We broke None, but "a" and "b" should still both be alive. Check that Loading
doh/connection/driver.rs +6 −9 Original line number Original line Diff line number Diff line Loading @@ -264,15 +264,12 @@ impl H3Driver { async fn drive(mut self) -> Result<Driver> { async fn drive(mut self) -> Result<Driver> { let _ = self.driver.status_tx.send(Status::H3); let _ = self.driver.status_tx.send(Status::H3); loop { loop { match self.drive_once().await { if let Err(e) = self.drive_once().await { Err(e) => { let _ = self let _ = self .driver .driver .status_tx .status_tx .send(Status::Dead { session: self.driver.quiche_conn.session() }); .send(Status::Dead { session: self.driver.quiche_conn.session() }); return Err(e); return Err(e) } Ok(()) => (), } } } } } } Loading
doh/dispatcher/driver.rs +1 −1 Original line number Original line Diff line number Diff line Loading @@ -118,7 +118,7 @@ impl Driver { cert_path: info.cert_path.clone(), cert_path: info.cert_path.clone(), max_idle_timeout: info.idle_timeout_ms, max_idle_timeout: info.idle_timeout_ms, }; }; let config = self.config_cache.from_key(&key)?; let config = self.config_cache.get(&key)?; vacant.insert( vacant.insert( Network::new(info, config, self.validation.clone(), self.tagger.clone()) Network::new(info, config, self.validation.clone(), self.tagger.clone()) .await?, .await?, Loading
doh/dispatcher/mod.rs +1 −4 Original line number Original line Diff line number Diff line Loading @@ -87,10 +87,7 @@ impl Dispatcher { .build()?; .build()?; let join_handle = runtime.spawn(async { let join_handle = runtime.spawn(async { let result = Driver::new(cmd_receiver, validation, tagger).drive().await; let result = Driver::new(cmd_receiver, validation, tagger).drive().await; match result { if let Err(ref e) = result { error!("Dispatcher driver exited due to {:?}", e) } Err(ref e) => error!("Dispatcher driver exited due to {:?}", e), Ok(()) => (), } result result }); }); Ok(Dispatcher { cmd_sender, join_handle, runtime }) Ok(Dispatcher { cmd_sender, join_handle, runtime }) Loading
doh/network/driver.rs +4 −8 Original line number Original line Diff line number Diff line Loading @@ -113,14 +113,10 @@ impl Driver { pub async fn drive(mut self) -> Result<()> { pub async fn drive(mut self) -> Result<()> { while let Some(cmd) = self.command_rx.recv().await { while let Some(cmd) = self.command_rx.recv().await { match cmd { match cmd { Command::Probe(duration) => match self.probe(duration).await { Command::Probe(duration) => Err(e) => self.status_tx.send(Status::Failed(Arc::new(e)))?, if let Err(e) = self.probe(duration).await { self.status_tx.send(Status::Failed(Arc::new(e)))? }, Ok(()) => (), Command::Query(query) => }, if let Err(e) = self.send_query(query).await { debug!("Unable to send query: {:?}", e) }, Command::Query(query) => match self.send_query(query).await { Err(e) => debug!("Unable to send query: {:?}", e), Ok(()) => (), }, }; }; } } Ok(()) Ok(()) Loading