Both tutorials were missing .await on the client connect call, causing the compiler to issue errors.
Thanks for alce#6260 on the #tonic-users discord channel for providing the answer.
This makes it so you can check if the initial connection
is established. Before this we used reconnect which would
lazily attempt to connect. So if you were trying to connect
to a non existant Server you wouldn't find out until after
you attempted your first RPC. This simplifies everything
by allowing you connect before creating the RPC client.
BREAKING CHANGE: `Endpoint::channel` was removed in favor of
an async `Endpoint::connect`.
* feat(transport): Add service multiplexing/routing
This change introduces a new "router" built on top of
`transport::Server` that allows one to run multiple
gRPC services on the same socket.
```rust
Server::builder()
.add_service(greeter)
.add_service(echo)
.serve(addr)
.await?;
```
There is also a new `multiplex` example showcasing
server side service multiplexing and client side
service multiplexing.
BREAKING CHANGES: `Server::serve` is now crate private
and all services must be added via `Server::add_service`.
Codegen also returns just a `Service` now instead of a
`MakeService` pair.
Closes#29
Signed-off-by: Lucio Franco [email protected]
This removes custom content-types in favor of
just using `application/grpc`. There is some
confusion around the specification but most
grpc implementations ignore the `+` and
anything after.
This commit adds a simple API for specifying the TLS certificate a GRPC
client will present (via the same `Identity` wrapper as a server cert is
configured). It also adds an API to specify which CA certificate client
TLS certificates will be validated against for servers.
* chore: Add tags to .gitignore
When generating ctags/universal-ctags, a 'tags' file is generated. This
commit adds any generted 'tags' file to .gitignore.
* feat(build): Expose type_attribute and field_attribute
This commit exposes the `type_attribute` and `field_attribute`
configuration settings from Prost. These are useful to tweak/extend the
generated types.
For example:
```
tonic_build::configure()
.out_dir(tmp)
.format(false)
.type_attribute(".", "#[derive(Serialize, Deserialize)]")
.type_attribute(".", "#[serde(rename_all = \"camelCase\")]")
.field_attribute("in", "#[serde(rename = \"in\")]")
.compile(&["tests/protos/wellknown.proto"], &["tests/protos"])
.unwrap();
```
Would add the serde `Serialize` and `Deserialize` traits, while renaming
all the fields to camelCase, and having serde keep fields named `in`
named `in`, rather than Prost's `in_`, to every type generated by Prost.
This commit reworks TLS configuration of both servers and endpoints in
order to provide a more flexible API. We now add options to configure
the selected TLS library using the appropriate 'native' configuration
structures, as well as retaining the existing simplier interface which
is compatible with both.
The new API can also be easily extended to support simple interfaces for
configuring mTLS and a range of other options without creating sprawl
in the builders for `Server` and `Endpoint`.
* transport: no crash after bad TLS handshake
Prevents the server exiting after a bad TLS handshake / error during
accept(). Instead the connection is dropped and the server continues to
serve new clients.
Previously an error would bubble up from the TLS library (tested with
rustls) and cause hyper to exit with:
[src/main.rs:85] &e = Error(
Server,
Error(
Accept,
Custom {
kind: InvalidData,
error: CorruptMessage,
},
),
)
* transport: add tracing error for TLS handshake failure
Co-Authored-By: Lucio Franco <[email protected]>
* fix(codec): Fix buffer decode panic on full
This is a naive fix for the buffer growing beyond capacity
and producing a panic. Ideally we should do a better job
of not having to allocate for new messages by using
a link list.
* fmt
Currently, using an RSA key - or indeed any text which is not a
PEM-encoded PKCS8-format key with RusTLS panics with an index-out-of-
range exception.
This commit introduces two new types of `TlsError` which indicate
problems with loading a certificate or private key:
- `CertificateParseError`, indicating that the certificate cannot be
parsed
- `PrivateKeyParseError`, indicating that the private key cannot be
parsed.
Additionally, in the case that reading the private key as PKCS8 fails,
we now try loading it as an RSA key before failing.