Commit Graph

302 Commits

Author SHA1 Message Date
Ian Jackson 5b684020ed tor-config: resolve_option tests: disable rsutfmt 2022-05-31 16:06:32 +01:00
Ian Jackson c2fa37c56a tor-config: Add comprehensive tests for resolve_option 2022-05-31 16:06:32 +01:00
Ian Jackson 4f42101554 lints: Add let_unit_value allow to all crates
From running add_warning, with manual picking of the right
hunks/lines.
2022-05-31 15:23:52 +01:00
Nick Mathewson f67c0eaf50 Merge branch 'tor-config-tests' into 'main'
Add a few coverage-based tests to tor-config.

See merge request tpo/core/arti!540
2022-05-31 14:08:51 +00:00
Nick Mathewson ca94ec72ef Add a few coverage-based tests to tor-config.
There's nothing major here, but it does fill in a few gaps.
2022-05-31 08:59:30 -04:00
Nick Mathewson 9fed0b39fa Merge branch 'dbg' into 'main'
Revert "Remove dbg!()s in tor-config"

See merge request tpo/core/arti!552
2022-05-31 12:38:59 +00:00
Ian Jackson ba0843da4a lints: Add lint block delimiters to every crate
This was the result of:
  maint/add_warning crates/*/src/{lib,main}.rs
and then manually curating the results.
2022-05-31 13:00:31 +01:00
Ian Jackson fbfaecdf72 config: Provide tor_config::resolve_option and resolve journald
Canonicalise the `logging.journald` setting in the validated
configuration.  Now it will never be `Some("")`, even if that is what
was written in the config file.

This allows us to write `journald = ""` in the example configuration.
(Without the canonicalisation the default builder produces `None` and
the example would produce `Some("")`, which are semantically identical
but fail the test.)

See https://gitlab.torproject.org/tpo/core/arti/-/issues/488 for some
background.
2022-05-30 16:00:45 +01:00
Ian Jackson b88c1c1093 tor-config: Drop Serialize and Deserialize from a test type
These violate our rule that *built* structs ought not to be desr.
But this is just in a test.
2022-05-30 16:00:45 +01:00
Orhun Parmaksız bfd41ddb5f
Lexically sort Cargo.toml dependencies
Utilize cargo-sort: https://github.com/DevinR528/cargo-sort

Signed-off-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2022-05-28 20:05:51 +03:00
Ian Jackson 35e3841e4c Revert "Remove dbg!()s in tor-config"
This was done because Nightly Rust complained about these, despite
them all being in tests.  That is now fixed upstream:
  https://github.com/rust-lang/rust-clippy/issues/8758
  https://github.com/rust-lang/rust-clippy/pull/8838

This reverts commit 9d26a91886.
2022-05-27 18:14:03 +01:00
Nick Mathewson 4326aa1de9 Regenerate version bump from previous commit.
This commit was made by reverting the previous commit, then
re-running the script I used to generate it.  In theory there should
be no semantic changes: only changes due to improved formatting from
cargo edit.
2022-05-27 10:18:52 -04:00
Nick Mathewson b232365a75 Semantic version changes for Arti 0.4.0 release
I followed the following procedure to make these changes:

* I used maint/changed_crates to find out which crates had changed
  since 0.3.0.
* I used grep and maint/list_crates to sort those crates in
  topological (dependency) order.
* I looked through semver_status to find which crates were listed as
  having semver-relevant changes (new APIs and breaking changes).
* I scanned through the git logs of the crates with no
  semver-relevant changes listed to confirm that, indeed, they had
  no changes.  For those crates, I incremented their patch-level
  version _without_ changing the version that other crates depend on.
* I scanned through the git logs of the crates with no
  semver-relevant changes listed to confirm that, indeed, they had
  no obvious breaking changes.
* I treated all crates that depend on `arti` and/or `arti-client` as
  having breaking changes.
* I identified crates that depend on crates that have changed, even
  if they have not changed themselves, and identified them as having
  a non-breaking change.
* For all of the crates, I used `cargo set-version -p $CRATE --bump
  $STATUS` (where `STATUS` is `patch` or `minor`) to update the
  versions, and the depended-upon versions.
2022-05-27 09:01:20 -04:00
Nick Mathewson fbc5218af6 Update tor-config README.md. 2022-05-27 08:34:52 -04:00
Nick Mathewson b4a87687f5 Fix a link with nightly rustdoc 2022-05-26 15:40:39 -04:00
Ian Jackson 4bf87d61ca Merge branch 'config-split' into 'main'
Break TorClientConfig out of ArtiConfig and warn on unknown config keys

Closes #459 and #417

See merge request tpo/core/arti!529
2022-05-26 10:40:43 +00:00
Ian Jackson c5a8e453b9 tor-config: load: clippy: adopt two suggestions
We can have mem::take, hooray.
2022-05-26 11:03:48 +01:00
Ian Jackson 42ccb68446 tor-config: load: Add missing "not".
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807331
2022-05-26 10:57:26 +01:00
Ian Jackson f5561c8cdb tor-config: load: Make UnrecognizedKeys not pub
This was a slip.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807330
2022-05-26 10:57:04 +01:00
Ian Jackson ed95d50d49 tor-config: load: Add reversed test 2022-05-25 19:15:47 +01:00
Ian Jackson ce96f0d9ce tor-config: Add duplicative doc comments as per review 2022-05-25 19:15:47 +01:00
Ian Jackson 21a064d4f8 tor-config: load: example: Document what it does and who might write it 2022-05-25 19:15:47 +01:00
Ian Jackson 3eab61603a tor-config: load: Add a newline
This makes the function a tiny bit clearer.
2022-05-25 19:15:47 +01:00
Ian Jackson bf97190a9f tor-config: load: Write actual definition of the Resolvable trait
This is not a doc comment because we don't want it to be public: it
must refer to private fields, etc.
2022-05-25 19:15:47 +01:00
Ian Jackson 2b65e1250e tor-config: load: Explain why not write out macro call n times 2022-05-25 19:15:47 +01:00
Ian Jackson 1ee2be9d6d tor-config: docs: add more docs about load, esp. traits 2022-05-25 19:15:47 +01:00
Ian Jackson 337b4a7231 tor-config: docs: add a lot of context and overview and xrefs 2022-05-25 19:15:47 +01:00
Ian Jackson 40b433d4ba tor-config: load: Avoid destructuring assignment
Not available in our MSRV.
2022-05-25 19:15:47 +01:00
Ian Jackson b552c4e2bf tor-config: load: Intersection: add more commentary 2022-05-25 19:15:47 +01:00
Ian Jackson 5661df823f tor-config: load: Drop a needless call to .into_iter()
I think this is a leftover from a previous version of this expression.
2022-05-25 19:15:47 +01:00
Ian Jackson a8a3661503 tor-config: load: Fix a misleading comment
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807070
2022-05-25 19:15:47 +01:00
Ian Jackson 964794bfa0 tor-config: load: Rename shorter_let
Instead of the wrong "prefix_len".  As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807068
2022-05-25 19:15:47 +01:00
Ian Jackson 26715c5550 tor-config: load: Docs 2022-05-25 19:15:47 +01:00
Ian Jackson 4f62c3ded1 tor-config: Typo fixes (as per review comments) 2022-05-25 19:15:47 +01:00
Ian Jackson 28c1f707a1 tor-config: load: Introduce UnrecognizedKeys enum
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807078

This is in fact much clearer than the Option.
2022-05-25 19:15:47 +01:00
Ian Jackson 151d28c90f Run rustfmt following renaming
Split into its own commit to avoid churn in the rename commits.
2022-05-25 16:41:50 +01:00
Ian Jackson 0803296bd6 tor-config: Rename resolve_return_unrecognized, ..._ignore_...
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807077
2022-05-25 16:41:05 +01:00
Ian Jackson 9f426e2c57 tor-config: Rename "ignored" to "unrecognized" throughout
As per review comments
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/529#note_2807076
2022-05-25 16:40:02 +01:00
Ian Jackson 4b0459d204 Merge branch 'bug475' into 'main'
ConfigurationSources: Allow config files to be world-readable.

Closes #475

See merge request tpo/core/arti!528
2022-05-25 14:23:12 +00:00
Ian Jackson 9c88158740 tor-config: Example for load module 2022-05-24 20:14:57 +01:00
Ian Jackson bb8e205b0d tor-config: Tests for ignored config key handling 2022-05-24 20:14:57 +01:00
Ian Jackson 09f26f2d68 tor-config: Track and (by default) warn on ignored config keys 2022-05-24 20:14:57 +01:00
Ian Jackson e1bc599db2 tor-config: Tests for support functions for tracking ignored keys 2022-05-24 20:14:57 +01:00
Ian Jackson 865ae13502 tor-config: Support functions for tracking ignored config keys
This turns out to need quite a complicated algorithm.
2022-05-24 20:14:57 +01:00
Ian Jackson 9e526aad7c Split TorClientConfig out of ArtiConfig, and Resolvable trait
This gets rid of `#[serde(flatten)]` which prevents serde_ignored (and
other kinds of introspection) from working properly.

The price is now that the toplevel has to deal with two configuration
objects.

The Resolvable trait is overkill right now, but is going to do More
Things in a moment.  In particular, we need the impl on tuples, so
that the whole config can be processed in one go.
2022-05-24 20:14:57 +01:00
Ian Jackson 687e5c369e tor-config: Introduce Builder trait and ConfigReolveError
We are going to need this for some generic code which is going to
appear shortly.  Having it produced by impl_standard_builder seems
best.  But that does mean being able to disable it, so extra stuff in
the macro.  Nothing uses this trait yet.

ConfigResolveError is not used now either, but will be in a moment.
2022-05-24 20:08:40 +01:00
Ian Jackson fcdac71be7 tor-config: Add a lint allow
I don't understand why this isn't tripping all the time.  Maybe
because this is in a macro.  Anyway, I am going to add a new
invocation of this macro from within a test where, empirically, it
trips.
2022-05-24 20:08:40 +01:00
Nick Mathewson 5a5a828db6 ConfigurationSources: Allow config files to be world-readable.
Fixes #475.
2022-05-24 11:05:57 -04:00
Nick Mathewson 95200383b5 fs-mistrust: make Mistrust have a corresponding Builder type.
This is an approximately minimal revision to get Builder in place;
subsequent commits will clean up the API.
2022-05-24 10:54:02 -04:00
Nick Mathewson 994426d18c Add a couple of "pub use" to make nightly rustdoc pass. 2022-05-20 12:12:23 -04:00
Nick Mathewson 9d26a91886 Remove dbg!()s in tor-config
This should satisfy our CI and turn it green again.
2022-05-20 10:34:32 -04:00
Nick Mathewson 934de16098 Merge branch 'arti-config-2' into 'main'
Abolish arti-config, replacing with tombstone crate

See merge request tpo/core/arti!508
2022-05-13 12:30:24 +00:00
Ian Jackson b6b5d05e1b tor-config: Provide useful documentation for sources module 2022-05-13 12:42:30 +01:00
Ian Jackson 44d2f5ccfd arti-config abolition: Move functionality to tor-config
This crate no longer has any reason to exist.  All its remaining
functionality is generic enough to go into tor-config.

In this commit, we move the contents of lib.rs into a new file in
tor-config.  It contains:

 * Code motion
 * The minimal "mod" and "use" changes
 * The minimal doc comment
 * A new a compat alias for ConfigurationSources.

The compat alias is there because various crates currently speak of
arti_config::ConfigurationSources and it is most convenient to fix
them up after the type is available in tor_config.
2022-05-13 12:42:30 +01:00
Ian Jackson 9a3205aeba arti-config abolition: Add deps to tor-config
These are needed to support the code which is moving.
2022-05-13 12:41:27 +01:00
Ian Jackson 8f724ad767 impl_standard_builder: Better comments explaining the parser 2022-05-13 10:46:31 +01:00
Ian Jackson be5bc04c02 impl_standard_builder: Have it generate FooConfig::builder
This deletes many handcoded impls.  It also generates lots of impls
that we previously didn't have.
2022-05-12 18:50:26 +01:00
Ian Jackson 86a3e006d3 impl_standard_builder: Test the Deserialize impl
Test the Deserialize impl of every config struct.

This detects bugs like the one fixed in !502.

The macro now becomes more complex because it needs to take options.
Right now this tt-munching option parser is overkill, but this
leave space for further options in the future.
2022-05-12 18:50:26 +01:00
Ian Jackson c1c6f2b376 Rename impl_standard_builder from impl_default_via_builder
I have Plans for this macro.  In particular:

 * I have a wip branch which tests that the Builder can be
   deserialised from an empty config (ie, that config reading
   of a config with a blank section for this item works).

 * I think we should autogenerate $Config::builder(),
   and promote that, rather than $ConfigBuilder::default().
   This macro could do that.
2022-05-12 15:59:13 +01:00
eta 5990df53fe Merge branch 'arti-config-1' into 'main'
arti-config: Move cmdline to tor-config

See merge request tpo/core/arti!498
2022-05-12 13:07:43 +00:00
Ian Jackson 3420fe735d Define and use impl_default_via_builder 2022-05-11 18:27:15 +01:00
Ian Jackson ab3bd9d6d5 arti-config: Move cmdline to tor-config
This does not know anything about arti, only about TOML and Config.

Code motion, plus necessary import adjustments.
2022-05-11 18:23:05 +01:00
Ian Jackson 26b3115586 tor-config: Export CfgPathError
It is not clear to me how this `pub enum` survived the "inaccessible
pub" lint.
2022-05-11 15:53:03 +01:00
Nick Mathewson 7b93091f57 Bump the version of every* crate to 0.3.0
* Except for safelog and fs-mistrust, which are new.
2022-05-06 10:03:15 -04:00
Ian Jackson 030289481f Switch to derive_builder_arti_fork
For reference, the git source for this crate (and the others in its
workspace) currently lives in my personal github account (ijackson).
If this fork turns out to be long-lived and gains features and/or
users, it would be good to move it to a gitlab somewhere.

I have granted Nick crate ownership on the crates.io system.
2022-05-06 13:36:40 +01:00
eta de2b23642d Merge branch 'typos-20220504' into 'main'
Fix typos (using the typos-cli tool).

See merge request tpo/core/arti!486
2022-05-05 15:55:22 +00:00
Ian Jackson d47e94b459 config derive attrs: Make builders serde, and validated structs not
* Builders additionally derive: Debug, Serialize, Deserialize.

 * Validated structs no longer derive: Serialize, Deserialize
   and all related attributes deleted.

 * As a consequence, all the `#[serde(deny_unknown_fields)]`
   are gone.  That means that right now unknown fields are totally
   ignored.  This is good for compatibility but poor for useability.
   Doing something better here is arti#417, in progress.

 * As a consequence, delete tor_dirmgr::retry::default_parallelism.
   (The default value was already duplicated into a builder attr.)
2022-05-05 10:35:52 +01:00
Nick Mathewson fc33fc3efb Fix typos (using the typos-cli tool). 2022-05-04 14:41:50 -04:00
Ian Jackson df2813ed55 list_builder: Add some xrefs about macro_rules limitations
Apropos
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/474#note_2800481
2022-05-04 18:35:33 +01:00
Nick Mathewson cb892116dc Fix typo 2022-05-04 17:34:47 +00:00
Ian Jackson 2487a46ef0 list_builder: Provide VecBuilder
This is for lists of plain types (non-builder types).
2022-05-04 17:18:55 +01:00
Ian Jackson 221fe63430 list_builder: Use Educe to derive Default
This allows us to use this with an item builder type which doesn't
impl Default.  (Obviously this only makes sense for items which aren't
actually builders.)
2022-05-04 17:18:05 +01:00
Ian Jackson 578684f290 list_builder: Make helper capable of handling generics
It is Quite Vexing that we have to use [ ] rather than the < > around
the generics, particularly given that we are also using [ ] to signal
"this is arrayish".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-05-04 17:17:46 +01:00
Ian Jackson 0c001ed60e list_builder: Actually honour attributes
The docs were a lie.  $docs_and_attrs was missing from the expander.

And add a note about how any supplied docs are handled.
2022-05-04 17:16:36 +01:00
Nick Mathewson d0330d2c95 Fix typos 2022-05-04 13:50:12 +01:00
Ian Jackson 4bca912715 Change builder list API
The new API is (roughly) as discussed in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/451

This is quite a large commit and it is not convenient to split it up.
It contains the following changes:

 * Redo the list builder and accessor macros implemnetation,
   including docs and tests.

 * Change uses of define_list_config_builder.  In each case:
   - Move the docs about the default value to the containing field.
   - Remove the other docs (which were just recapitulations, and
     are now not needed since the ListBuilder is no longer public).
   - Rewmove or replace `pub` in the define_list_builder_helper call,
     so that the builder is no longer public.
   - Change the main macro call site to use define_list_builder_helper.
   - Add a call to define_list_builder_accessors.

 * Make the module `list_builder` pub so that we have somewhere to
   put the overview documentation.

 * Consequential changes:
   - Change `outer.inner().replace(X)` to `outer.set_inner(X)`
   - Consequential changes to imports (`use` statements).
2022-05-04 13:50:10 +01:00
Ian Jackson 71911d2921 Introduce ThingListBuilder::default_list
This removes a caveat from the API and will be convenient for what is
coming.
2022-05-04 13:48:30 +01:00
Ian Jackson 8ad4735d58 Add dependency on paste crate
The list accessor macro is going to want this.
2022-05-04 13:48:30 +01:00
Ian Jackson f4088a755c Fix config version
This matches Cargo.lock.  I suspect a mismerge in arti!478.
2022-05-04 13:39:18 +01:00
Ian Jackson 2da84857a5 CfgPath: Test serialisation round-trip with a binary format
Use MessagePack.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-05-03 17:42:54 +01:00
Ian Jackson 1e6c6169a8 CfgPath: Make it Serialize
And provide round-trip tests.

As per https://gitlab.torproject.org/tpo/core/arti/-/issues/371
2022-05-03 17:42:54 +01:00
Ian Jackson ed970310e2 CfgPath: Overhaul API
Document that this can contain either a string for expansion, or a
literal PathBuf not for expansion.

Rename the `from_path` method to `new_literal`: a very important
difference is whether it gets expanded - less important than the Rust
type.  Also, now it takes `Into<PathBuf>`, which avoids a needless
clone.

(We don't change the API in `arti-client` because
`&tempfile::Tempdir()` doesn't implement `Into<PathBuf>`, so
`arti-client` has to have some new `as_ref` calls.)

Provide accessors `as_unexpanded_str` and `as_literal_path`.  The
deserialisation already makes this part of the stable API,l so not
pvoding accessors seems just obstructive.  They are useful for tests,
too.

Add tests for the new entrypoints, and for deserialisation of both
variants from TOML (via config, or directly) and JSON.
2022-05-03 17:42:14 +01:00
Ian Jackson ae776392fa CfgPath: Change deserialisaation of Literal variant
We introduce LiteralPath struct, so that a literal path deserialises
from
    some_path = { literal: "actual path string" }

This makes the deserialisation unambiguous.
2022-05-03 17:42:14 +01:00
Ian Jackson a97ad69855 derive_builder: Use git dep everywhere, rather than cargo patch
The `[patch]` approach causes the tree not to build when used as a
dependency, unless the `[patch]` is replicated into the depending
project.

Instead, replace our `derive_builer =` dependencies with a reference
to a specific git commit:

  perl -i~ -pe 'next unless m/^derive_builder/; s#"(0\.11\.2)"#{ version = "$1", git = "https://github.com/ijackson/rust-derive-builder", rev = "ba0c1a5311bd9f93ddf5f5b8ec2a5f6f03b22fbe" }#' crates/*/Cargo.toml

