Commit Graph

302 Commits

Author SHA1 Message Date
Ian Jackson a6d7e38f6d tor-config Listen: Add a note about EADDRINUSE
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/602#note_2830848
2022-08-25 18:41:28 +01:00
Ian Jackson 81bf8d5f4d tor-config; Listen: Return addresses in groups for error behaviour
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/602#note_2830766
2022-08-25 18:41:28 +01:00
Ian Jackson 846fe3d520 tor-config: Provide resolve_alternative_specs 2022-08-25 18:41:28 +01:00
Ian Jackson 3af1f3e712 tor-config: Support tracking deprecated config keys 2022-08-25 18:41:28 +01:00
Ian Jackson 33358379f4 tor-config: Introduce ResolutionResults
This will allow us to handle new kinds of warnigns etc.
2022-08-25 18:41:03 +01:00
Ian Jackson 29a24a9dcb tor-config: Rename UnrecognizedKey to DisfavouredKey
We're going to want the to use the same type for deprecated keys.
2022-08-25 18:40:14 +01:00
Ian Jackson f588268128 tor-config: Provide misc::Listen 2022-08-25 18:40:14 +01:00
Ian Jackson 00c51bf63f tor-config misc tests: Add standard lint suppression block 2022-08-25 18:40:14 +01:00
Ian Jackson a931ec08bd tor-config: tests: Apply standard lint block in sources.rs
Fixes a spurious clippy warning on nightly, about a dbg!
2022-08-25 16:33:59 +01:00
Ian Jackson ae5ca43779 tor-config: semver.md: Document change to ConfigurationSource enum 2022-08-25 15:58:29 +01:00
Ian Jackson 2662fd0d71 tor-config source: just ConfigurationSource, not FoundConfigFile
FoundConfigFile existed to hide something that ConfigurationSource now
exposes.
2022-08-25 15:58:29 +01:00
Ian Jackson 9c00ec7da4 tor-config: Replace dir detection with ConfigurationSource enum
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/682#note_2830860

And subsequent IRC discussion.

Having done the work as per review comments, I don't much like the
result.  It's quite un-ergonomiuc.  If we can't have fs autodetection,
I think syntactic autodetection within sources.rs would be nearly as
nice.

However, I seem to be outvoted.  At least the externally visible
functionality (of an arti binary, say) is reasonably ergonomic.
2022-08-25 15:58:29 +01:00
Ian Jackson e98bdf6004 tor-config: Provide is_syntactically_directory helper function 2022-08-25 15:58:29 +01:00
Ian Jackson a3005d8c0a tor-config: MustRead: Make public
I think this ought to be exhaustive.
2022-08-25 15:58:29 +01:00
Ian Jackson 7c0637ad44 config watch: Fix and reduce debounce interval
The parameter to FileWatcher::new is not a polling time fallback; it
is a "debounce time".  Events are always delayed by at least this
much.

10s is much too long for this.  1s is more appropriate.
2022-08-25 15:58:29 +01:00
Ian Jackson 7d8b3e2f2f config sources: Read arti.d as well as arti.toml
Fixes #474 aka #271
2022-08-25 15:58:29 +01:00
Ian Jackson ba94c4a4fa config sources tests: Test results of directory scan 2022-08-25 15:58:29 +01:00
Ian Jackson b700816eef config sources tests: Break out sources_nodefaults 2022-08-25 15:58:29 +01:00
Ian Jackson e4fea3e1ea config sources tests: Introduce test of reading directory 2022-08-25 15:58:29 +01:00
Ian Jackson 08767f59d8 config sources: Supporting reading directories 2022-08-25 15:58:29 +01:00
Ian Jackson 7d088cf8df config sources: Introduce scan() and FoundConfigFiles
We're going to need to do config file reading in two phases.

Right now this isn't actually necessary, because the set of files
is fixed since we don't support dynamically scanning directories.
But the new API will be needed in a moment.

