oxidecomputer / dropshot

expose REST APIs from a Rust program
Apache License 2.0
843 stars 74 forks source link

[11/n] [dropshot_endpoint] somewhat more first-class channel implementation #1037

Closed sunshowers closed 3 months ago

sunshowers commented 3 months ago

Currently, the channel implementation mostly defers to the endpoint implementation. I realized while writing the channel implementation for servers that this scheme is a bit too unwieldy to be ported properly. Turn the channel implementation into slightly more of a first-class citizen.

(This isn't fully first-class because it has an adapter function that converts a channel into being used by ApiEndpoint::new. We can definitely improve this, but this PR is already large enough so I've deferred that until later.)

In the last few PRs in the series, we've built up a toolbox of components that can be used for this, which means that the channel-specific code can be pretty lightweight. I've tried to strike a balance between DRY and excessive modularization, so there's some copy-paste but all the logically complex bits are shared.

I've tried to mirror the channel and endpoint files as closely as possible, so folks can read them side by side and follow what's going on.

This also fixes two issues along the way:

  1. Previously, channel args couldn't be named _. To fix this, generate our own argument names similar to how it's already done for endpoints.

  2. Ban channel paths with wildcards. This was originally mentioned in #1007.