Note that the commitid has changed.  This is because derive_builder is
in fact a workspace of 4 crates.  3 of them are of interest to arti
itself (the 4th exists only for testing).  So the same "add git
revision" treatment had to be done to the `derive_builder` and
`derive_builder_macro` crates.  Each dependency edge involves a new
commit in the derive_builder workspace, since we can't create a git
commit containing its own commitid.  (We want to use commits, rather
than a branch, so that what we are depending on is actually properly
defined, and not subject to the whims of my personal github
namespace.)

There are no actual code changes in derive_builder.
2022-04-27 14:57:59 +01:00
Nick Mathewson c1ea419477 Merge branch 'main' into 'msrv_1_56'
# Conflicts:
#   crates/tor-config/Cargo.toml
#   crates/tor-dirmgr/src/state.rs
#   doc/semver_status.md
2022-04-26 12:45:16 +00:00
Ian Jackson e81d215787 list-builder: Provide tests of all methods
Because the macro output is private, if we miss one out of the tests,
it doesn't fail due to dead code :-).
2022-04-25 18:24:28 +01:00
Ian Jackson c71046294b list_builder: Allow the struct to not be pub
Really, we probably don't want any of these not to be pub, but it
triggers "unreachable pub" in my test cases, and making it not pub by
mistake seems not very serious, and likely to be noticed.

