Skip to content
Permalink
Browse files

Merge pull request #517 from input-output-hk/grpc-origin

Introduce support for the origin in grpc client.
  • Loading branch information...
qnikst committed Mar 12, 2019
2 parents 2072528 + e0f716b commit 43d7197a1652c79d45099228e897d6c82da812c9
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 43d7197

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