Commit 7e50c4ad authored by Nick Mathewson's avatar Nick Mathewson 🎨
Browse files

Move storage and config logic from netdir to dirmgr.

parent 21ebb5ca
......@@ -112,7 +112,7 @@ fn get_netdir(args: &Args) -> Result<tor_netdir::NetDir> {
eprintln!("Can't specify both --tor-dir and --chutney-dir");
return Err(anyhow!("Conflicting --tor-dir and --chutney-dir"));
}
let mut cfg = tor_netdir::NetDirConfigBuilder::new();
let mut cfg = tor_dirmgr::NetDirConfigBuilder::new();
if let Some(ref d) = args.tor_dir {
cfg.add_default_authorities();
......@@ -266,10 +266,10 @@ fn main() -> Result<()> {
// TODO: This is just a kludge for testing.
if args.dirclient {
let fb = tor_netdir::fallback::FallbackSet::new();
let store = tor_netdir::storage::sqlite::SqliteStore::from_path("/home/nickm/.arti")?;
let store = tor_dirmgr::storage::sqlite::SqliteStore::from_path("/home/nickm/.arti")?;
let store = tor_dirmgr::DirStoreHandle::new(store);
let circmgr = Arc::new(circmgr);
let mut cfg = tor_netdir::NetDirConfigBuilder::new();
let mut cfg = tor_dirmgr::NetDirConfigBuilder::new();
cfg.add_default_authorities();
let cfg = cfg.finalize();
let authorities = cfg.into_authorities();
......
......@@ -17,13 +17,21 @@ tor-llcrypto = { path="../tor-llcrypto", version= "*" }
tor-rtcompat = { path="../tor-rtcompat", version= "*" }
anyhow = "1.0.34"
async-trait = "0.1.41"
async-rwlock = "1.3.0"
async-trait = "0.1.41"
base64 = "0.13.0"
chrono = "0.4.19"
digest = "0.9.0"
event-listener = "2.5.1"
futures = "0.3.8"
rand = "0.7.3"
hex = "0.4.2"
log = "0.4.11"
memmap = "0.7.0"
rand = "0.7.3"
rusqlite = { version="0.24.1", features=["chrono"] }
thiserror = "1.0.22"
[dev-dependencies]
futures-await-test = "0.3.0"
hex-literal = "0.3.1"
tempdir = "0.3.7"
......@@ -3,11 +3,11 @@
//! Directory configuration tells us where to load and store directory
//! information ,where to fetch it from, and how to validate it.
use crate::fallback::{FallbackDir, FallbackSet};
use crate::storage::legacy::LegacyStore;
use crate::Authority;
use crate::PartialNetDir;
use crate::{Error, Result};
use tor_netdir::fallback::{FallbackDir, FallbackSet};
use tor_llcrypto::pk::ed25519::Ed25519Identity;
use tor_llcrypto::pk::rsa::RSAIdentity;
......
//! Declare an error type for the dirmgr crate.
use thiserror::Error;
/// An error originated by the directory manager code
#[derive(Error, Debug)]
pub enum Error {
/// We received a document we didn't want at all.
#[error("unwanted object: {0}")]
Unwanted(&'static str),
/// A bad argument was provided to some configuration function.
#[error("bad argument: {0}")]
BadArgument(&'static str),
/// We couldn't read something from disk that we should have been
/// able to read.
#[error("corrupt cache: {0}")]
CacheCorruption(&'static str),
/// rusqlite gave us an error.
#[error("sqlite error: {0}")]
SqliteError(#[from] rusqlite::Error),
/// A schema version that says we can't read it.
#[error("unrecognized data storage schema")]
UnrecognizedSchema,
}
#![allow(unused_variables)]
#![allow(unused)]
pub mod authority;
// TODO: make this private.
mod config;
mod docmeta;
mod err;
pub mod storage;
use crate::docmeta::ConsensusMeta;
use crate::storage::sqlite::SqliteStore;
use tor_checkable::{ExternallySigned, SelfSigned, Timebound};
use tor_circmgr::{CircMgr, DirInfo};
use tor_netdir::docmeta::ConsensusMeta;
use tor_netdir::storage::sqlite::SqliteStore;
use tor_netdir::{Authority, MDReceiver, NetDir, PartialNetDir};
use tor_netdir::{MDReceiver, NetDir, PartialNetDir};
use tor_netdoc::doc::authcert::{AuthCert, AuthCertKeyIds};
use tor_netdoc::doc::microdesc::{MDDigest, Microdesc, MicrodescReader};
use tor_netdoc::doc::netstatus::{MDConsensus, UnvalidatedMDConsensus};
use tor_netdoc::AllowAnnotations;
use anyhow::{anyhow, Error, Result};
use anyhow::{anyhow, Result};
use async_rwlock::RwLock;
use std::collections::HashSet;
......@@ -21,6 +28,10 @@ use std::path::Path;
use std::sync::Arc;
use std::time::SystemTime;
pub use authority::Authority;
pub use config::{NetDirConfig, NetDirConfigBuilder};
pub use err::Error;
/*
// XXXX shouldn't be pub.
#[derive(Debug)]
......
......@@ -24,7 +24,7 @@ impl InputString {
InputString::UncheckedBytes(v) => std::str::from_utf8(&v[..]),
InputString::MappedBytes(m) => std::str::from_utf8(&m[..]),
}
.map_err(|_| Error::CacheCorruption("Invalid UTF-8"))
.map_err(|_| Error::CacheCorruption("Invalid UTF-8").into())
}
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
......
......@@ -61,12 +61,12 @@ impl LegacyStore {
let text = input.as_str()?;
for cert in AuthCert::parse_multiple(text) {
let r = (|| {
let r: Result<_> = (|| {
let cert = cert?.check_signature()?.check_valid_now()?;
let found = authorities.iter().any(|a| a.matches_cert(&cert));
if !found {
return Err(Error::Unwanted("no such authority"));
return Err(Error::Unwanted("no such authority").into());
}
Ok(cert)
})();
......
......@@ -80,7 +80,7 @@ impl SqliteStore {
return Ok(())
} else */
if readable_by > SCHEMA_VERSION {
return Err(Error::UnrecognizedSchema);
return Err(Error::UnrecognizedSchema.into());
}
// rolls back the transaction, but nothing was done.
......@@ -121,7 +121,7 @@ impl SqliteStore {
.components()
.all(|c| matches!(c, path::Component::Normal(_)))
{
return Err(Error::CacheCorruption("Invalid path in database"));
return Err(Error::CacheCorruption("Invalid path in database").into());
}
let mut result = self.path.clone();
......
......@@ -14,12 +14,9 @@ tor-llcrypto = { path="../tor-llcrypto", version= "*" }
tor-protover = { path="../tor-protover", version= "*" }
base64 = "0.13.0"
chrono = "0.4.19"
digest = "0.9.0"
hex = "0.4.2"
lazy_static = "1.4.0"
log = "0.4.11"
memmap = "0.7.0"
rand = "0.7.3"
rusqlite = { version="0.24.1", features=["chrono"] }
signature = "1.2.2"
......@@ -28,4 +25,3 @@ thiserror = "1.0.22"
[dev-dependencies]
hex-literal = "0.3.1"
simple-logging = "2.0.2"
tempdir = "0.3.7"
\ No newline at end of file
......@@ -20,13 +20,9 @@
#![deny(missing_docs)]
#![deny(clippy::missing_docs_in_private_items)]
mod authority;
mod config;
pub mod docmeta;
mod err;
pub mod fallback;
mod pick;
pub mod storage;
use ll::pk::rsa::RSAIdentity;
use tor_llcrypto as ll;
......@@ -39,9 +35,6 @@ pub use err::Error;
/// A Result using the Error type from the tor-netdir crate
pub type Result<T> = std::result::Result<T, Error>;
pub use authority::Authority;
pub use config::{NetDirConfig, NetDirConfigBuilder};
/// Internal: how should we find the base weight of each relay? This
/// value is global over a whole directory, and depends on the bandwidth
/// weights in the consensus.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment