diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2022-04-21 03:36:10 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-04-21 03:36:10 +0000 |
commit | bb6d978c314f9b1195c4bb55a7ebaad24eb1c7a7 (patch) | |
tree | 0855ec6e46efe0c57bb04dc10f014b9bea5a1b59 | |
parent | 176a895b43f968d15b3013aad2fe88dc02fccdc6 (diff) | |
parent | 0bbc4ee2208c95fd71adcbd68d4299bdf0f74811 (diff) | |
download | DnsResolver-bb6d978c314f9b1195c4bb55a7ebaad24eb1c7a7.tar.gz |
Merge "Fix lints from Rust 1.60" am: 0bbc4ee220
Original change: https://android-review.googlesource.com/c/platform/packages/modules/DnsResolver/+/2068049
Change-Id: I84f86f37ca52df605d211d927ab28bd6e259d8b5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | doh/config.rs | 26 | ||||
-rw-r--r-- | doh/connection/driver.rs | 15 | ||||
-rw-r--r-- | doh/dispatcher/driver.rs | 2 | ||||
-rw-r--r-- | doh/dispatcher/mod.rs | 5 | ||||
-rw-r--r-- | doh/network/driver.rs | 12 |
5 files changed, 25 insertions, 35 deletions
diff --git a/doh/config.rs b/doh/config.rs index 9d2a25ae..1f91a151 100644 --- a/doh/config.rs +++ b/doh/config.rs @@ -137,7 +137,7 @@ impl Cache { /// Behaves as `Config::from_cert_path`, but with a cache. /// If any object previously given out by this cache is still live, /// 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 if let Some(config) = self.state.read().unwrap().get_config(key) { return Ok(config); @@ -191,9 +191,9 @@ fn create_quiche_config() { fn shared_cache() { let cache_a = Cache::new(); 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); - 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); } @@ -203,11 +203,11 @@ fn different_keys() { 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_c = Key { cert_path: Some("a".to_string()), max_idle_timeout: 5000 }; - let config_a = cache.from_key(&key_a).unwrap(); - let config_b = cache.from_key(&key_b).unwrap(); - let _config_b = cache.from_key(&key_b).unwrap(); - let config_c = cache.from_key(&key_c).unwrap(); - let _config_c = cache.from_key(&key_c).unwrap(); + let config_a = cache.get(&key_a).unwrap(); + let config_b = cache.get(&key_b).unwrap(); + let _config_b = cache.get(&key_b).unwrap(); + let config_c = cache.get(&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_b.0), 2); @@ -222,9 +222,9 @@ fn lifetimes() { let cache = Cache::new(); 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 config_none = cache.from_key(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); - let config_a = cache.from_key(&key_a).unwrap(); - let config_b = cache.from_key(&key_b).unwrap(); + let config_none = cache.get(&Key { cert_path: None, max_idle_timeout: 1000 }).unwrap(); + let config_a = cache.get(&key_a).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 // thing keeping them alive. @@ -232,7 +232,7 @@ fn lifetimes() { 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. - 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); // config_b was most recently created, so it should have a keep-alive @@ -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 // 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); // We broke None, but "a" and "b" should still both be alive. Check that diff --git a/doh/connection/driver.rs b/doh/connection/driver.rs index 50d0928b..7eab52cd 100644 --- a/doh/connection/driver.rs +++ b/doh/connection/driver.rs @@ -264,15 +264,12 @@ impl H3Driver { async fn drive(mut self) -> Result<Driver> { let _ = self.driver.status_tx.send(Status::H3); loop { - match self.drive_once().await { - Err(e) => { - let _ = self - .driver - .status_tx - .send(Status::Dead { session: self.driver.quiche_conn.session() }); - return Err(e); - } - Ok(()) => (), + if let Err(e) = self.drive_once().await { + let _ = self + .driver + .status_tx + .send(Status::Dead { session: self.driver.quiche_conn.session() }); + return Err(e) } } } diff --git a/doh/dispatcher/driver.rs b/doh/dispatcher/driver.rs index 59e6f3dc..5e0359cb 100644 --- a/doh/dispatcher/driver.rs +++ b/doh/dispatcher/driver.rs @@ -118,7 +118,7 @@ impl Driver { cert_path: info.cert_path.clone(), max_idle_timeout: info.idle_timeout_ms, }; - let config = self.config_cache.from_key(&key)?; + let config = self.config_cache.get(&key)?; vacant.insert( Network::new(info, config, self.validation.clone(), self.tagger.clone()) .await?, diff --git a/doh/dispatcher/mod.rs b/doh/dispatcher/mod.rs index b63f97fb..18439c8e 100644 --- a/doh/dispatcher/mod.rs +++ b/doh/dispatcher/mod.rs @@ -87,10 +87,7 @@ impl Dispatcher { .build()?; let join_handle = runtime.spawn(async { let result = Driver::new(cmd_receiver, validation, tagger).drive().await; - match result { - Err(ref e) => error!("Dispatcher driver exited due to {:?}", e), - Ok(()) => (), - } + if let Err(ref e) = result { error!("Dispatcher driver exited due to {:?}", e) } result }); Ok(Dispatcher { cmd_sender, join_handle, runtime }) diff --git a/doh/network/driver.rs b/doh/network/driver.rs index 375ac2c1..b0f59392 100644 --- a/doh/network/driver.rs +++ b/doh/network/driver.rs @@ -113,14 +113,10 @@ impl Driver { pub async fn drive(mut self) -> Result<()> { while let Some(cmd) = self.command_rx.recv().await { match cmd { - Command::Probe(duration) => match self.probe(duration).await { - Err(e) => self.status_tx.send(Status::Failed(Arc::new(e)))?, - Ok(()) => (), - }, - Command::Query(query) => match self.send_query(query).await { - Err(e) => debug!("Unable to send query: {:?}", e), - Ok(()) => (), - }, + Command::Probe(duration) => + if let Err(e) = self.probe(duration).await { self.status_tx.send(Status::Failed(Arc::new(e)))? }, + Command::Query(query) => + if let Err(e) = self.send_query(query).await { debug!("Unable to send query: {:?}", e) }, }; } Ok(()) |