Parse an address string into an Ingress. Supports both IP:port (e.g., "127.0.0.1:18551") and domain:port (e.g., "node.example.com:18551")
(address: &str)
| 24 | /// Parse an address string into an Ingress. |
| 25 | /// Supports both IP:port (e.g., "127.0.0.1:18551") and domain:port (e.g., "node.example.com:18551") |
| 26 | fn parse_ingress(address: &str) -> Result<Ingress, Box<dyn std::error::Error>> { |
| 27 | // Try to parse as a socket address first (IP:port) |
| 28 | if let Ok(socket_addr) = address.parse::<SocketAddr>() { |
| 29 | return Ok(Ingress::from(socket_addr)); |
| 30 | } |
| 31 | |
| 32 | // Otherwise, try to parse as hostname:port |
| 33 | let (host, port_str) = address |
| 34 | .rsplit_once(':') |
| 35 | .ok_or_else(|| format!("Invalid address format (expected host:port): {address}"))?; |
| 36 | |
| 37 | let port: u16 = port_str |
| 38 | .parse() |
| 39 | .map_err(|_| format!("Invalid port number: {port_str}"))?; |
| 40 | |
| 41 | let hostname = Hostname::new(host).map_err(|e| format!("Invalid hostname '{host}': {e}"))?; |
| 42 | |
| 43 | Ok(Ingress::Dns { |
| 44 | host: hostname, |
| 45 | port, |
| 46 | }) |
| 47 | } |
| 48 | |
| 49 | impl Bootstrappers { |
| 50 | /// Load bootstrappers from a TOML file |
no outgoing calls