Commit Graph

48 Commits

Author SHA1 Message Date
Ian Jackson 42df88d6bf Run maint/add_warning to add lint block everywhere 2023-08-23 10:34:00 +01:00
Nick Mathewson cec6d0ce33 Run add_warnings on all files. 2023-08-04 07:45:04 -04:00
Nick Mathewson 5cc3fe1629 Bump patchlevel versions of crates with trivial changes
These crates have had trivial changes only: typically,
changes to documentation or to clippy warnings.  There's no
good reason to update which version of them other crates depend on,
so we only bump _their_ patchlevels.

```
tor-async-utils
caret
safelog
tor-events
tor-units
tor-rtcompat
tor-rpcbase
tor-llcrypto
tor-protover
tor-bytes
tor-hscrypto
tor-socksproto
tor-cert
tor-cell
tor-consdiff
tor-congestion
arti-rpcserver
arti-testing
arti-bench
arti-config
arti-hyper
```
2023-08-01 11:03:56 -04:00
Nick Mathewson 3acdf102c7 Increment patchlevel versions of crates with minor changes
These crates are at version 0.x.y, so we don't need to distinguish
new-feature changes from other changes:

```
tor-basic-utils
fs-mistrust
tor-error
tor-geoip
tor-checkable
tor-linkspec
tor-netdoc
tor-netdir
tor-persist
tor-ptmgr
tor-hsservice
```

This crate has a breaking change, but only when the semver-breaking
feature `experimental-api` is enabled:

```
tor-config
```

This crate is at version 1.x.y, but has no new public APIs, and
therefore does not need a minor version bump:

```
arti
```
2023-08-01 10:57:55 -04:00
Dimitris Apostolou 947ddfff0c
Fix typos 2023-07-22 10:10:34 +03:00
Ian Jackson 473447a82e Run maint/add_warning to actually apply new lint allows 2023-07-10 13:49:51 +01:00
Nick Mathewson 03f9f9987a Run add_warning to remove `missing_panics_doc` deny.
Closes #950.
2023-07-06 14:32:23 -04:00
Nick Mathewson de13a7319b Bump patchlevel versions on crates with smaller changes
Done with the commands below.

The following crates have had various changes, and should get a
patchlevel bump. Since they are pre-1.0, we do not need to
distinguish new APIs from other changes.

```
cargo set-version --bump patch -p arti-client
cargo set-version --bump patch -p safelog
cargo set-version --bump patch -p tor-bytes
cargo set-version --bump patch -p tor-cert
cargo set-version --bump patch -p tor-circmgr
cargo set-version --bump patch -p tor-config
cargo set-version --bump patch -p tor-consdiff
cargo set-version --bump patch -p tor-dirclient
cargo set-version --bump patch -p tor-dirmgr
cargo set-version --bump patch -p tor-error
cargo set-version --bump patch -p tor-hsservice
cargo set-version --bump patch -p tor-linkspec
cargo set-version --bump patch -p tor-llcrypto
cargo set-version --bump patch -p tor-netdir
cargo set-version --bump patch -p tor-netdoc
cargo set-version --bump patch -p tor-proto
cargo set-version --bump patch -p tor-rpcbase
cargo set-version --bump patch -p tor-socksproto
```

This crate has new features, but no new non-experimental Rust APIs.
So even though it is post-1.0, it gets a patchlevel bump.

```
cargo set-version --bump patch -p arti
```
2023-06-30 08:42:21 -04:00
Ian Jackson 161b9844da lints: Run maint/add_warning to actually apply new lints 2023-06-21 12:15:41 +01:00
Ian Jackson affa5b5e91 Merge branch 'rpcdoc' into 'main'
rpc: Minor docs improvements

See merge request tpo/core/arti!1260
2023-06-20 12:11:49 +00:00
Ian Jackson 85a046e266 rpc: Cross-reference up from tor-rpcbase re where DispatchTable lives 2023-06-16 17:48:59 +01:00
Ian Jackson 1710ce54f4 rpc: Remove some verbiage about 'static, and demo that it's OK without
It's now not actually possible to write code that doesn't work, even
if `Tr` *isn't* 'static, because of the bounds on `CastTable::insert`.

