1#[allow(unsafe_code)]
16mod generated;
17
18use std::{error::Error, time::Duration};
19
20pub use generated::*;
21use proto_gen::node_service::node_service_client::NodeServiceClient;
22use rustfs_common::globals::GLOBAL_Conn_Map;
23use tonic::{
24 Request, Status,
25 metadata::MetadataValue,
26 service::interceptor::InterceptedService,
27 transport::{Channel, Endpoint},
28};
29
30pub const DEFAULT_GRPC_SERVER_MESSAGE_LEN: usize = 100 * 1024 * 1024;
32
33pub async fn node_service_time_out_client(
34 addr: &String,
35) -> Result<
36 NodeServiceClient<
37 InterceptedService<Channel, Box<dyn Fn(Request<()>) -> Result<Request<()>, Status> + Send + Sync + 'static>>,
38 >,
39 Box<dyn Error>,
40> {
41 let token: MetadataValue<_> = "rustfs rpc".parse()?;
42 let channel = match GLOBAL_Conn_Map.read().await.get(addr) {
43 Some(channel) => channel.clone(),
44 None => {
45 let connector = Endpoint::from_shared(addr.to_string())?.connect_timeout(Duration::from_secs(60));
46 connector.connect().await?
47 }
48 };
49 GLOBAL_Conn_Map.write().await.insert(addr.to_string(), channel.clone());
50
51 Ok(NodeServiceClient::with_interceptor(
53 channel,
54 Box::new(move |mut req: Request<()>| {
55 req.metadata_mut().insert("authorization", token.clone());
56 Ok(req)
57 }),
58 ))
59}