Making the struct private in the test cases has the useful effect of
checking that all the methods are tested.
2022-04-25 18:24:06 +01:00
Ian Jackson 83b9fbea99 list_builder: Use $crate namespaced imports
I don't think we need to bother with things in the prelude,
but doing it for serde and ConfigBuildError seems nice.

Noticed while writing a test case.
2022-04-25 18:23:02 +01:00
Ian Jackson ce877e4421 Document defaults for all the config lists
And add an imprecation in define_list_config_builder's doc comment do
do so in future for other invocations of the macro.

Add add the missing full stops.
2022-04-25 18:22:54 +01:00
Ian Jackson bb81a412ea define_list_config_builder: Provide example of item_build
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798027
2022-04-25 18:20:21 +01:00
Ian Jackson bfd0e48a5c define_list_config_builder: Expand generated docs for methods etc.
Requested in
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798022
2022-04-25 18:20:21 +01:00
Ian Jackson 8664766270 Rename macro_first_nonempty (from macro_coalesce_args)
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798026
2022-04-25 18:15:25 +01:00
Ian Jackson 1f215da1a3 Rename ThingListBuilder::replace (from set)
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798024
2022-04-25 18:15:25 +01:00
Nick Mathewson b60b0a266a Bump every crate's edition to 2021.
This is an automated change made with a perl one-liner and verified
with grep -L and grep -l.

