Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump tonic version to v0.9 #151

Merged
merged 6 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## tonic, etcd [0.3.0] - 2023-07-20

### Changed

- tonic: Update `tonic` and `tonic-build` to v0.9.2.
- etcd: Update `etcd-client` to v0.11.1.

## [0.2.25] - 2023-07-03

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ If your project depends on the following crates, replace them by our simulators:
```toml
[dependencies]
tokio = { version = "0.2", package = "madsim-tokio" }
tonic = { version = "0.2", package = "madsim-tonic" }
etcd-client = { version = "0.2", package = "madsim-etcd-client" }
tonic = { version = "0.3", package = "madsim-tonic" }
etcd-client = { version = "0.3", package = "madsim-etcd-client" }
rdkafka = { version = "0.2", package = "madsim-rdkafka" }
aws-sdk-s3 = { version = "0.2", package = "madsim-aws-sdk-s3" }

[dev-dependencies]
tonic-build = { version = "0.2", package = "madsim-tonic-build" }
tonic-build = { version = "0.3", package = "madsim-tonic-build" }
```

If your dependency graph includes the following crates, replace them by our patched version:
Expand Down
6 changes: 3 additions & 3 deletions madsim-etcd-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim-etcd-client"
version = "0.2.23"
version = "0.3.0+0.11.1"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "The etcd simulator on madsim."
Expand All @@ -13,7 +13,7 @@ license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[target.'cfg(not(madsim))'.dependencies]
etcd-client = "0.10"
etcd-client = "0.11"

[target.'cfg(madsim)'.dependencies]
http = "0.2"
Expand All @@ -24,7 +24,7 @@ serde_with = "2"
spin = "0.9"
thiserror = "1"
toml = "0.7"
tonic = { version = "0.8", default-features = false }
tonic = { version = "0.9", default-features = false }
tokio = { version = "1", features = ["sync"] }
tracing = "0.1"

Expand Down
2 changes: 1 addition & 1 deletion madsim-etcd-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ Replace all `etcd-client` entries in your Cargo.toml:

```toml
[dependencies]
etcd-client = { version = "0.2", package = "madsim-etcd-client" }
etcd-client = { version = "0.3", package = "madsim-etcd-client" }
```
4 changes: 2 additions & 2 deletions madsim-tonic-build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim-tonic-build"
version = "0.2.11"
version = "0.3.0+0.9.2"
edition = "2021"
authors = ["Lucio Franco <[email protected]>", "Runji Wang <[email protected]>"]
description = "Codegen module of `madsim-tonic` simulation implementation."
Expand All @@ -18,7 +18,7 @@ proc-macro2 = "1"
prost-build = { version = "0.11", optional = true }
quote = "1"
syn = "1"
tonic-build = "0.8"
tonic-build = "0.9.2"

[features]
compression = []
Expand Down
6 changes: 3 additions & 3 deletions madsim-tonic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "madsim-tonic"
version = "0.2.25"
version = "0.3.0+0.9.2"
edition = "2021"
authors = ["Runji Wang <[email protected]>"]
description = "The `tonic` simulator on madsim."
Expand All @@ -16,12 +16,12 @@ license = "Apache-2.0"
tls = ["tonic/tls"]

[target.'cfg(not(madsim))'.dependencies]
tonic = "0.8.3"
tonic = "0.9.2"

[target.'cfg(madsim)'.dependencies]
async-stream = "0.3"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
futures-util = "0.3"
madsim = { version = "0.2.20", path = "../madsim" }
tracing = "0.1"
tonic = { version = "0.8.3", default-features = false, features = ["codegen", "transport"] }
tonic = { version = "0.9.2", default-features = false, features = ["codegen", "transport"] }
4 changes: 2 additions & 2 deletions madsim-tonic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Replace all `tonic` and `tonic-build` entries in your Cargo.toml:

