@@ -8,7 +8,7 @@ use crate::{request_settings::AppliedRequestSettings, RequestSettings};
88use dapi_grpc:: core:: v0:: core_client:: CoreClient ;
99use dapi_grpc:: core:: v0:: { self as core_proto} ;
1010use dapi_grpc:: platform:: v0:: { self as platform_proto, platform_client:: PlatformClient } ;
11- use dapi_grpc:: tonic:: transport:: Uri ;
11+ use dapi_grpc:: tonic:: transport:: { ClientTlsConfig , Uri } ;
1212use dapi_grpc:: tonic:: Streaming ;
1313use dapi_grpc:: tonic:: { transport:: Channel , IntoRequest } ;
1414use futures:: { future:: BoxFuture , FutureExt , TryFutureExt } ;
@@ -18,59 +18,101 @@ pub type PlatformGrpcClient = PlatformClient<Channel>;
1818/// Core Client using gRPC transport.
1919pub type CoreGrpcClient = CoreClient < Channel > ;
2020
21- fn create_channel ( uri : Uri , settings : Option < & AppliedRequestSettings > ) -> Channel {
22- let mut builder = Channel :: builder ( uri) ;
21+ fn create_channel (
22+ uri : Uri ,
23+ settings : Option < & AppliedRequestSettings > ,
24+ ) -> Result < Channel , dapi_grpc:: tonic:: transport:: Error > {
25+ let mut builder = Channel :: builder ( uri) . tls_config (
26+ ClientTlsConfig :: new ( )
27+ . with_native_roots ( )
28+ . with_webpki_roots ( )
29+ . assume_http2 ( true ) ,
30+ ) ?;
2331
2432 if let Some ( settings) = settings {
2533 if let Some ( timeout) = settings. connect_timeout {
2634 builder = builder. connect_timeout ( timeout) ;
2735 }
2836 }
2937
30- builder. connect_lazy ( )
38+ Ok ( builder. connect_lazy ( ) )
3139}
3240
3341impl TransportClient for PlatformGrpcClient {
3442 type Error = dapi_grpc:: tonic:: Status ;
3543
36- fn with_uri ( uri : Uri , pool : & ConnectionPool ) -> Self {
37- pool. get_or_create ( PoolPrefix :: Platform , & uri, None , || {
38- Self :: new ( create_channel ( uri. clone ( ) , None ) ) . into ( )
39- } )
40- . into ( )
44+ fn with_uri ( uri : Uri , pool : & ConnectionPool ) -> Result < Self , Self :: Error > {
45+ Ok ( pool
46+ . get_or_create ( PoolPrefix :: Platform , & uri, None , || {
47+ match create_channel ( uri. clone ( ) , None ) {
48+ Ok ( channel) => Ok ( Self :: new ( channel) . into ( ) ) ,
49+ Err ( e) => Err ( dapi_grpc:: tonic:: Status :: failed_precondition ( format ! (
50+ "Channel creation failed: {}" ,
51+ e
52+ ) ) ) ,
53+ }
54+ } ) ?
55+ . into ( ) )
4156 }
4257
4358 fn with_uri_and_settings (
4459 uri : Uri ,
4560 settings : & AppliedRequestSettings ,
4661 pool : & ConnectionPool ,
47- ) -> Self {
48- pool. get_or_create ( PoolPrefix :: Platform , & uri, Some ( settings) , || {
49- Self :: new ( create_channel ( uri. clone ( ) , Some ( settings) ) ) . into ( )
50- } )
51- . into ( )
62+ ) -> Result < Self , Self :: Error > {
63+ Ok ( pool
64+ . get_or_create (
65+ PoolPrefix :: Platform ,
66+ & uri,
67+ Some ( settings) ,
68+ || match create_channel ( uri. clone ( ) , Some ( settings) ) {
69+ Ok ( channel) => Ok ( Self :: new ( channel) . into ( ) ) ,
70+ Err ( e) => Err ( dapi_grpc:: tonic:: Status :: failed_precondition ( format ! (
71+ "Channel creation failed: {}" ,
72+ e
73+ ) ) ) ,
74+ } ,
75+ ) ?
76+ . into ( ) )
5277 }
5378}
5479
5580impl TransportClient for CoreGrpcClient {
5681 type Error = dapi_grpc:: tonic:: Status ;
5782
58- fn with_uri ( uri : Uri , pool : & ConnectionPool ) -> Self {
59- pool. get_or_create ( PoolPrefix :: Core , & uri, None , || {
60- Self :: new ( create_channel ( uri. clone ( ) , None ) ) . into ( )
61- } )
62- . into ( )
83+ fn with_uri ( uri : Uri , pool : & ConnectionPool ) -> Result < Self , Self :: Error > {
84+ Ok ( pool
85+ . get_or_create ( PoolPrefix :: Core , & uri, None , || {
86+ match create_channel ( uri. clone ( ) , None ) {
87+ Ok ( channel) => Ok ( Self :: new ( channel) . into ( ) ) ,
88+ Err ( e) => Err ( dapi_grpc:: tonic:: Status :: failed_precondition ( format ! (
89+ "Channel creation failed: {}" ,
90+ e
91+ ) ) ) ,
92+ }
93+ } ) ?
94+ . into ( ) )
6395 }
6496
6597 fn with_uri_and_settings (
6698 uri : Uri ,
6799 settings : & AppliedRequestSettings ,
68100 pool : & ConnectionPool ,
69- ) -> Self {
70- pool. get_or_create ( PoolPrefix :: Core , & uri, Some ( settings) , || {
71- Self :: new ( create_channel ( uri. clone ( ) , Some ( settings) ) ) . into ( )
72- } )
73- . into ( )
101+ ) -> Result < Self , Self :: Error > {
102+ Ok ( pool
103+ . get_or_create (
104+ PoolPrefix :: Core ,
105+ & uri,
106+ Some ( settings) ,
107+ || match create_channel ( uri. clone ( ) , Some ( settings) ) {
108+ Ok ( channel) => Ok ( Self :: new ( channel) . into ( ) ) ,
109+ Err ( e) => Err ( dapi_grpc:: tonic:: Status :: failed_precondition ( format ! (
110+ "Channel creation failed: {}" ,
111+ e
112+ ) ) ) ,
113+ } ,
114+ ) ?
115+ . into ( ) )
74116 }
75117}
76118
0 commit comments