Commit Graph

110 Commits

Author SHA1 Message Date
Nick Mathewson 2e1115acc3 rpc: Change the formatting of object IDs
We want each ID to have a unique form every time it is given out,
so that you can't use ID==ID to check whether Object==Object.  (See
discussions leading to #848.)

We'd also like the form of object IDs to be a little annoying to
analyze, to discourage people from writing programs that depends on
their particular format.  (We are reserving the right to change the
format whenever we want.)

We _don't_ want to use any cryptography here (yet), lest somebody
think that this is an actual security mechanism.  (This isn't for
security; it's for encouraging developers to treat IDs as opaque.)

With that in mind, we now lightly obfuscate our generational indices
before returning them.
2023-05-15 15:59:58 -04:00
Nick Mathewson 8531ed2dad rpc: rename GenIdx::into/try_from implementations
These are about to become nondeterministic-ish and probably shouldn't
use the Into/TryFrom traits.
2023-05-15 15:26:58 -04:00
Nick Mathewson 0d207028ce rpc: do not deduplicate strong object ids
Per discussion referenced at #848, we want each operation that
returns a strong object ID to return a new, distinct strong ID.

Note that we no longer need to put strong and weak references in the
same arena; we can clean this code up a lot down the road.
2023-05-15 15:26:53 -04:00
Nick Mathewson c9819455e1 rpc: Repair an error in our ObjectId encoding.
Now we generate object IDs that we can parse.  This is about to be
obsolete once we change how we generate objects and their IDs for #848,
but we may as well start from a working state.
2023-05-15 13:48:47 -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 da185223c0 objmap: move types to top of file. 2023-05-04 10:37:27 -04:00
Nick Mathewson 7918904b99 Note/clean more TODOs in objmap. 2023-05-04 10:37:27 -04:00
Nick Mathewson 6fb5d08103 RPC: Make the "client" return optional. 2023-05-04 10:37:27 -04:00
Nick Mathewson 0e3fa38c03 RPC: Make "Weak" and "Strong" entries separate.
Now there can be one of each, since we want references and handles
to be conceptually separate.

(The alternative would be to say that an operation either "returns a
handle" or "returns a reference (which may become a handle) unless a
handle already exists.")
2023-05-04 10:37:27 -04:00
Nick Mathewson 7f59d7dae5 Temporarily replace generational-arena with a fake version.
This fake version is completely silly, but it will do the job until
we figure out our MPL2 concerns.
2023-05-04 10:37:27 -04:00
Nick Mathewson 54dabdbd0c RPC: make arti-rpcserver require the arti-client/rpc feature 2023-05-04 10:37:25 -04:00
Nick Mathewson b807e834a3 RPC: Rename session.rs to connection.rs 2023-05-04 10:35:05 -04:00
Nick Mathewson 7845f04908 RPC: rename Session to Connection.
To me, "Session" suggests that we're authenticated, when we are
not necessarily authenticated.  Also, we may eventually want to have
some kind of persistent session object; if we do, then we'll want
Connections to be separate.
2023-05-04 10:35:05 -04:00
Nick Mathewson 94df123932 RPC: Make authentication return a TorClient.
(This is the correct capabilities-based behavior. For now it will only
work if the TorClient uses a PreferredRuntime, but with luck we will
find a solution for #837 soon.)
2023-05-04 10:35:05 -04:00
Nick Mathewson 475da9b802 Add a generational arena for object mapping for RPC.
See the comments on `TypedAddr` for some explanations about
why this is so tricky.  Thanks to @diziet for helping me figure
this out.
2023-05-04 10:35:05 -04:00
Nick Mathewson 9be9ddb902 RPC: Add "register" methods to RequestContext. 2023-05-04 10:35:05 -04:00
Nick Mathewson d7ab388faf RPC: Start on plumbing TorClient into our RPC code
Because of #837, we won't be able to work with _every_ TorClient<R>,
so I'm only going to be using TorClient<PreferredRuntime> for now.
2023-05-04 10:35:03 -04:00
Nick Mathewson 879a453212 RPC: Move the "listen" part of the RPC listener code to `arti`.
Now there's a module in `arti` that runs the loop for an RPC
listener.  The part of the old `listener` module that made
the framed connections is now part of the `Session` object.

There is now yet another a temporary location for the pipe; we
should pick something better.  At least now it's configurable.
2023-05-04 10:30:40 -04:00
Nick Mathewson 25398b5a3b rpc: Make an RpcMgr type to own the DispatchTable.
In the future, this will probably hold more data as well, like a
TorClient and some configuration info.

The TorClient will present an issue; I've made comments about that.

Closes #820
2023-05-04 10:22:27 -04:00
Nick Mathewson e845a553f3 Upgrade tracing to 0.1.36.
This is the first version to impl Value for String.

With luck, this will get minimal_versions CI passing.
2023-05-03 11:09:21 -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 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 f33aefd76c rpcserver: Use with_fn. 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
Ian Jackson 219153a541 Merge branch 'rpc_refactoring_v2' into 'main'
A few RPC refactorings

Closes #817 and #824

See merge request tpo/core/arti!1144
2023-04-18 16:00:05 +00: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 83f5dc4888 rpc: Ensure well-ordering of responses.
Previously the main loop received updates via a `mpsc::channel`, and
final responses via a `futures::unordered`.  This could lead to
final responses being transmitted to the user before the updates
were all flushed.

Now all of the responses are sent to the main loop via the same channel,
and they can't get out-of-sequence.

Closes #817 and (IMO) simplifies the code a bit.
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 c51f44aa0b rpcserver: Fix a couple of broken rustdoc links 2023-04-16 08:39:52 -04:00
Nick Mathewson ea77f959fb rpc: Change `id=<SYNTAX>` to "no id".
Now instead of hoping that buggy clients will detect a magic `id`,
we can simply tell them that they will get no `id` at all.  If they
can't handle that case, no major harm is done: the connection will
get closed anyway.
2023-04-13 09:03:52 -04:00
Nick Mathewson 5041b51498 rpc: Require that errors are RpcError.
Since we're serializing everything in this format, let's enforce it.
With this change, we can no longer cram arbitrary junk into an
RPC error, so we have to clean up our handling of cancelled requests.
2023-04-13 09:03:52 -04:00
Nick Mathewson 767c91557e rpc: Improve error reporting for invalid requests
This is a bit big, but it's not that _complicated_.

The idea here is that we use serde's "untagged" enum facility
when parsing our `Request`s, such that if parsing as a `Request`
fails, we parse as an `InvalidRequest` and try to report
what the problem was exactly.

This lets us determine the ID of a request (if it had one),
so we can report that ID in our error message.  We can also
recover from a much broader variety of errors.

We now also conform with the spec reporting errors about
completely wrong json, requests without IDs, and so on.
2023-04-12 16:21:34 -04:00
Nick Mathewson 6bdfc5740f arti-rpcserver: Be careful about saying "result".
Even though json-rpc uses "result" to mean "a successful return value
from a method", we can't: Rust's `Result` type is so pervasive
that confusion would be inevitable.
2023-04-12 12:08:53 -04:00
Nick Mathewson 4d82bf4b98 arti-rpcserver: Rename Authentication{Method => Scheme}. 2023-04-12 11:53:50 -04:00
Nick Mathewson 4327276922 arti-rpcserver: rename cmd to method. 2023-04-12 11:51:48 -04:00
Nick Mathewson b2b0a0dd83 arti-rpcserver: rename command to method. 2023-04-12 11:51:37 -04:00
Nick Mathewson c5b70224b2 tor-rpcbase: Rename and rephrase "command" to "method" 2023-04-12 11:25:03 -04:00
Nick Mathewson 9a5f319a84 Rename tor-rpccmd to tor-rpcbase. 2023-04-12 07:34:57 -04:00
Nick Mathewson 5979272cc4 rpc: Make AuthenticationMethod an enum. 2023-04-12 07:34:57 -04:00
Nick Mathewson 0eb15ae592 rpc: Reify and expose DispatchTable. 2023-04-12 07:34:57 -04:00
Nick Mathewson a02a200ccd rpc: Use Pin<Box<Stream/Sink>> for run_loop 2023-04-12 07:34:57 -04:00
Nick Mathewson 3ad5d2f6ea rpc: Import Pin/Context/Poll.
(Except for one case where we are using crate::Context and
task::Context at the same time.)
2023-04-12 07:34:57 -04:00
Nick Mathewson 8845309125 rpc: Document our intended read-blocking behavior. 2023-04-12 07:34:57 -04:00
Nick Mathewson ed1cbce13a rpc: Switch JsonLinesEncoder to have Default, not new. 2023-04-12 07:34:57 -04:00
Nick Mathewson 03937e35b2 rpc: Rename BoxedResponseBody => ResponseBody 2023-04-12 07:34:57 -04:00
Nick Mathewson 07bb57a4c2 rpc: Remove anyhow dependency 2023-04-12 07:34:57 -04:00
Nick Mathewson ff68a5f02a rpc: Add standard warnings to arti-rpcserver 2023-04-12 07:34:57 -04:00
Nick Mathewson b024fe5596 rpc: Add an authentication step.
Per our design, every connection starts out unauthenticated, and
needs one authenticate command to become authenticated.

Right now the only authentication type is "This is a unix named
socket where everybody who can connect has permission."
2023-04-12 07:34:57 -04:00
Nick Mathewson f9de7929c1 RPC: add a temporary "listen" function.
It requires tokio, it's unix-only, and makes some unfortunate
shortcuts.  Probably good enough for initial testing.
2023-04-12 07:34:57 -04:00
Nick Mathewson 3e64cab62d rpc: Declare a trivial Echo command that works on a session. 2023-04-12 07:34:57 -04:00
Nick Mathewson 41cba18899 rpc: Wire up arti-rpcserver to use tor-rpccmd. 2023-04-12 07:34:57 -04:00
Nick Mathewson 3fbcead7dc rpc: do a better job of hiding impl_const_type_id! 2023-04-12 07:34:57 -04:00
Nick Mathewson e26d9452dc RPC: Initial implementation of a multiple-argument dispatch
This code uses some kludges (discussed with Ian previously and
hopefully well documented here) to get a type-identifier for each
type in a const context.  It then defines a macro to declare a
type-erased versions of a concrete implementation functions, and
register those implementations to be called later.

We will probably want to tweak a bunch of this code as we move ahead.
2023-04-12 07:34:57 -04:00
Nick Mathewson a4660a4e09 Start on a lower-level tor-rpccmd crate.
This crate will hold the backend pieces of RPC interaction that
different parts of Arti get to implement.
2023-04-12 07:34:57 -04:00
Nick Mathewson 6e3f3b4dfc rpc: Add a Session object and an interaction loop. 2023-04-12 07:34:57 -04:00
Nick Mathewson 5247486cfc rpc: Add asynchronous_codec wrapper for jsonlines. 2023-04-12 07:34:57 -04:00
Nick Mathewson a662fb1296 rpc: Add a cancellable future type.
Ordinarily you can cancel a future just by dropping it, but we'll
want the ability to cancel futures that we no longer own (because we
gave them to a `FuturesUnordered`).
2023-04-12 07:34:57 -04:00
Nick Mathewson 0779d405cf rpc: Implement json message types for serde. 2023-04-12 07:34:57 -04:00