Mountain/Vine/Client/
TryConnectSingle.rs1
2use std::time::Duration;
14
15use crate::{
16 Vine::{
17 Client::Shared::{CocoonClient, SIDECAR_CLIENTS},
18 Error::VineError,
19 },
20 dev_log,
21};
22
23pub async fn Fn(SideCarIdentifier:&str, Endpoint:&str) -> Result<(), VineError> {
24 let EndpointURL = if Endpoint.starts_with("http://") || Endpoint.starts_with("https://") {
25 Endpoint.to_string()
26 } else {
27 format!("http://{}", Endpoint)
28 };
29
30 let UseTuned = std::env::var("LAND_TONIC_TUNED").as_deref() != Ok("0");
31
32 let mut Channel = tonic::transport::Channel::from_shared(EndpointURL)
33 .map_err(|E| VineError::RPCError(format!("Failed to create channel: {}", E)))?;
34
35 if UseTuned {
36 Channel = Channel
37 .tcp_nodelay(true)
38 .http2_keep_alive_interval(Duration::from_secs(10))
39 .keep_alive_timeout(Duration::from_secs(20))
40 .http2_adaptive_window(true)
41 .initial_stream_window_size(4 * 1024 * 1024)
42 .initial_connection_window_size(16 * 1024 * 1024)
43 .concurrency_limit(1024)
44 .buffer_size(256 * 1024)
45 .timeout(Duration::from_secs(30))
46 .connect_timeout(Duration::from_secs(5));
47 }
48
49 let Connected = Channel
50 .connect()
51 .await
52 .map_err(|E| VineError::RPCError(format!("Failed to connect: {}", E)))?;
53
54 let Client = CocoonClient::new(Connected);
55
56 {
57 let mut Pool = SIDECAR_CLIENTS.lock();
58
59 Pool.insert(SideCarIdentifier.to_string(), Client.clone());
60 }
61
62 if std::env::var("LAND_VINE_STREAMING").as_deref() == Ok("1") {
63 let SideCarForMux = SideCarIdentifier.to_string();
64
65 match crate::Vine::Multiplexer::Multiplexer::Open(SideCarForMux, Client).await {
66 Ok(_) => {
67 dev_log!(
68 "grpc",
69 "[VineClient] streaming multiplexer opened for sidecar '{}'",
70 SideCarIdentifier
71 );
72 },
73
74 Err(Error) => {
75 dev_log!(
76 "grpc",
77 "warn: [VineClient] streaming multiplexer open failed for '{}' ({}); falling back to unary",
78 SideCarIdentifier,
79 Error
80 );
81 },
82 }
83 }
84
85 Ok(())
86}