Skip to content
Permalink
Browse files

Introduce support for the origin in grpc client.

When enstabilishing grpc connection we should pass origin
URL to the connection, otherwise it can't be established.
For this reason we introduce an additional field that allows
us to pass the origin contructed elsewhere.
This method allows to keep the connection abstract but still
allows to keep fully static structures without additional
allocations or boxes, that must be a case if AddOrigin struct
is used.
  • Loading branch information...
qnikst committed Mar 12, 2019
1 parent 2072528 commit e0f716b925676c0916d89de4ab722077e868d923
Showing with 13 additions and 2 deletions.
  1. +2 −0 network-grpc/Cargo.toml
  2. +11 −2 network-grpc/src/client.rs
@@ -15,12 +15,14 @@ chain-core = { path = "../chain-core" }
network-core = { path = "../network-core" }
bytes = "0.4"
futures = "0.1"
http = "0.1.16"
h2 = "0.1.11"
prost = "0.4"
prost-derive = "0.4"
tokio = "0.1"
tower-h2 = { git = "https://github.com/tower-rs/tower-h2" }
tower-util = { git = "https://github.com/tower-rs/tower" }
tower-add-origin = { git = "https://github.com/tower-rs/tower-http" }

[dependencies.tower-grpc]
git = "https://github.com/tower-rs/tower-grpc"
@@ -9,6 +9,7 @@ use network_core::{
use futures::future::Executor;
use tokio::io;
use tokio::prelude::*;
use tower_add_origin::{self, AddOrigin};
use tower_grpc::{codegen::server::tower::Service, BoxBody, Code, Request, Status, Streaming};
use tower_h2::client::{Background, Connect, ConnectError, Connection};
use tower_util::MakeService;
@@ -83,7 +84,7 @@ pub struct Client<C, S, E>
where
C: ProtocolConfig,
{
node: gen_client::Node<Connection<S, E, BoxBody>>,
node: gen_client::Node<AddOrigin<Connection<S, E, BoxBody>>>,
_phantom: PhantomData<(C::Block, C::Gossip)>,
}

@@ -93,7 +94,11 @@ where
S: AsyncRead + AsyncWrite,
E: Executor<Background<S, BoxBody>> + Clone,
{
pub fn connect<P>(peer: P, executor: E) -> impl Future<Item = Self, Error = Error>
pub fn connect<P>(
peer: P,
executor: E,
uri: http::Uri,
) -> impl Future<Item = Self, Error = Error>
where
P: Service<(), Response = S, Error = io::Error> + 'static,
{
@@ -103,6 +108,10 @@ where
.map_err(|e| Error::Connect(e))
.map(|conn| {
// TODO: add origin URL with add_origin middleware from tower-http
let conn = tower_add_origin::Builder::new()
.uri(uri)
.build(conn)
.unwrap();

Client {
node: gen_client::Node::new(conn),

0 comments on commit e0f716b

Please sign in to comment.
You can’t perform that action at this time.