Some warnings are introduced with this change; they will be removed
in subsequent commits.

See arti#208 for older discussion on this issue.
2022-04-25 13:05:31 -04:00
Nick Mathewson ca05b0904c Add 'rust-version = "1.56"' to every Cargo.toml file.
This change was made automatically with a perl one-liner, and
confirmed with `grep -L`.

The `rust-version` field itself was introduced in 1.56.0.
2022-04-25 13:04:31 -04:00
Nick Mathewson 0069fd2206 Reformat all not-yet-reformatted Cargo.toml files.
There are no semantic changes here; only formatting.  This is in
preparation for other changes (wrt MSRV and edition)
2022-04-25 13:04:31 -04:00
Ian Jackson dca4f3ede1 Use better syntax for doc comment attribute
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798020
2022-04-25 17:05:30 +01:00
Ian Jackson 961f6b527e config list-builder: Allow overriding the per-item build method
This will be useful especially for simple lists where the entry
doesn't need a separate builder type.
2022-04-25 17:04:23 +01:00
Ian Jackson 0036b91662 Introduce define_list_config_builder macro
This replaces two almost-identical sets of structs and impls.  More
are on the way, as per
  https://gitlab.torproject.org/tpo/core/arti/-/issues/447
2022-04-25 12:41:00 +01:00
Ian Jackson 91a8bc0c11 impl From<SubfieldBuildError> for ConfigBuildError
We are going to be using sub-field builders.
2022-04-22 16:46:32 +01:00
Ian Jackson 6da7a2e3e2 Use git source for derive_builder for now, for sub_builder feature
This commitid is the current head of my MR branch
  https://github.com/colin-kiegel/rust-derive-builder/pull/253
  https://github.com/ijackson/rust-derive-builder/tree/field-builder
