Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit 1d3d703

Browse files
committed
Upgrate to latest rust-http2
1 parent d4691d0 commit 1d3d703

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1181
-432
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ jobs:
135135
run: "./ci/install-protobuf.sh"
136136
shell: bash
137137
- name: install protobuf-codegen
138-
run: cargo install protobuf-codegen --version=2.18.2
138+
run: cargo install protobuf-codegen --version=2.23
139139
shell: bash
140140
- name: gen
141141
run: grpc-compiler/test-protoc-plugin/gen.sh

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ In Cargo.toml:
6363
```ini
6464
[dependencies]
6565
grpc = "~0.8"
66-
protobuf = "~2"
66+
protobuf = "2.23"
6767
futures = "~0.3"
6868

6969
[build-dependencies]

ci-gen/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn test_protoc_plugin_job() -> Job {
7373
steps.push(install_protobuf_step());
7474
steps.push(Step::run(
7575
"install protobuf-codegen",
76-
"cargo install protobuf-codegen --version=2.18.2",
76+
"cargo install protobuf-codegen --version=2.23",
7777
));
7878
steps.push(Step::run("gen", "grpc-compiler/test-protoc-plugin/gen.sh"));
7979
steps.push(Step::run(

grpc-compiler/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ authors = ["Stepan Koltsov <[email protected]>"]
77
edition = "2018"
88

99
[dependencies]
10-
protobuf = "~2.18.2"
11-
protobuf-codegen = "~2.18.2"
10+
protobuf = "2.23"
11+
protobuf-codegen = "2.23"
1212

1313
[[bin]]
1414

grpc-compiler/src/codegen.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'a> MethodGen<'a> {
295295

296296
fn server_sig(&self) -> String {
297297
format!(
298-
"{}(&self, o: ::grpc::ServerHandlerContext, req: {}, resp: {}) -> ::grpc::Result<()>",
298+
"{}(&self, req: {}, resp: {}) -> ::grpc::Result<()>",
299299
self.snake_name(),
300300
self.server_req_type(),
301301
self.server_resp_type(),
@@ -492,7 +492,7 @@ impl<'a> ServiceGen<'a> {
492492
method.write_descriptor(w, "::grpc::rt::ArcOrStatic::Static(&", "),");
493493
w.block("{", "},", |w| {
494494
w.write_line(&format!("let handler_copy = {}.clone();", handler));
495-
w.write_line(&format!("::grpc::rt::MethodHandler{}::new(move |ctx, req, resp| (*handler_copy).{}(ctx, req, resp))",
495+
w.write_line(&format!("::grpc::rt::MethodHandler{}::new(move |req, resp| (*handler_copy).{}(req, resp))",
496496
method.streaming_upper(),
497497
method.snake_name()));
498498
});

grpc-compiler/test-protoc-plugin/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ publish = false
66
edition = "2018"
77

88
[dependencies]
9-
tls-api = "0.4.*"
10-
protobuf = "~2.18.2"
9+
tls-api = "0.5.0"
10+
protobuf = "2.23"
1111
grpc = { path = "../../grpc" }
1212
grpc-protobuf = { path = "../../grpc-protobuf" }
1313

grpc-examples/greeter/Cargo.toml

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ path = "../../grpc"
1515
path = "../../grpc-protobuf"
1616

1717
[dependencies]
18-
protobuf = "~2.18.2"
18+
protobuf = "2.23"
1919
futures = "0.3.*"
20-
tls-api = "0.4.*"
21-
tls-api-native-tls = "0.4.*"
22-
httpbis = "~0.9"
23-
#httpbis = { git = "https://github.com/stepancheg/rust-http2" }
20+
tls-api = "0.5.0"
21+
tls-api-stub = "0.5.0"
22+
tls-api-native-tls = "0.5.0"
23+
#httpbis = "~0.9"
24+
httpbis = { git = "https://github.com/stepancheg/rust-http2" }
25+
#httpbis = { path = "../../../rust-http2/httpbis" }
2426
env_logger = "~0.5"
2527

2628
[build-dependencies]

grpc-examples/greeter/src/bin/greeter_client.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use tls_api::TlsConnectorBuilder;
1313

1414
fn test_tls_connector() -> tls_api_native_tls::TlsConnector {
1515
let root_ca = include_bytes!("../root-ca.der");
16-
let root_ca = tls_api::Certificate::from_der(root_ca.to_vec());
1716

1817
let mut builder = tls_api_native_tls::TlsConnector::builder().unwrap();
1918
builder
@@ -45,8 +44,10 @@ fn main() {
4544
// This is a bit complicated, because we need to explicitly pass root CA here
4645
// because server uses self-signed certificate.
4746
// TODO: simplify it
48-
let tls_option =
49-
httpbis::ClientTlsOption::Tls("foobar.com".to_owned(), Arc::new(test_tls_connector()));
47+
let tls_option = httpbis::ClientTlsOption::Tls(
48+
"foobar.com".to_owned(),
49+
Arc::new(test_tls_connector().into_dyn()),
50+
);
5051
let grpc_client = Arc::new(
5152
grpc::ClientBuilder::new("::1", port)
5253
.explicit_tls(tls_option)

grpc-examples/greeter/src/bin/greeter_server.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ use std::thread;
44
use grpc_examples_greeter::helloworld::*;
55
use grpc_examples_greeter::helloworld_grpc::*;
66

7-
use grpc::ServerHandlerContext;
87
use grpc::ServerRequestSingle;
98
use grpc::ServerResponseUnarySink;
9+
use tls_api::TlsAcceptor;
1010
use tls_api::TlsAcceptorBuilder;
1111

1212
struct GreeterImpl;
1313

1414
impl Greeter for GreeterImpl {
1515
fn say_hello(
1616
&self,
17-
_: ServerHandlerContext,
1817
req: ServerRequestSingle<HelloRequest>,
1918
resp: ServerResponseUnarySink<HelloReply>,
2019
) -> grpc::Result<()> {
@@ -32,7 +31,7 @@ impl Greeter for GreeterImpl {
3231

3332
fn test_tls_acceptor() -> tls_api_native_tls::TlsAcceptor {
3433
let pkcs12 = include_bytes!("../foobar.com.p12");
35-
let builder = tls_api_native_tls::TlsAcceptorBuilder::from_pkcs12(pkcs12, "mypass").unwrap();
34+
let builder = tls_api_native_tls::TlsAcceptor::builder_from_pkcs12(pkcs12, "mypass").unwrap();
3635
builder.build().unwrap()
3736
}
3837

grpc-examples/route_guide/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ path = "../../grpc"
1515
path = "../../grpc-protobuf"
1616

1717
[dependencies]
18-
protobuf = "~2.18.2"
18+
protobuf = "2.23"
1919
futures = "0.3.*"
20-
tls-api = "0.4.*"
21-
tls-api-native-tls = "0.4.*"
20+
tls-api = "0.5.0"
21+
tls-api-stub = "0.5.0"
2222
env_logger = "0.4.*"
2323
rand = "0.5.5"
2424
json = "0.11.*"

grpc-examples/route_guide/src/server.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl RouteGuideImpl {
4242
impl RouteGuide for RouteGuideImpl {
4343
fn get_feature(
4444
&self,
45-
_o: ServerHandlerContext,
4645
req: ServerRequestSingle<Point>,
4746
resp: ServerResponseUnarySink<Feature>,
4847
) -> grpc::Result<()> {
@@ -60,13 +59,13 @@ impl RouteGuide for RouteGuideImpl {
6059

6160
fn list_features(
6261
&self,
63-
o: ServerHandlerContext,
6462
mut req: ServerRequestSingle<Rectangle>,
6563
mut resp: ServerResponseSink<Feature>,
6664
) -> grpc::Result<()> {
65+
let loop_handle = req.loop_handle();
6766
let req = req.take_message();
6867
let saved_features = self.saved_features.clone();
69-
o.spawn(async move {
68+
loop_handle.spawn(async move {
7069
for feature in &saved_features[..] {
7170
if in_range(feature.get_location(), &req) {
7271
resp.ready().await?;
@@ -80,17 +79,18 @@ impl RouteGuide for RouteGuideImpl {
8079

8180
fn record_route(
8281
&self,
83-
o: ServerHandlerContext,
8482
req: ServerRequest<Point>,
8583
resp: ServerResponseUnarySink<RouteSummary>,
8684
) -> grpc::Result<()> {
8785
let start_time = Instant::now();
8886

8987
let saved_features = self.saved_features.clone();
9088

89+
let loop_handle = req.loop_handle();
90+
9191
let mut stream = req.into_stream();
9292

93-
o.spawn(async move {
93+
loop_handle.spawn(async move {
9494
struct State {
9595
point_count: u32,
9696
feature_count: u32,
@@ -133,15 +133,16 @@ impl RouteGuide for RouteGuideImpl {
133133

134134
fn route_chat(
135135
&self,
136-
o: ServerHandlerContext,
137136
req: ServerRequest<RouteNote>,
138137
mut resp: ServerResponseSink<RouteNote>,
139138
) -> grpc::Result<()> {
140139
let route_notes_map = self.route_notes.clone();
141140

141+
let loop_handle = req.loop_handle();
142+
142143
let mut req = req.into_stream();
143144

144-
o.spawn(async move {
145+
loop_handle.spawn(async move {
145146
loop {
146147
// Wait until resp is writable
147148
resp.ready().await?;

grpc-protobuf/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ keywords = ["grpc"]
1111
edition = "2018"
1212

1313
[dependencies]
14-
protobuf = { version = "~2.18.2", features = ["with-bytes"] }
14+
protobuf = { version = "2.23", features = ["with-bytes"] }
1515
grpc = { path = "../grpc", version = "=0.9.0-pre" }
16-
bytes = "0.5.*"
16+
bytes = "1.0.1"
1717

1818
[lib]
1919
doctest = false

grpc/Cargo.toml

+9-6
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ edition = "2018"
1414
log = "0.4"
1515
log-ndc = "0.2.*"
1616
futures = "0.3.1"
17-
tokio = { version = "~0.2.6", features = ["net", "uds", "io-util", "time"] }
18-
httpbis = "~0.9"
19-
#httpbis = { git = "https://github.com/stepancheg/rust-http2" }
20-
tls-api = "0.4.*"
21-
tls-api-stub = "0.4.*"
22-
bytes = "0.5.*"
17+
tokio = { version = "1.2.0", features = ["io-util", "net", "time", "rt"] }
18+
tokio-util = { version = "0.6.3", features = ["io"] }
19+
#httpbis = "~0.9"
20+
httpbis = { git = "https://github.com/stepancheg/rust-http2" }
21+
#httpbis = { path = "../../rust-http2/httpbis" }
22+
tls-api = "0.5.0"
23+
tls-api-stub = "0.5.0"
24+
bytes = "1.0.1"
2325
base64 = "0.9"
2426

2527
[dev-dependencies]
2628
log-ndc-env-logger = "~0.2"
29+
rand = "0.8.3"
2730

2831
[lib]
2932
doctest = false

grpc/src/bytesx/buf_eq.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use bytes::Buf;
2+
use std::cmp;
3+
4+
/// Test if two buffers content is the same.
5+
pub fn buf_eq<B1: Buf, B2: Buf>(mut b1: B1, mut b2: B2) -> bool {
6+
loop {
7+
if !b1.has_remaining() || !b2.has_remaining() {
8+
return b1.has_remaining() == b2.has_remaining();
9+
}
10+
let s1 = b1.chunk();
11+
let s2 = b2.chunk();
12+
let min = cmp::min(s1.len(), s2.len());
13+
if &s1[..min] != &s2[..min] {
14+
return false;
15+
}
16+
b1.advance(min);
17+
b2.advance(min);
18+
}
19+
}
20+
21+
#[cfg(test)]
22+
mod test {
23+
use super::*;
24+
use bytes::buf::Chain;
25+
26+
#[test]
27+
fn test() {
28+
assert!(buf_eq(b"".as_ref(), b"".as_ref()));
29+
assert!(buf_eq(b"ab".as_ref(), b"ab".as_ref()));
30+
assert!(!buf_eq(b"a".as_ref(), b"ab".as_ref()));
31+
assert!(!buf_eq(b"abc".as_ref(), b"ab".as_ref()));
32+
33+
assert!(buf_eq(b"".as_ref().chain(b"ab".as_ref()), b"ab".as_ref()));
34+
assert!(buf_eq(b"a".as_ref().chain(b"b".as_ref()), b"ab".as_ref()));
35+
assert!(!buf_eq(b"a".as_ref().chain(b"bc".as_ref()), b"ab".as_ref()));
36+
}
37+
}

0 commit comments

Comments
 (0)