Merge branch 'main' into 'intern-more'
# Conflicts: # doc/semver_status.md
This commit is contained in:
commit
8f430fd58d
|
@ -1485,9 +1485,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humantime-serde"
|
name = "humantime-serde"
|
||||||
version = "1.0.1"
|
version = "1.1.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ac34a56cfd4acddb469cc7fff187ed5ac36f498ba085caf8bbc725e3ff474058"
|
checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"humantime 2.1.0",
|
"humantime 2.1.0",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -3098,8 +3098,6 @@ name = "tor-basic-utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"educe",
|
"educe",
|
||||||
"humantime-serde",
|
|
||||||
"serde",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3441,6 +3439,7 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"derive_more",
|
"derive_more",
|
||||||
"digest 0.10.3",
|
"digest 0.10.3",
|
||||||
|
"educe",
|
||||||
"hex",
|
"hex",
|
||||||
"hex-literal",
|
"hex-literal",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
@ -38,7 +38,7 @@ tor-persist = { path="../tor-persist", version = "0.1.0"}
|
||||||
tor-proto = { path="../tor-proto", version = "0.1.0"}
|
tor-proto = { path="../tor-proto", version = "0.1.0"}
|
||||||
tor-rtcompat = { path="../tor-rtcompat", version = "0.1.0"}
|
tor-rtcompat = { path="../tor-rtcompat", version = "0.1.0"}
|
||||||
|
|
||||||
humantime-serde = "1"
|
humantime-serde = "1.1.1"
|
||||||
derive_builder = "0.10.2"
|
derive_builder = "0.10.2"
|
||||||
derive_more = "0.99"
|
derive_more = "0.99"
|
||||||
directories = "4"
|
directories = "4"
|
||||||
|
|
|
@ -17,7 +17,6 @@ use std::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
pub use tor_basic_utils::humantime_serde_option;
|
|
||||||
pub use tor_config::{CfgPath, ConfigBuildError, Reconfigure};
|
pub use tor_config::{CfgPath, ConfigBuildError, Reconfigure};
|
||||||
|
|
||||||
/// Types for configuring how Tor circuits are built.
|
/// Types for configuring how Tor circuits are built.
|
||||||
|
@ -77,20 +76,20 @@ pub struct StreamTimeoutConfig {
|
||||||
/// to a host?
|
/// to a host?
|
||||||
#[builder(default = "default_connect_timeout()")]
|
#[builder(default = "default_connect_timeout()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_connect_timeout")]
|
#[serde(with = "humantime_serde", default = "default_connect_timeout")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) connect_timeout: Duration,
|
pub(crate) connect_timeout: Duration,
|
||||||
|
|
||||||
/// How long should we wait before timing out when resolving a DNS record?
|
/// How long should we wait before timing out when resolving a DNS record?
|
||||||
#[builder(default = "default_dns_resolve_timeout()")]
|
#[builder(default = "default_dns_resolve_timeout()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_dns_resolve_timeout")]
|
#[serde(with = "humantime_serde", default = "default_dns_resolve_timeout")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) resolve_timeout: Duration,
|
pub(crate) resolve_timeout: Duration,
|
||||||
|
|
||||||
/// How long should we wait before timing out when resolving a DNS
|
/// How long should we wait before timing out when resolving a DNS
|
||||||
/// PTR record?
|
/// PTR record?
|
||||||
#[builder(default = "default_dns_resolve_ptr_timeout()")]
|
#[builder(default = "default_dns_resolve_ptr_timeout()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_dns_resolve_ptr_timeout")]
|
#[serde(with = "humantime_serde", default = "default_dns_resolve_ptr_timeout")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) resolve_ptr_timeout: Duration,
|
pub(crate) resolve_ptr_timeout: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,6 @@ categories = ["rust-patterns"] # We must put *something* here and this will do
|
||||||
repository = "https://gitlab.torproject.org/tpo/core/arti.git/"
|
repository = "https://gitlab.torproject.org/tpo/core/arti.git/"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.103", features = ["derive"], optional = true }
|
|
||||||
humantime-serde-crate = { package = "humantime-serde", version = "1", optional = true }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["humantime-serde"]
|
|
||||||
humantime-serde = ["humantime-serde-crate", "serde"]
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
educe = "0.4.6"
|
educe = "0.4.6"
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
//! Module to adaopt `humantime_serde` to `Option<Duration>`
|
|
||||||
|
|
||||||
use humantime_serde_crate::Serde as HtSerde;
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
|
||||||
|
|
||||||
/// Serializes an `Option<Duration>` or `Option<SystemTime>` via the humantime crate.
|
|
||||||
pub fn serialize<T, S>(d: &Option<T>, s: S) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
for<'a> HtSerde<&'a T>: Serialize,
|
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let nested: Option<HtSerde<&T>> = d.as_ref().map(Into::into);
|
|
||||||
nested.serialize(s)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deserialize an `Option<Duration>` or `Option<SystemTime>` via the humantime crate.
|
|
||||||
pub fn deserialize<'a, T, D>(d: D) -> Result<Option<T>, D::Error>
|
|
||||||
where
|
|
||||||
HtSerde<T>: Deserialize<'a>,
|
|
||||||
D: Deserializer<'a>,
|
|
||||||
{
|
|
||||||
let got: Option<HtSerde<T>> = Deserialize::deserialize(d)?;
|
|
||||||
Ok(got.map(HtSerde::into_inner))
|
|
||||||
}
|
|
|
@ -41,9 +41,6 @@
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
#[cfg(feature = "humantime-serde")]
|
|
||||||
pub mod humantime_serde_option;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------
|
// ----------------------------------------------------------------------
|
||||||
|
|
||||||
/// Function with the signature of `Debug::fmt` that just prints `".."`
|
/// Function with the signature of `Debug::fmt` that just prints `".."`
|
||||||
|
|
|
@ -36,7 +36,7 @@ bounded-vec-deque = "0.1"
|
||||||
derive_builder = "0.10.2"
|
derive_builder = "0.10.2"
|
||||||
educe = "0.4.6"
|
educe = "0.4.6"
|
||||||
futures = "0.3.14"
|
futures = "0.3.14"
|
||||||
humantime-serde = "1"
|
humantime-serde = "1.1.1"
|
||||||
itertools = "0.10.1"
|
itertools = "0.10.1"
|
||||||
tracing = "0.1.18"
|
tracing = "0.1.18"
|
||||||
pin-project = "1"
|
pin-project = "1"
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
//!
|
//!
|
||||||
//! Most types in this module are re-exported by `arti-client`.
|
//! Most types in this module are re-exported by `arti-client`.
|
||||||
|
|
||||||
use tor_basic_utils::humantime_serde_option;
|
|
||||||
use tor_config::ConfigBuildError;
|
use tor_config::ConfigBuildError;
|
||||||
|
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
|
@ -121,7 +120,7 @@ pub struct PreemptiveCircuitConfig {
|
||||||
/// available for that port?
|
/// available for that port?
|
||||||
#[builder(default = "default_preemptive_duration()")]
|
#[builder(default = "default_preemptive_duration()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_preemptive_duration")]
|
#[serde(with = "humantime_serde", default = "default_preemptive_duration")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) prediction_lifetime: Duration,
|
pub(crate) prediction_lifetime: Duration,
|
||||||
|
|
||||||
/// How many available circuits should we try to have, at minimum, for each
|
/// How many available circuits should we try to have, at minimum, for each
|
||||||
|
@ -150,7 +149,7 @@ pub struct CircuitTiming {
|
||||||
/// it out for new requests?
|
/// it out for new requests?
|
||||||
#[builder(default = "default_max_dirtiness()")]
|
#[builder(default = "default_max_dirtiness()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_max_dirtiness")]
|
#[serde(with = "humantime_serde", default = "default_max_dirtiness")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) max_dirtiness: Duration,
|
pub(crate) max_dirtiness: Duration,
|
||||||
|
|
||||||
/// When a circuit is requested, we stop retrying new circuits
|
/// When a circuit is requested, we stop retrying new circuits
|
||||||
|
@ -158,7 +157,7 @@ pub struct CircuitTiming {
|
||||||
// TODO: Impose a maximum or minimum?
|
// TODO: Impose a maximum or minimum?
|
||||||
#[builder(default = "default_request_timeout()")]
|
#[builder(default = "default_request_timeout()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_request_timeout")]
|
#[serde(with = "humantime_serde", default = "default_request_timeout")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) request_timeout: Duration,
|
pub(crate) request_timeout: Duration,
|
||||||
|
|
||||||
/// When a circuit is requested, we stop retrying new circuits after
|
/// When a circuit is requested, we stop retrying new circuits after
|
||||||
|
@ -173,7 +172,7 @@ pub struct CircuitTiming {
|
||||||
/// request.
|
/// request.
|
||||||
#[builder(default = "default_request_loyalty()")]
|
#[builder(default = "default_request_loyalty()")]
|
||||||
#[serde(with = "humantime_serde", default = "default_request_loyalty")]
|
#[serde(with = "humantime_serde", default = "default_request_loyalty")]
|
||||||
#[builder(attrs(serde(with = "humantime_serde_option")))]
|
#[builder(attrs(serde(with = "humantime_serde::option")))]
|
||||||
pub(crate) request_loyalty: Duration,
|
pub(crate) request_loyalty: Duration,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ serde = { version = "1.0.103", features = ["derive"] }
|
||||||
signature = "1"
|
signature = "1"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
time = { version = "0.3", features = ["formatting", "parsing"] }
|
time = { version = "0.3", features = ["formatting", "parsing"] }
|
||||||
humantime-serde = "1"
|
humantime-serde = "1.1.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures-await-test = "0.3.0"
|
futures-await-test = "0.3.0"
|
||||||
|
|
|
@ -764,6 +764,13 @@ impl<DM: WriteNetDir> DirState for GetMicrodescsState<DM> {
|
||||||
if self.register_microdescs(microdescs) {
|
if self.register_microdescs(microdescs) {
|
||||||
// Just stopped being pending.
|
// Just stopped being pending.
|
||||||
self.mark_consensus_usable(storage)?;
|
self.mark_consensus_usable(storage)?;
|
||||||
|
// We can save a lot of ram this way, though we don't want to do it
|
||||||
|
// so often. As a compromise we call `shrink_to_fit at most twice
|
||||||
|
// per consensus: once when we're ready to use, and once when we are
|
||||||
|
// complete.
|
||||||
|
self.missing.shrink_to_fit();
|
||||||
|
} else if self.missing.is_empty() {
|
||||||
|
self.missing.shrink_to_fit();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(changed)
|
Ok(changed)
|
||||||
|
|
|
@ -32,7 +32,7 @@ tor-units = { path="../tor-units", version = "0.1.0"}
|
||||||
derive_builder = "0.10.2"
|
derive_builder = "0.10.2"
|
||||||
educe = "0.4.6"
|
educe = "0.4.6"
|
||||||
futures = "0.3.14"
|
futures = "0.3.14"
|
||||||
humantime-serde = "1"
|
humantime-serde = "1.1.1"
|
||||||
itertools = "0.10.1"
|
itertools = "0.10.1"
|
||||||
pin-project = "1"
|
pin-project = "1"
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
|
|
|
@ -42,6 +42,7 @@ bitflags = "1"
|
||||||
time = { version = "0.3", features = ["std", "parsing", "macros"] }
|
time = { version = "0.3", features = ["std", "parsing", "macros"] }
|
||||||
derive_more = "0.99"
|
derive_more = "0.99"
|
||||||
digest = "0.10.0"
|
digest = "0.10.0"
|
||||||
|
educe = "0.4.6"
|
||||||
hex = "0.4"
|
hex = "0.4"
|
||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
phf = { version = "0.10.0", features = ["macros"] }
|
phf = { version = "0.10.0", features = ["macros"] }
|
||||||
|
|
|
@ -18,6 +18,8 @@ use crate::parse::rules::*;
|
||||||
use crate::parse::tokenize::*;
|
use crate::parse::tokenize::*;
|
||||||
use crate::{ParseErrorKind as EK, Result};
|
use crate::{ParseErrorKind as EK, Result};
|
||||||
|
|
||||||
|
use educe::Educe;
|
||||||
|
|
||||||
/// Describe the rules for one section of a document.
|
/// Describe the rules for one section of a document.
|
||||||
///
|
///
|
||||||
/// The rules are represented as a mapping from token index to
|
/// The rules are represented as a mapping from token index to
|
||||||
|
@ -36,58 +38,37 @@ pub(crate) struct SectionRules<T: Keyword> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The entry or entries for a particular keyword within a document.
|
/// The entry or entries for a particular keyword within a document.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Educe)]
|
||||||
enum TokVal<'a, K: Keyword> {
|
#[educe(Default)]
|
||||||
/// No value has been found.
|
struct TokVal<'a, K: Keyword>(Vec<Item<'a, K>>);
|
||||||
None,
|
|
||||||
/// A single value has been found; we're storing it in place.
|
|
||||||
///
|
|
||||||
/// We use a one-element array here so that we can return a slice
|
|
||||||
/// of the array.
|
|
||||||
Some([Item<'a, K>; 1]),
|
|
||||||
/// Multiple values have been found; they go in a vector.
|
|
||||||
Multi(Vec<Item<'a, K>>),
|
|
||||||
}
|
|
||||||
impl<'a, K: Keyword> TokVal<'a, K> {
|
impl<'a, K: Keyword> TokVal<'a, K> {
|
||||||
|
/// Return the number of Items for this value.
|
||||||
|
fn none() -> Self {
|
||||||
|
Default::default()
|
||||||
|
}
|
||||||
/// Return the number of Items for this value.
|
/// Return the number of Items for this value.
|
||||||
fn count(&self) -> usize {
|
fn count(&self) -> usize {
|
||||||
match self {
|
self.0.len()
|
||||||
TokVal::None => 0,
|
|
||||||
TokVal::Some(_) => 1,
|
|
||||||
TokVal::Multi(v) => v.len(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Return the first Item for this value, or None if there wasn't one.
|
/// Return the first Item for this value, or None if there wasn't one.
|
||||||
fn first(&self) -> Option<&Item<'a, K>> {
|
fn first(&self) -> Option<&Item<'a, K>> {
|
||||||
match self {
|
self.0.get(0)
|
||||||
TokVal::None => None,
|
|
||||||
TokVal::Some([t]) => Some(t),
|
|
||||||
TokVal::Multi(v) => Some(&v[0]),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Return the Item for this value, if there is exactly one.
|
/// Return the Item for this value, if there is exactly one.
|
||||||
fn singleton(&self) -> Option<&Item<'a, K>> {
|
fn singleton(&self) -> Option<&Item<'a, K>> {
|
||||||
match self {
|
match &*self.0 {
|
||||||
TokVal::None => None,
|
&[ref x] => Some(x),
|
||||||
TokVal::Some([t]) => Some(t),
|
_ => None,
|
||||||
TokVal::Multi(_) => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Return all the Items for this value, as a slice.
|
/// Return all the Items for this value, as a slice.
|
||||||
fn as_slice(&self) -> &[Item<'a, K>] {
|
fn as_slice(&self) -> &[Item<'a, K>] {
|
||||||
match self {
|
&self.0
|
||||||
TokVal::None => &[],
|
|
||||||
TokVal::Some(t) => &t[..],
|
|
||||||
TokVal::Multi(v) => &v[..],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// Return the last Item for this value, if any.
|
/// Return the last Item for this value, if any.
|
||||||
fn last(&self) -> Option<&Item<'a, K>> {
|
fn last(&self) -> Option<&Item<'a, K>> {
|
||||||
match self {
|
self.0.last()
|
||||||
TokVal::None => None,
|
|
||||||
TokVal::Some([t]) => Some(t),
|
|
||||||
TokVal::Multi(v) => Some(&v[v.len() - 1]),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +92,7 @@ impl<'a, T: Keyword> Section<'a, T> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
let n = T::n_vals();
|
let n = T::n_vals();
|
||||||
let mut v = Vec::with_capacity(n);
|
let mut v = Vec::with_capacity(n);
|
||||||
v.resize(n, TokVal::None);
|
v.resize(n, TokVal::none());
|
||||||
Section {
|
Section {
|
||||||
v,
|
v,
|
||||||
first: None,
|
first: None,
|
||||||
|
@ -169,19 +150,9 @@ impl<'a, T: Keyword> Section<'a, T> {
|
||||||
fn add_tok(&mut self, t: T, item: Item<'a, T>) {
|
fn add_tok(&mut self, t: T, item: Item<'a, T>) {
|
||||||
let idx = Keyword::idx(t);
|
let idx = Keyword::idx(t);
|
||||||
if idx >= self.v.len() {
|
if idx >= self.v.len() {
|
||||||
self.v.resize(idx + 1, TokVal::None);
|
self.v.resize(idx + 1, TokVal::none());
|
||||||
}
|
}
|
||||||
let m = &mut self.v[idx];
|
self.v[idx].0.push(item);
|
||||||
|
|
||||||
match m {
|
|
||||||
TokVal::None => *m = TokVal::Some([item]),
|
|
||||||
TokVal::Some([x]) => {
|
|
||||||
*m = TokVal::Multi(vec![x.clone(), item]);
|
|
||||||
}
|
|
||||||
TokVal::Multi(ref mut v) => {
|
|
||||||
v.push(item);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if self.first.is_none() {
|
if self.first.is_none() {
|
||||||
self.first = Some(t);
|
self.first = Some(t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,4 +58,7 @@ tor-netdoc:
|
||||||
tor-protover:
|
tor-protover:
|
||||||
new-api: Protocols now implements Eq, PartialEq, and Hash.
|
new-api: Protocols now implements Eq, PartialEq, and Hash.
|
||||||
|
|
||||||
|
tor-basic-utils:
|
||||||
|
|
||||||
|
Remove `humantime_serde_option` module.
|
||||||
|
(Use `humantime_serde::option` instead.)
|
||||||
|
|
Loading…
Reference in New Issue