Using the commitid prevents surprises if that branch is updated.

We will require this newer version of derive_builder.  The version
will need to be bumped again later, assuming the upstream MR is merged
and upstream do a release containing the needed changes.

We will need the new version of not only `derive_builder_core` (the
main macro implementation) but also`derive_builder` for a new error
type.
2022-04-21 14:07:28 +01:00
Nick Mathewson 5b2fc118df Bump all arti*, tor* crates to 0.2.0
Not all of these strictly need to be bumped to 0.2.0; many could go
to 0.1.1 instead.  But since everything at the tor-rtcompat and
higher layers has had breaking API changes, it seems not so useful
to distinguish.  (It seems unlikely that anybody at this stage is
depending on e.g. tor-protover but not arti-client.)
2022-04-01 09:15:18 -04:00
Ian Jackson da787d074a derive_builder: Switch to upstream 0.11
This has the different syntax for builder field attributes than what I
originally proposed in my MR, and which therefore is in the pinned
branch.

My upstream MR for the field attributes feature was morged:
  https://github.com/colin-kiegel/rust-derive-builder/issues/239
2022-03-16 16:34:44 +00:00
Ian Jackson 6761cf2b69 Merge branch 'config-no-retcon' into 'main'
Drop config back-conversion from FooConfig to FooConfigBuilder

