From d1863c3178a628ba56a79e54643fa725b188bc1e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 28 Feb 2023 14:51:28 +0000 Subject: [PATCH] hsclient state: Break out ServiceState::blank We're going to have another function which will want this. Leave a convenience closure to capture the runtime. --- crates/tor-hsclient/src/state.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/tor-hsclient/src/state.rs b/crates/tor-hsclient/src/state.rs index c27fbe6b3..57cf7e8e8 100644 --- a/crates/tor-hsclient/src/state.rs +++ b/crates/tor-hsclient/src/state.rs @@ -128,6 +128,16 @@ enum ServiceState { Dummy, } +impl ServiceState { + /// Make a new (blank) `ServiceState::Closed` + fn blank(runtime: &impl Runtime) -> Self { + ServiceState::Closed { + data: D::default(), + last_used: runtime.now(), + } + } +} + impl Services { /// Connect to a hidden service // We *do* drop guard. There is *one* await point, just after drop(guard). @@ -138,6 +148,8 @@ impl Services { isolation: Box, secret_keys: HsClientSecretKeys, ) -> Result { + let blank_state = || ServiceState::blank(&connector.runtime); + let mut guard = connector .services .lock() @@ -149,11 +161,6 @@ impl Services { let records = services.index.entry(hs_id).or_default(); - let blank_state = || ServiceState::Closed { - data: D::default(), - last_used: connector.runtime.now(), - }; - let table_index = match records .iter_mut() .enumerate()