(
plugin: &ConfiguredPlugin<(), tokio::io::Stdin, tokio::io::Stdout>,
)
| 19 | } |
| 20 | |
| 21 | pub async fn parse_options( |
| 22 | plugin: &ConfiguredPlugin<(), tokio::io::Stdin, tokio::io::Stdout>, |
| 23 | ) -> Result<WssproxyOptions, anyhow::Error> { |
| 24 | let wss_address_val = plugin |
| 25 | .option_str(OPT_WSS_BIND_ADDR)? |
| 26 | .ok_or_else(|| anyhow!("`{}` option is not configured", OPT_WSS_BIND_ADDR))?; |
| 27 | let wss_address_str = wss_address_val |
| 28 | .as_str_arr() |
| 29 | .ok_or_else(|| anyhow!("{} is not a string array!", OPT_WSS_BIND_ADDR))?; |
| 30 | |
| 31 | let mut wss_domains = Vec::new(); |
| 32 | let mut wss_addresses = Vec::new(); |
| 33 | for addr in wss_address_str.iter() { |
| 34 | wss_domains.push( |
| 35 | addr.rsplit_once(':') |
| 36 | .ok_or_else(|| anyhow!("WSS host missing port. Current Value: {}.", addr))? |
| 37 | .0 |
| 38 | .to_owned(), |
| 39 | ); |
| 40 | wss_addresses.extend(addr.to_socket_addrs().map_err(|_| { |
| 41 | anyhow!( |
| 42 | "WSS host should be a valid IP or resolvable domain. Current Value: {}.", |
| 43 | addr |
| 44 | ) |
| 45 | })?); |
| 46 | } |
| 47 | |
| 48 | if wss_addresses.is_empty() { |
| 49 | return Err(anyhow!( |
| 50 | "WSS host is missing a valid IP or resolvable domain." |
| 51 | )); |
| 52 | } |
| 53 | |
| 54 | for socket_addr in wss_addresses.iter() { |
| 55 | if !validate_port(socket_addr.port()) { |
| 56 | return Err(anyhow!( |
| 57 | "WSS port should be a valid available port between 1024 and 65535. \ |
| 58 | Current Value: {}.", |
| 59 | socket_addr.port() |
| 60 | )); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | let certs_dir_val = plugin |
| 65 | .option_str(OPT_WSS_CERTS_DIR)? |
| 66 | .ok_or_else(|| anyhow!("{} is not set!", OPT_WSS_CERTS_DIR))?; |
| 67 | let certs_dir_str = certs_dir_val |
| 68 | .as_str() |
| 69 | .ok_or_else(|| anyhow!("{} is not a string!", OPT_WSS_CERTS_DIR))?; |
| 70 | |
| 71 | let certs_dir = PathBuf::from(certs_dir_str); |
| 72 | |
| 73 | let mut rpc = ClnRpc::new( |
| 74 | Path::new(&plugin.configuration().lightning_dir).join(plugin.configuration().rpc_file), |
| 75 | ) |
| 76 | .await?; |
| 77 | |
| 78 | let ws_addr_config = rpc |
no test coverage detected