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