```toml
[dependencies]
tonic = { version = "0.2", package = "madsim-tonic" }
tonic = { version = "0.3", package = "madsim-tonic" }

[dev-dependencies]
tonic-build = { version = "0.2", package = "madsim-tonic-build" }
tonic-build = { version = "0.3", package = "madsim-tonic-build" }
```
31 changes: 4 additions & 27 deletions madsim-tonic/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ pub mod codegen {
use std::any::Any;
pub use std::net::SocketAddr;
use std::time::Duration;
use tonic::{
metadata::MetadataMap, service::Interceptor, Extensions, Request, Response, Status,
};
use tonic::{service::Interceptor, Request, Status};

pub use futures_util as futures;
pub use tonic::codegen::*;
Expand All @@ -62,7 +60,7 @@ pub mod codegen {

pub trait RequestExt<T>: Sized {
fn timeout(&self) -> Option<Duration>;
fn set_remote_addr(&mut self, addr: SocketAddr);
fn set_tcp_connect_info(&mut self, local_addr: SocketAddr, remote_addr: SocketAddr);
fn intercept<F: Interceptor>(self, interceptor: &mut F) -> Result<Self, Status>;
fn boxed(self) -> Request<BoxMessage>
where
Expand All @@ -87,9 +85,9 @@ pub mod codegen {
}

/// Set the remote address of Request.
fn set_remote_addr(&mut self, addr: SocketAddr) {
fn set_tcp_connect_info(&mut self, local_addr: SocketAddr, remote_addr: SocketAddr) {
let tcp_info: tonic::transport::server::TcpConnectInfo =
unsafe { std::mem::transmute(Some(addr)) };
unsafe { std::mem::transmute((Some(local_addr), Some(remote_addr))) };
self.extensions_mut().insert(tcp_info);
}

Expand All @@ -109,25 +107,4 @@ pub mod codegen {
self.map(|inner| Box::new(inner) as BoxMessage)
}
}

pub trait ResponseExt<T>: Sized {
fn into_parts(self) -> (MetadataMap, Extensions, T);
fn from_parts(metadata: MetadataMap, extensions: Extensions, inner: T) -> Self;
}

impl<T> ResponseExt<T> for Response<T> {
fn into_parts(mut self) -> (MetadataMap, Extensions, T) {
let metadata = std::mem::take(self.metadata_mut());
let extensions = std::mem::take(self.extensions_mut());
let inner = self.into_inner();
(metadata, extensions, inner)
}

fn from_parts(metadata: MetadataMap, extensions: Extensions, inner: T) -> Self {
let mut rsp = Response::new(inner);
*rsp.metadata_mut() = metadata;
*rsp.extensions_mut() = extensions;
rsp
}
}
}
13 changes: 7 additions & 6 deletions madsim-tonic/src/transport/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Server implementation and builder.

use super::{Error, NamedService};
use crate::codegen::{BoxMessage, BoxMessageStream, RequestExt, ResponseExt};
use crate::codegen::{BoxMessage, BoxMessageStream, RequestExt};
use crate::sim::AppendMetadata;
use crate::tower::layer::util::{Identity, Stack};
use crate::{Request, Response, Status};
Expand Down Expand Up @@ -206,6 +206,7 @@ impl<L> Router<L> {
signal: impl Future<Output = ()>,
) -> Result<(), Error> {
let ep = Endpoint::bind(addr).await.map_err(Error::from_source)?;
let local_addr = ep.local_addr().unwrap();
let mut signal = Box::pin(signal).fuse();
loop {
// receive a request
Expand All @@ -223,7 +224,7 @@ impl<L> Router<L> {
let span = debug_span!("request", ?addr, ?path);
debug!(parent: &span, "received");

request.set_remote_addr(addr);
request.set_tcp_connect_info(local_addr, addr);
let request: Request<BoxMessageStream> = request.map(move |msg| {
if msg.downcast_ref::<()>().is_none() {
// single request
Expand Down Expand Up @@ -264,8 +265,8 @@ impl<L> Router<L> {
if server_streaming {
let (header, stream) = match result {
Ok(response) => {
let (metadata, extensions, stream) = response.into_parts();
let header = Response::from_parts(metadata, extensions, ());
let (metadata, stream, extensions) = response.into_parts();
let header = Response::from_parts(metadata, (), extensions);
(Ok(header), Some(stream))
}
Err(e) => (Err(e), None),
Expand Down Expand Up @@ -296,15 +297,15 @@ impl<L> Router<L> {
} else {
let rsp: Result<Response<BoxMessage>, Status> = match result {
Ok(response) => {
let (metadata, extensions, mut stream) = response.into_parts();
let (metadata, mut stream, extensions) = response.into_parts();
let inner: BoxMessage = select_biased! {
_ = tx.closed().fuse() => {
debug!(parent: &span, "client closed");
return Ok(());
}
msg = stream.next().fuse() => msg.unwrap().unwrap(),
};
Ok(Response::from_parts(metadata, extensions, inner))
Ok(Response::from_parts(metadata, inner, extensions))
}
Err(e) => Err(e),
};
Expand Down