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.
This commit is contained in:
Ian Jackson 2023-02-28 14:51:28 +00:00
parent 4f5f378516
commit d1863c3178
1 changed files with 12 additions and 5 deletions

View File

@ -128,6 +128,16 @@ enum ServiceState<D: MockableConnectorData> {
Dummy,
}
impl<D: MockableConnectorData> ServiceState<D> {
/// Make a new (blank) `ServiceState::Closed`
fn blank(runtime: &impl Runtime) -> Self {
ServiceState::Closed {
data: D::default(),
last_used: runtime.now(),
}
}
}
impl<D: MockableConnectorData> Services<D> {
/// Connect to a hidden service
// We *do* drop guard. There is *one* await point, just after drop(guard).
@ -138,6 +148,8 @@ impl<D: MockableConnectorData> Services<D> {
isolation: Box<dyn Isolation>,
secret_keys: HsClientSecretKeys,
) -> Result<D::ClientCirc, HsClientConnError> {
let blank_state = || ServiceState::blank(&connector.runtime);
let mut guard = connector
.services
.lock()
@ -149,11 +161,6 @@ impl<D: MockableConnectorData> Services<D> {
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()