()
| 48 | |
| 49 | #[tokio::main] |
| 50 | async fn main() -> Result<(), anyhow::Error> { |
| 51 | unsafe { |
| 52 | // SAFETY: |
| 53 | // `std::env::set_var` is unsafe in Rust 2024 because environment variables |
| 54 | // are process-global and unsynchronized. Concurrent reads/writes from |
| 55 | // multiple threads can cause undefined behavior. |
| 56 | // |
| 57 | // This call happens at process startup, before any threads are spawned and |
| 58 | // before any code that may read environment variables is executed. |
| 59 | // Therefore, no concurrent access is possible. |
| 60 | std::env::set_var( |
| 61 | "CLN_PLUGIN_LOG", |
| 62 | "cln_plugin=info,cln_rpc=info,clnrest=debug,warn", |
| 63 | ) |
| 64 | }; |
| 65 | |
| 66 | log_panics::init(); |
| 67 | |
| 68 | let _ = rustls::crypto::ring::default_provider().install_default(); |
| 69 | |
| 70 | let plugin = match Builder::new(tokio::io::stdin(), tokio::io::stdout()) |
| 71 | .option(OPT_CLNREST_PORT) |
| 72 | .option(OPT_CLNREST_CERTS) |
| 73 | .option(OPT_CLNREST_PROTOCOL) |
| 74 | .option(OPT_CLNREST_HOST) |
| 75 | .option(OPT_CLNREST_CORS) |
| 76 | .option(OPT_CLNREST_CSP) |
| 77 | .option(OPT_CLNREST_SWAGGER) |
| 78 | .rpcmethod_from_builder( |
| 79 | RpcMethodBuilder::new("clnrest-register-path", register_path) |
| 80 | .description("Register a dynamic REST path for clnrest") |
| 81 | .usage("path rpc_method [http_method] [rune_required] [rune_restrictions]"), |
| 82 | ) |
| 83 | .subscribe("*", handle_notification) |
| 84 | .dynamic() |
| 85 | .configure() |
| 86 | .await? |
| 87 | { |
| 88 | Some(p) => p, |
| 89 | None => return Ok(()), |
| 90 | }; |
| 91 | |
| 92 | let clnrest_options = match parse_options(&plugin) { |
| 93 | Ok(opts) => opts, |
| 94 | Err(e) => return plugin.disable(&e.to_string()).await, |
| 95 | }; |
| 96 | |
| 97 | let (notify_tx, notify_rx) = mpsc::channel(100); |
| 98 | |
| 99 | let state = PluginState { |
| 100 | notification_sender: notify_tx, |
| 101 | dyn_router: Arc::new(Mutex::new(matchit::Router::new())), |
| 102 | }; |
| 103 | |
| 104 | let plugin = plugin.start(state.clone()).await?; |
| 105 | |
| 106 | tokio::select! { |
| 107 | _ = plugin.join() => { |
nothing calls this directly
no test coverage detected