I tried to produce a non-working setup with a non-static `Simple`, but
you can't implement `Object` for such a thing.  Removing 'static from
Object would stop the downcasts from Any to Object working.

Prior to the new typesafe insert, this change
  - let f: fn(&dyn $crate::Object) -> &(dyn $traitname + 'static) = |self_| {
  + let f: fn(&dyn $crate::Object) -> &(dyn $traitname) = |self_| {
would result in a runtime crash.  Now it results in a compiler error.
2023-06-15 12:07:11 +01:00
Ian Jackson 0eedf0e254 rpc: Give the name `O` to "the type associated with this CastTable"
This was locally bound to `S` in one place.  Bind and use it throughout.
Since this is an RPC object, `O` is a better name.

In each item, use the description once and thereafter just the name.
2023-06-15 12:03:53 +01:00
Ian Jackson 2228751a00 rpc: Add Simple test case for CastTable 2023-06-15 12:03:53 +01:00
Ian Jackson 54b364cdcf rpc: Move boxing from macro to CastTable::insert (formatting) 2023-06-15 12:03:53 +01:00
Ian Jackson 890a7b52be rpc: Move boxing from macro to CastTable::insert 2023-06-15 11:32:32 +01:00
Ian Jackson 8452fe11cf rpc: Make CastTable::insert be more type-safe
This checks the Requirements.
2023-06-15 11:13:26 +01:00
Nick Mathewson 8166a29746 RPC: Functionality to downcast dyn Object to a dyn Trait.
This is a rather tricky piece of functionality.  It works as
follows.

We introduce a `CastTable` type.  Each `CastTable` tells us how to
downcast `dyn Object` for objects of a single concrete type.
The `Object` type now has a `get_casttable` method that returns
an empty `CastTable` by default.

`CastTable` is, internally, a map from the `TypeId` of the target
dyn Trait reference type to a function
`fn(&dyn Object) -> &dyn Trait`.  These functions are stored as
`Box<dyn Any + ...>`.  (They are Boxed because they may refer to
generic functions, which you can't get a static reference to,
and they're Any because the functions have different types.)

The `decl_object!` macro now implements `get_casttable` as
appropriate.  (The syntax is a bit janky, but that's what we get
for not using derive_adhoc.)  For non-generic types, `get_casttable`
uses a Lazy<CastTable>`. to initialize a CastTable exactly once.
For generic types, it use a `Lazy<RwLock<HashMap<..>>` to
build one CastTable per instantiation of the generic type.

This could probably be optimized a bit more, the yaks could be
shaved in a more scintillating hairstyle, and the syntax for
generic `decl_object` could definitely be improved.
2023-06-12 13:35:28 -04:00
Nick Mathewson 999f914e03 rpc: make decl_object! responsible for writing impl Object {} blocks. 2023-06-07 14:37:04 -04:00
Nick Mathewson b7feb034a9 RPC: Let objects declare that they need a GlobalId. 2023-06-05 14:46:51 -04:00
Nick Mathewson daf5ecc153 Bump crate versions in preparation for v1.1.5 release.
Generated with the following commands:

```
cargo set-version --bump minor -p tor-cell
cargo set-version --bump minor -p tor-linkspec
cargo set-version --bump minor -p tor-proto
cargo set-version --bump minor -p tor-netdoc
cargo set-version --bump minor -p tor-circmgr

cargo set-version --bump patch -p tor-cert
cargo set-version --bump patch -p tor-basic-utils
cargo set-version --bump patch -p tor-rpcbase
cargo set-version --bump patch -p tor-llcrypto
cargo set-version --bump patch -p tor-hscrypto
cargo set-version --bump patch -p tor-checkable
cargo set-version --bump patch -p tor-async-utils
cargo set-version --bump patch -p caret
cargo set-version --bump patch -p fs-mistrust
cargo set-version --bump patch -p safelog
cargo set-version --bump patch -p retry-error
cargo set-version --bump patch -p tor-error
cargo set-version --bump patch -p tor-config
cargo set-version --bump patch -p tor-events
cargo set-version --bump patch -p tor-units
cargo set-version --bump patch -p tor-rtcompat
cargo set-version --bump patch -p tor-rtmock
cargo set-version --bump patch -p tor-protover
cargo set-version --bump patch -p tor-bytes
cargo set-version --bump patch -p tor-socksproto
cargo set-version --bump patch -p tor-consdiff
cargo set-version --bump patch -p tor-netdir
cargo set-version --bump patch -p tor-congestion
cargo set-version --bump patch -p tor-persist
cargo set-version --bump patch -p tor-chanmgr
cargo set-version --bump patch -p tor-ptmgr
cargo set-version --bump patch -p tor-guardmgr
cargo set-version --bump patch -p tor-dirclient
cargo set-version --bump patch -p tor-dirmgr
cargo set-version --bump patch -p tor-hsclient
cargo set-version --bump patch -p tor-hsservice
cargo set-version --bump patch -p arti-client
cargo set-version --bump patch -p arti-rpcserver
cargo set-version --bump patch -p arti-config
cargo set-version --bump patch -p arti-hyper
cargo set-version --bump patch -p arti
cargo set-version --bump patch -p arti-bench
cargo set-version --bump patch -p arti-testing
```
2023-06-01 10:03:05 -04:00
Nick Mathewson 936387efee rpc: Remove downgrade_owned for now
Rationale: Our weak-vs-strong design is a bit confused at the moment
due to concerns about deduplication and  capability semantics.  It's
not clear that a general "change strong to weak" method is
compatible with what we want to provide.
2023-05-24 10:15:56 -04:00
Nick Mathewson 9713e8d305 rpc: Implement functionality to remove objects from a session
I've made doing some design choices here:
  * Reserving "rpc" as a prefix for post-authentication
    functionality that is not arti-specific.
  * Declaring these to be methods on the session rather than methods
    on the objects themselves.

There's a problem with defining an API to drop a weak reference; see
comment in code.
2023-05-24 10:15:56 -04:00
Nick Mathewson 15a8644bf7 rpc: fix documentation for methods in Context. 2023-05-24 10:15:56 -04:00
Nick Mathewson 7a5373c110 Run fixup-features --no-annotate for initial Cargo.toml fixes.
This does the following:
  - Gives every crate a `full`.
  - Cause every `full` to depend on `full` from the lower-level
    crates.
  - Makes every feature listed _directly_ in `experimental` depend
    on `__is_experimental`.
2023-05-15 09:07:21 -04:00
Nick Mathewson 9be9ddb902 RPC: Add "register" methods to RequestContext. 2023-05-04 10:35:05 -04:00
Nick Mathewson 1904cfc8b9 Increment crate versions.
Because of the errorkind bumps, we're calling this a breaking change
in everything lower-level than `arti`.

Generated with:
```
cargo set-version -p tor-basic-utils --bump minor
cargo set-version -p tor-async-utils --bump minor
cargo set-version -p caret --bump minor
cargo set-version -p fs-mistrust --bump minor
cargo set-version -p safelog --bump minor
cargo set-version -p retry-error --bump minor
cargo set-version -p tor-error --bump minor
cargo set-version -p tor-config --bump minor
cargo set-version -p tor-events --bump minor
cargo set-version -p tor-units --bump minor
cargo set-version -p tor-rtcompat --bump minor
cargo set-version -p tor-rtmock --bump minor
cargo set-version -p tor-rpcbase --bump minor
cargo set-version -p tor-llcrypto --bump minor
cargo set-version -p tor-protover --bump minor
cargo set-version -p tor-bytes --bump minor
cargo set-version -p tor-hscrypto --bump minor
cargo set-version -p tor-socksproto --bump minor
cargo set-version -p tor-checkable --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-proto --bump minor
cargo set-version -p tor-netdoc --bump minor
cargo set-version -p tor-consdiff --bump minor
cargo set-version -p tor-netdir --bump minor
cargo set-version -p tor-congestion --bump minor
cargo set-version -p tor-persist --bump minor
cargo set-version -p tor-chanmgr --bump minor
cargo set-version -p tor-ptmgr --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 tor-hsclient --bump minor
cargo set-version -p tor-hsservice --bump minor
cargo set-version -p arti-client --bump minor
cargo set-version -p arti-rpcserver --bump minor
cargo set-version -p arti-config --bump minor
cargo set-version -p arti-hyper --bump minor

cargo set-version -p arti --bump patch
cargo set-version -p arti-bench --bump patch
cargo set-version -p arti-testing --bump patch
```
2023-05-03 08:31:11 -04:00
Nick Mathewson 7c1f45a514 RPC: Log all internal errors. 2023-04-19 12:38:26 -04:00
Nick Mathewson ffcbd8fe88 rpc: Simplify and clarify SendUpdateError. 2023-04-19 12:38:26 -04:00
Nick Mathewson accd3d858f Arti: Add ability to remember the list of methods names.
Right now, this lets us say whether the method was unrecognized or
whether the parameter type was incorrect.

We'll use this to enforce correct method names later on.

(I have to add another `inventory` here, since the `typetag`
maintainer does not want to expose this functionality: see
https://github.com/dtolnay/typetag/issues/57#issuecomment-1506106290
)
2023-04-19 12:38:26 -04:00
Nick Mathewson e6092e99ea rpc: New syntax for method declaration
Now you just declare your function `my_func` with the right types,
and invoke `rpc_invoke_fn!{ my_func(ObjType, MethodType); }`
2023-04-19 12:38:26 -04:00
Nick Mathewson a415b0e2d2 rpc: impl From<SendUpdateError> for RpcError. 2023-04-19 12:38:26 -04:00
Nick Mathewson 6f6a4d073e rpcbase: Use with_fn. 2023-04-19 12:38:26 -04:00
Nick Mathewson 80a13ff898 rpc: Minor tweaks to get a sink to compile. 2023-04-19 12:38:26 -04:00
Nick Mathewson 0503f7bd4b rpc: Use Method types to determine type of method outputs, updates.
This lets us do much less in our rpc_invoke_fn functions.
2023-04-19 12:38:26 -04:00
Nick Mathewson 7dcfb02c22 rpc: Split Method into DynMethod and Method
Now `Method` has an Output and Update associated type, and
`decl_method` can do a little more.
2023-04-19 12:38:26 -04:00
Nick Mathewson 5a2c38a134 rpc: simplify API by always providing a sink.
Previously we have two places where we had to do "make a `Drain` sink
if updates aren't wanted"; now there's only one.
2023-04-16 08:46:42 -04:00
Nick Mathewson 58ad91cbf5 rpc: Wire updates into rpc invoke functions again.
Now that the sink is not part of the context, RPC functions that are
able to send an update have to declare an `impl Sink` as their
fourth argument.  This syntax is not final.

Part of #824.
2023-04-16 08:46:42 -04:00
Nick Mathewson 3b9fc60763 rpc: Move update sink out of context.
Now the update sink is its own boxed object.  It is not yet passed
to the invoke functions that want it.
2023-04-16 08:46:41 -04:00
Nick Mathewson 8dd65dcd5f rpc, spec: Document current ObjectError, RequestError behavior as correct. 2023-04-13 09:03:52 -04:00
Nick Mathewson 739561b2cb rpcbase: Use correct error codes, and add tests.
Well, mostly correct.  Our current serde implementation doesn't
tell us much about what went wrong with the object, so we can't
tell why we couldn't convert it into a Request.

Also, our output for the data field is not as the spec says:
we should bring them into conformance.

Part of #825.
2023-04-12 13:32:15 -04:00
Nick Mathewson 2e017d3575 tor-rpcbase: Create error kinds properly.
The field is called "kinds", it is a list, and it holds strings
beginning with "arti:".
2023-04-12 12:27:16 -04:00
Nick Mathewson 193253a158 tor-rpcbase: rename cmd to method everywhere. 2023-04-12 11:45:30 -04:00
Nick Mathewson 224b919835 tor-rpcbase: Rename cmd.rs to method.rs. 2023-04-12 11:26:12 -04:00
Nick Mathewson c5b70224b2 tor-rpcbase: Rename and rephrase "command" to "method" 2023-04-12 11:25:03 -04:00
Nick Mathewson 8e6848b965 rpc: Try to fix rustdoc errors. 2023-04-12 08:02:30 -04:00
Nick Mathewson 44fbd87208 rpc: Use empty structs in test code. 2023-04-12 07:35:07 -04:00
Nick Mathewson 9a5f319a84 Rename tor-rpccmd to tor-rpcbase. 2023-04-12 07:34:57 -04:00