See merge request tpo/core/arti!391
2022-03-10 14:47:01 +00:00
Ian Jackson 416b56d852 Use git source for derive_builder for now, for attrs feature
We are going to want to specify custom attributes on fields of the
builder struct.  This feature was missing from derive_builder.

This commitid is the current head of my MR branch
  https://github.com/colin-kiegel/rust-derive-builder/pull/237
  https://github.com/ijackson/rust-derive-builder/tree/builder-field-attrs
Using the commitid prevents surprises if that branch is updated.

We will require this newer version of derive_builder.  The version
will need to be bumped again later, assuming the upstream MR is merged
and upstream do a release containing the needed changes.
2022-03-07 15:56:57 +00:00
Michael 206714f2e4 Test shell variable expansion on windows 2022-03-05 01:40:42 +00:00
Ian Jackson eb66d0af6f Merge branch 'derive-traits' into 'main'
Tidy up many open-coded trait impls

See merge request tpo/core/arti!374
2022-03-04 11:25:57 +00:00
Ian Jackson e45a95f65a Replace manual Default impl with std derive in tor-config 2022-03-02 18:01:08 +00:00
Ian Jackson 72bb8e7f28 Switch to shellexpand-fork version of shellexpand
Apropos discussion in
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/274
2022-03-02 12:14:51 +00:00
Nick Mathewson 83c8b11c2c Merge branch 'clippy-allow-arc-clone' into 'main'
Disable clippy::clone_on_ref_ptr

See merge request tpo/core/arti!352
2022-03-01 20:38:05 +00:00
Nick Mathewson e8e9791a97 Bump all crates to 0.1.0 2022-03-01 08:59:34 -05:00
Nick Mathewson 5735222691 Update README.md files from rustdoc. 2022-03-01 08:30:53 -05:00
Nick Mathewson dd8cd08691 Add warnings about configuration stability. 2022-02-28 14:25:24 -05:00
Ian Jackson afb50fe735 Disable clippy::clone_on_ref_ptr
This lint is IMO inherently ill-conceived.

I have looked for the reasons why this might be thought to be a good
idea and there were basically two (and they are sort of contradictory):

I. "Calling ‘.clone()` on an Rc, Arc, or Weak can obscure the fact
    that only the pointer is being cloned, not the underlying data."

This is the wording from
  https://rust-lang.github.io/rust-clippy/v0.0.212/#clone_on_ref_ptr

It is a bit terse; we are left to infer why it is a bad idea to
obscure this fact.  It seems to me that if it is bad to obscure some
fact, that must be because the fact is a hazard.  But why would it be
a hazard to not copy the underlying data ?

In other languages, faliing to copy the underlying data is a serious
correctness hazard.  There is a whose class of bugs where things were
not copied, and then mutated and/or reused in multiple places in ways
that were not what the programmer intended.  In my experience, this is
a very common bug when writing Python and Javascript.  I'm told it's
common in golang too.

But in Rust this bug is much much harder to write.  The data inside an
Arc is immutable.  To have this bug you'd have use interior mutability
- ie mess around with Mutex or RefCell.  That provides a good barrier
to these kind of accidents.

II. "The reason for writing Rc::clone and Arc::clone [is] to make it
     clear that only the pointer is being cloned, as opposed to the
     underlying data. The former is always fast, while the latter can
     be very expensive depending on what is being cloned."

This is the reasoning found here
  https://github.com/rust-lang/rust-clippy/issues/2048

This is saying that *not* using Arc::clone is hazardous.
Specifically, that a deep clone is a performance hazard.

But for this argument, the lint is precisely backwards.  It's linting
the "good" case and asking for it to be written in a more explicit
way; while the supposedly bad case can be written conveniently.

Also, many objects (in our codebase, and in all the libraries we use)
that are Clone are in fact simply handles.  They contain Arc(s) (or
similar) and are cheap to clone.  Indeed, that is the usual case.

It does not make sense to distinguish in the syntax we use to clone
such a handle, whether the handle is a transparent Arc, or an opaque
struct containing one or more other handles.

