()
| 16 | |
| 17 | #[tokio::main] |
| 18 | async fn main() -> Result<(), anyhow::Error> { |
| 19 | unsafe { |
| 20 | // SAFETY: |
| 21 | // `std::env::set_var` is unsafe in Rust 2024 because environment variables |
| 22 | // are process-global and unsynchronized. Concurrent reads/writes from |
| 23 | // multiple threads can cause undefined behavior. |
| 24 | // |
| 25 | // This call happens at process startup, before any threads are spawned and |
| 26 | // before any code that may read environment variables is executed. |
| 27 | // Therefore, no concurrent access is possible. |
| 28 | std::env::set_var( |
| 29 | "CLN_PLUGIN_LOG", |
| 30 | "cln_plugin=info,cln_rpc=info,wss_proxy=debug,warn", |
| 31 | ) |
| 32 | }; |
| 33 | |
| 34 | log_panics::init(); |
| 35 | |
| 36 | let opt_wss_proxy_bind_addr = ConfigOption::new_str_arr_no_default( |
| 37 | OPT_WSS_BIND_ADDR, |
| 38 | "WSS proxy address to connect with WS", |
| 39 | ); |
| 40 | |
| 41 | let default_certs_dir = std::env::current_dir()?; |
| 42 | let default_certs_dir_str = default_certs_dir |
| 43 | .to_str() |
| 44 | .ok_or_else(|| anyhow!("Invalid working directory: {:?}", default_certs_dir))?; |
| 45 | |
| 46 | let opt_wss_proxy_certs = ConfigOption::new_str_with_default( |
| 47 | OPT_WSS_CERTS_DIR, |
| 48 | default_certs_dir_str, |
| 49 | "Certificate location for WSS proxy", |
| 50 | ); |
| 51 | |
| 52 | let conf_plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout()) |
| 53 | .option(opt_wss_proxy_bind_addr) |
| 54 | .option(opt_wss_proxy_certs) |
| 55 | .dynamic() |
| 56 | .configure() |
| 57 | .await? |
| 58 | { |
| 59 | Some(p) => p, |
| 60 | None => return Ok(()), |
| 61 | }; |
| 62 | |
| 63 | let wss_proxy_options = match parse_options(&conf_plugin).await { |
| 64 | Ok(opts) => opts, |
| 65 | Err(e) => return conf_plugin.disable(&e.to_string()).await, |
| 66 | }; |
| 67 | |
| 68 | let plugin = conf_plugin.start(()).await?; |
| 69 | |
| 70 | let tls_config = match get_tls_config(&wss_proxy_options).await { |
| 71 | Ok(tls) => tls, |
| 72 | Err(err) => { |
| 73 | log_error(err.to_string()); |
| 74 | process::exit(1) |
| 75 | } |
nothing calls this directly
no test coverage detected