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
33 let mut Channel = tonic::transport::Channel::from_shared(EndpointURL)
34 .map_err(|E| VineError::RPCError(format!("Failed to create channel: {}", E)))?;
35
36 if UseTuned {
37 Channel = Channel
38 .tcp_nodelay(true)
39 .http2_keep_alive_interval(Duration::from_secs(10))
40 .keep_alive_timeout(Duration::from_secs(20))
41 .http2_adaptive_window(true)
42 .initial_stream_window_size(4 * 1024 * 1024)
43 .initial_connection_window_size(16 * 1024 * 1024)
44 .concurrency_limit(1024)
45 .buffer_size(256 * 1024)
46 .timeout(Duration::from_secs(30))
47 .connect_timeout(Duration::from_secs(5));
48 }
49
50 let Connected = Channel
51 .connect()
52 .await
53 .map_err(|E| VineError::RPCError(format!("Failed to connect: {}", E)))?;
54
55 let Client = CocoonClient::new(Connected);
56
57 {
58 let mut Pool = SIDECAR_CLIENTS.lock();
59
60 Pool.insert(SideCarIdentifier.to_string(), Client.clone());
61 }
62
63 if std::env::var("LAND_VINE_STREAMING").as_deref() == Ok("1") {
64 let SideCarForMux = SideCarIdentifier.to_string();
65
66 match crate::Vine::Multiplexer::Multiplexer::Open(SideCarForMux, Client).await {
67 Ok(_) => {
68 dev_log!(
69 "grpc",
70 "[VineClient] streaming multiplexer opened for sidecar '{}'",
71 SideCarIdentifier
72 );
73 },
74
75 Err(Error) => {
76 dev_log!(
77 "grpc",
78 "warn: [VineClient] streaming multiplexer open failed for '{}' ({}); falling back to unary",
79 SideCarIdentifier,
80 Error
81 );
82 },
83 }
84 }
85
86 Ok(())
87}