Forcing Arc::clone to be written as such makes for code churn when a
type is changed from Arc<Something> to Something: Clone, or vice
versa.
2022-02-24 18:15:44 +00:00
Nick Mathewson 1cecc7e45a Change deny(clippy::all) to warn(clippy::all).
Closes #338.
2022-02-14 09:24:06 -05:00
Nick Mathewson cb6de69ef6 tor-config: Add HasKind support.
This required a few new ErrorKinds.
2022-02-09 12:30:20 -05:00
Michael 334bba2ef2 Fix invalid path character on windows 2022-01-31 20:53:13 +00:00
Nick Mathewson 01d9937308 Bump the patch version of every crate that changed since 0.0.3 2022-01-31 10:30:52 -05:00
Nick Mathewson e0ee3b5049 Explain that CfgPath can look at the environment.
Closes #246.
2022-01-12 14:59:13 -05:00
Nick Mathewson 7d3482ca1a Bump all crate versions to 0.0.3. 2022-01-11 09:40:32 -05:00
Nick Mathewson 4841b50c9f Minimize the required version for each dependency.
I found these versions empirically, by using the following process:

First, I used `cargo tree --depth 1 --kind all` to get a list of
every immediate dependency we had.

Then, I used `cargo upgrade --workspace package@version` to change
each dependency to the earliest version with which (in theory) the
current version is semver-compatible.  IOW, if the current version
was 3.2.3, I picked "3".  If the current version was 0.12.8, I
picked "0.12".

Then, I used `cargo +nightly upgrade -Z minimal-versions` to
downgrade Cargo.lock to the minimal listed version for each
dependency.  (I had to override a few packages; see .gitlab-ci.yml
for details).

Finally, I repeatedly increased the version of each of our
dependencies until our code compiled and the tests passed.  Here's
what I found that we need:

anyhow >= 1.0.5: Earlier versions break our hyper example.

async-broadcast >= 0.3.2: Earlier versions fail our tests.

async-compression 0.3.5: Earlier versions handled futures and tokio
    differently.

async-trait >= 0.1.2: Earlier versions are too buggy to compile our
    code.

clap 2.33.0: For Arg::default_value_os().

coarsetime >= 0.1.20: exposed as_ticks() function.

curve25519-dalek >= 3.2: For is_identity().

generic-array 0.14.3: Earlier versions don't implement
    From<&[T; 32]>

httparse >= 1.2: Earlier versions didn't implement Error.

itertools at 0.10.1: For at_most_once.

rusqlite >= 0.26.3: for backward compatibility with older rustc.

serde 1.0.103: Older versions break our code.

serde_json >= 1.0.50: Since we need its Value type to implement Eq.

shellexpand >= 2.1: To avoid a broken dirs crate version.

tokio >= 1.4: For Handle::block_on().

tracing >= 0.1.18: Previously, tracing_core and tracing had separate
    LevelFilter types.

typenum >= 1.12: Compatibility with rust-crypto crates

x25519-dalek >= 1.2.0: For was_contributory().

Closes #275.
2022-01-07 19:08:58 -05:00
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
Daniel Eades 9b51a52b53 address clippy's latest lint 2021-12-20 09:46:41 +00:00
Nick Mathewson b3b6a92145 Add a few tests to tor-config. 2021-12-07 19:52:49 -05:00
Nick Mathewson 1ff5a513ae Oops: MutCfg shouldn't implement Clone.
We don't want MutCfg to be automatially coneable, or we'll wind up with
surprises like the one that this patch fixes in TorClient.

(The "surprise" is that reconfigure() would only apply its
client-specific options  to one client instance.)
2021-12-07 17:54:24 -05:00
Nick Mathewson 8fed1524fa MutCfg: Add map_and_replace.
This will help in the case when a configuration can only partially
change.
2021-12-07 16:40:49 -05:00
Nick Mathewson f06d5ae48f MutCfg facility to help with reconfiguration.
It's useful to keep configuration objects inside a RwLock<Arc<>>, so we
can have slightly-stale pointers to the existing configuration structure
without holding locks too long.

This code adds a MutCfg type with basic support for this pattern,
and functions to make it a bit more ergonomic.
2021-12-07 15:42:14 -05:00
Nick Mathewson 606d64eac5 Sketch API for reconfiguration.
This patch doesn't actually make anything reconfigurable, but it
does create an API that will tell you "you can't change the value of
that!"  If the API looks reasonable, I can start making it possible
to change the values of individual items.
2021-12-07 15:42:14 -05:00
eta 2920a4d084 Merge branch 'simplify_config_helpers' into 'main'
Change sane_defaults() and with_directories()

See merge request tpo/core/arti!155
2021-11-29 20:42:28 +00:00
Nick Mathewson eef81d9d57 Bump every crate by one patch version. 2021-11-29 15:21:58 -05:00
Nick Mathewson f107794b74 Change sane_defaults() and with_directories()
The sane_defaults() call is now the same as you get from a default
builder: by convention, we just call that method Default::default().

