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