(server: &str, token: &str)
| 317 | static EDGE_TUNNEL_ADDRS: OnceLock<Mutex<HashMap<(String, String), SocketAddr>>> = OnceLock::new(); |
| 318 | |
| 319 | async fn edge_tunnel_addr(server: &str, token: &str) -> Result<SocketAddr> { |
| 320 | let key = (server.to_string(), token.to_string()); |
| 321 | let registry = EDGE_TUNNEL_ADDRS.get_or_init(|| Mutex::new(HashMap::new())); |
| 322 | |
| 323 | { |
| 324 | let addrs = registry.lock().await; |
| 325 | if let Some(addr) = addrs.get(&key).copied() { |
| 326 | return Ok(addr); |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | let proxy = crate::edge_tunnel::start_tunnel_proxy(server, token).await?; |
| 331 | debug!( |
| 332 | local_addr = %proxy.local_addr, |
| 333 | server, |
| 334 | "edge tunnel proxy started, routing gRPC through local proxy" |
| 335 | ); |
| 336 | |
| 337 | let mut addrs = registry.lock().await; |
| 338 | Ok(*addrs.entry(key).or_insert(proxy.local_addr)) |
| 339 | } |
| 340 | |
| 341 | pub async fn build_channel(server: &str, tls: &TlsOptions) -> Result<Channel> { |
| 342 | if server.starts_with("http://") { |
no test coverage detected