The with_directories() constructor makes more sense as a constructor
for the TorClientConfigBuilder than for TorClientConfig.
2021-11-29 14:20:34 -05:00
Nick Mathewson eb861b7edd Merge branch 'config-updates-and-tests' 2021-11-29 13:59:41 -05:00
Nick Mathewson 0b3bce2e3e Resolve some warnings in tor-config test 2021-11-25 09:39:11 -05:00
Daniel Eades db16d13df4 add semicolons if nothing returned 2021-11-25 13:20:37 +00:00
Daniel Eades 052f51ff71 deglob some enums, use concise iteration syntax 2021-11-25 12:39:52 +00:00
Nick Mathewson f55950ab8d Fix a few typos.
Also fix some commonwealth spellings that had slipped in.
2021-11-24 18:12:44 -05:00
Nick Mathewson 9fdb7d9751 More tests for tor-config. 2021-11-24 08:38:42 -05:00
Nick Mathewson 40ff7113d4 Make every Config type implement Eq.
Doing this is necessary for reconfiguration support, and will help a lot
with testing, too.
2021-11-21 12:06:15 -05:00
Nick Mathewson efdd327569 Rename .gitignore APP_FOO to ARTI_FOO.
Since these shell-variables are hardwired to use org.torproject.Arti as
the program name, it isn't appropriate to call them "app-specific".

If we someday reinstate APP_FOO, it should be based on a user-provided
application name.
2021-11-21 11:29:10 -05:00
Nick Mathewson 05be12e4d8 Give CfgPath an alternative inner representation.
In order to handle explicitly specified path buffers directly, we now
let CfgPath be either a string (that gets expanded) or a PathBuf
(that doesn't).

This simplifies TorClientConfig::with_directories()
2021-11-21 11:17:56 -05:00
Nick Mathewson 0372d24eed Make arti-client config object match arti config better.
Now every section that the two configuration objects share has the
same type and name.  This should help us in documenting our configuration
in a way that doesn't confuse people.

There is still lots of API work to go.
2021-11-21 10:54:34 -05:00
Nick Mathewson 934412586e Use named fields for the elements of ConfigBuildError 2021-11-18 14:31:34 -05:00
Nick Mathewson 5184f5ba84 Move top-level configuration downwards from `arti` to `arti-config`.
To do this at all neatly, I had to split out `tor-config` from
`arti-config` again, and putting the lower level stuff (paths,
builder errors) into tor-config.  I also changed our use of
derive_builder to always use a common error type, to avoid
error type proliferation.
2021-11-18 11:37:48 -05:00
Nick Mathewson e5c5519f7b Remove dependency from arti-client to tor-config.
I'm about to make tor-config a higher-level module, so it can't be a
dependency for tor-config.
2021-11-16 16:01:55 -05:00
Nick Mathewson e6e740646a Bump all crate versions to 0.0.1 2021-10-29 11:05:51 -04:00
eta 4fa0122dde Improve and future-proof the `arti` CLI
This switches out `arti`'s argument-parsing library with `clap`, which
is a lot more featureful (and very widely used within the Rust
ecosystem). We also now use a lot of `clap`'s features to improve the
CLI experience:

- The CLI now expects a subcommand (currently, either "help", or "proxy"
  for the existing SOCKS proxy behaviour). This should let us add
  additional non-SOCKS-proxy features to arti in future.
- `clap` supports default values determined at runtime, so the way the
  default config file is loaded was changed: now, we determine the
  OS-specific path for said file before invoking `clap`, so the help
  command can show it properly.
  - The behaviour of `tor_config` was also changed; now, one simply
    specifies a list of configuration files to load, together with
    whether they're required.
  - That function also way overused generics; this has been fixed.
- Instead of using the ARTI_LOG environment variable to configure
  logging, one now uses the `-l, --log-level` CLI option.
  (The intent is for this option to be more discoverable by users.)
- The `proxy` subcommand allows the user to override the SOCKS port used
  on the CLI without editing the config file.
2021-10-27 19:11:48 +01:00
Nick Mathewson babd0b53ae Remove #![allow(clippy::unwrap_used)] in cmdline.rs 2021-10-21 13:59:37 -04:00
Nick Mathewson 445ec6d220 Fix most warnings from nightly.
(One represents code that I forgot to write.)
2021-10-19 16:21:12 -04:00
Nick Mathewson af7c9d5a0b enable checked_conversions lint. 2021-10-09 16:53:13 -04:00
Nick Mathewson b51e2ff5b3 Upgrade memmap2, directories, and dirs dependencies. 2021-09-23 08:26:29 -04:00
Daniel Eades fb3b8b84b5 fix/silence clippy lints in test modules 2021-09-08 17:28:31 +02:00
Nick Mathewson 557a0ff40b Move all crates into a `crates` subdirectory.
This will cause some pain for now, but now is really the best time
to do this kind of thing.
2021-08-27 09:53:09 -04:00