Code motion and API changes, but no overall functional change.
Review with `git show -b` may be helpful.

The new API also provides for dealing with directories, but right now
that doesn't happen.
2022-08-25 15:58:29 +01:00
Ian Jackson cd2432474c tor-config sources: Remove some unneeded .to_string() from tests 2022-08-25 15:58:29 +01:00
trinity-1686a 7f939fa480 enable doc_auto_cfg feature on every crate when documenting for docs.rs 2022-08-24 18:22:41 +02:00
Ian Jackson ee2580face tor-config: resolve_option_general: Add semver note 2022-08-23 14:21:13 +01:00
Ian Jackson 0c747b8069 tor-config: resolve_option_general: Add TODO about example 2022-08-23 14:20:49 +01:00
Nick Mathewson 32c14d37bf Fix syntax in doc comment. 2022-08-23 12:59:41 +00:00
Ian Jackson 457c17adb0 tor-config: Provide resolve_option_general, for T: !Default etc.
At one point in this MR I thought I was going to want this for
arti::cfg::ListenConfig (which we don't want to be Default).

In fact ListenConfig is being handled specially, but having written
this function it seemed sensible to keep it.  Since resolve_option
becomes a wrapper for it, the existing tests exercise it.
2022-08-22 16:26:38 +01:00
Ian Jackson d9338293c8 Add semver notes 2022-08-17 10:54:41 +01:00
eta e5396a35c8 Fix typos in comments. 2022-08-17 10:54:41 +01:00
Ian Jackson 2fbc196f8e tor-config: Introduce PaddingLevel
This will be used for controlling channel padding, for now.
2022-08-16 18:38:53 +01:00
Ian Jackson fbe80fd417 tor-config: Introduce ReconfigureError::Bug
Reconfigurations might fail due to internal errors.
2022-08-16 18:37:06 +01:00
Ian Jackson 33e0d67018 Update shellexpand, and switch to non-fork
Now we have bus>1 ownership of the crate name `shellexpand`.  I have
made a release, and retired `shellexpand-fork`.

The new shellexpand release switches to a (quite similarly) unforked
version of `dirs`.
2022-08-05 15:36:47 +01:00
Nick Mathewson 859ae4acd0 Bump patch versions on crates that have new APIs.
Do _not_ bump the dependency versions on crates that have had no
changes since arti 0.0.5, since those crates do not depend on the
new APIs.

```
cargo set-version -p tor-basic-utils   --bump patch
cargo set-version -p tor-llcrypto      --bump patch
git restore crates/tor-checkable
git restore crates/tor-consdiff
git restore crates/tor-rtmock
```
2022-08-01 09:56:29 -04:00
Nick Mathewson 511cb46997 Bump minor version on crates with deps with breaking changes.
This performs the transitive closure of the last operation:
everything that depends on a crate with a breaking change gets the
version which it depends on bumped.

```
cargo set-version -p tor-proto         --bump minor
cargo set-version -p tor-netdoc        --bump minor
cargo set-version -p arti-hyper        --bump minor
cargo set-version -p arti-bench        --bump minor
cargo set-version -p arti-testing      --bump minor
cargo set-version -p tor-config        --bump minor
```
2022-08-01 09:49:13 -04:00
Nick Mathewson f5dcb98f06 Bump minor versions on all crates that have had breaking changes.
Done with these commands:

```
cargo set-version -p fs-mistrust       --bump minor
cargo set-version -p tor-bytes         --bump minor
cargo set-version -p tor-socksproto    --bump minor
cargo set-version -p tor-cert          --bump minor
cargo set-version -p tor-linkspec      --bump minor
cargo set-version -p tor-cell          --bump minor
cargo set-version -p tor-netdir        --bump minor
cargo set-version -p tor-persist       --bump minor
cargo set-version -p tor-chanmgr       --bump minor
cargo set-version -p tor-guardmgr      --bump minor
cargo set-version -p tor-circmgr       --bump minor
cargo set-version -p tor-dirclient     --bump minor
cargo set-version -p tor-dirmgr        --bump minor
cargo set-version -p arti-client       --bump minor
cargo set-version -p arti              --bump minor
```
2022-08-01 09:43:09 -04:00
trinity-1686a eed8032dbd fix nighly clippy 2022-07-23 20:25:33 +02:00
Nick Mathewson 20435aea75 Bump crate and dependency versions.
These were done with the following commands:

```
cargo set-version -p tor-basic-utils   --bump patch
cargo set-version -p fs-mistrust       --bump minor
cargo set-version -p tor-error         --bump patch
cargo set-version -p tor-config        --bump patch
cargo set-version -p tor-units         --bump patch
cargo set-version -p tor-rtcompat      --bump minor
cargo set-version -p tor-llcrypto      --bump patch
cargo set-version -p tor-bytes         --bump minor
cargo set-version -p tor-socksproto    --bump minor
cargo set-version -p tor-cert          --bump minor
cargo set-version -p tor-cell          --bump minor
cargo set-version -p tor-proto         --bump minor
cargo set-version -p tor-netdoc        --bump patch
cargo set-version -p tor-netdir        --bump minor
cargo set-version -p tor-persist       --bump patch
cargo set-version -p tor-chanmgr       --bump minor
cargo set-version -p tor-guardmgr      --bump minor
cargo set-version -p tor-circmgr       --bump patch
cargo set-version -p tor-dirclient     --bump patch
cargo set-version -p tor-dirmgr        --bump minor
cargo set-version -p arti-client       --bump patch
cargo set-version -p arti              --bump minor
cargo set-version -p arti-bench        --bump minor
cargo set-version -p arti-testing      --bump minor
```
2022-06-24 12:00:22 -04:00
Ian Jackson 23c352b96b clippy: Consolidate many lints in maint/add_warning
Found these by disabling the nightly dbg macro special case.  Now, we
have a mechanism for globally adding suppressions to tests, we can use
that instead.
2022-06-24 14:23:38 +01:00
Ian Jackson 589c6e52bb Run maint/add_warning crates/*/src/{lib,main}.rs
Update all lint blocks
2022-06-23 19:15:42 +01:00
Nick Mathewson c39631af27 tor-config: style fixes on CfgPathError. 2022-06-22 08:36:13 -04:00
Nick Mathewson 37cbd38abc tor-config: Don't format source error as part of error message
This is one I missed earlier.
2022-06-22 08:23:33 -04:00
Ian Jackson 90ba8b15de impl_standard_builder: Allow for !Default 2022-06-16 15:42:06 +01:00
Ian Jackson c895057cb9 tor-config: impl_standard_builder: handle contexts with local Result 2022-06-16 15:27:00 +01:00
Ian Jackson baca49e087 config: Suppose that we might extend resolve_option to non-T::Default
As per point 3 in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/488
2022-06-10 14:23:16 +01:00
Ian Jackson 77f33176c3 config: Do not strip_option for journald (and in future)
As per point 1 in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/488
2022-06-10 14:23:13 +01:00
Dimitris Apostolou 8488192ba1
Fix typos 2022-06-05 18:47:51 +03:00
Ian Jackson 9f4fe6a484 tor-config: Fix a doc link
Nightly cargo doc complaints about this.
2022-06-01 15:48:45 +01:00
Ian Jackson 98ccd7e7e2 Merge branch 'lint' into 'main'
lints: Make lint blocks consistent and ensure they stay that way

Closes #469

See merge request tpo/core/arti!557
2022-05-31 18:27:53 +00:00
Ian Jackson 9aec60871c Merge branch 'config-test' into 'main'
arti config: Check that example config is exhaustive

See merge request tpo/core/arti!546
2022-05-31 16:33:27 +00:00
Ian Jackson 89c4f76b6c tor-config: Suppress unwrap lint in tests
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/546#note_2808892
2022-05-31 16:58:14 +01:00
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