tor-dirmgr: Refactor storage not to take Microdesc type.

Since all it needs is an MDDigest, that's what it should take.  This
will make it easier to test.
This commit is contained in:
Nick Mathewson 2020-11-30 11:11:39 -05:00
parent 1806135313
commit e979bd5cb2
3 changed files with 14 additions and 9 deletions

View File

@ -1,10 +1,13 @@
//! Types to describe information about other downloaded directory
//! documents, without necessarily having the full document.
use tor_llcrypto as ll;
use tor_netdoc::doc::netstatus::{Lifetime, MDConsensus, UnvalidatedMDConsensus};
//!
//! These types are all local within tor-dirmgr. They're used so that
//! the storage code doesn't need to know about all of the parsed
//! types from tor-netdoc.
use digest::Digest;
use tor_llcrypto as ll;
use tor_netdoc::doc::netstatus::{Lifetime, MDConsensus, UnvalidatedMDConsensus};
/// Information about a consensus that we have in storage.
///

View File

@ -12,7 +12,6 @@
#![deny(clippy::missing_docs_in_private_items)]
pub mod authority;
// TODO: make this private.
mod config;
mod docmeta;
mod err;
@ -617,7 +616,10 @@ where
{
let mut w = store.write().await;
w.store_microdescs(
new_mds.iter().flatten().map(|(txt, md)| (&txt[..], md)),
new_mds
.iter()
.flatten()
.map(|(txt, md)| (&txt[..], md.digest())),
mark_listed,
)?;
}

View File

@ -8,7 +8,7 @@ use crate::storage::InputString;
use crate::{Error, Result};
use tor_netdoc::doc::authcert::{AuthCert, AuthCertKeyIds};
use tor_netdoc::doc::microdesc::{MDDigest, Microdesc};
use tor_netdoc::doc::microdesc::MDDigest;
use std::collections::HashMap;
use std::convert::TryInto;
@ -399,15 +399,15 @@ impl SqliteStore {
/// it was last listed at `when`.
pub fn store_microdescs<'a, I>(&mut self, input: I, when: SystemTime) -> Result<()>
where
I: IntoIterator<Item = (&'a str, &'a Microdesc)>,
I: IntoIterator<Item = (&'a str, &'a MDDigest)>,
{
let when: DateTime<Utc> = when.into();
let tx = self.conn.transaction()?;
let mut stmt = tx.prepare(INSERT_MD)?;
for (content, md) in input.into_iter() {
let h_digest = hex::encode(md.digest());
for (content, md_digest) in input.into_iter() {
let h_digest = hex::encode(md_digest);
stmt.execute(params![h_digest, when, content])?;
}
stmt.finalize()?;