mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-19 21:04:41 +00:00
Support IPv6 in BN and VC HTTP APIs (#3104)
## Issue Addressed #3103 ## Proposed Changes Parse `http-address` and `metrics-address` as `IpAddr` for both the beacon node and validator client to support IPv6 addresses. Also adjusts parsing of CORS origins to allow for IPv6 addresses. ## Usage You can now set `http-address` and/or `metrics-address` flags to IPv6 addresses. For example, the following: `lighthouse bn --http --http-address :: --metrics --metrics-address ::1` will expose the beacon node HTTP server on `[::]` (equivalent of `0.0.0.0` in IPv4) and the metrics HTTP server on `localhost` (the equivalent of `127.0.0.1` in IPv4) The beacon node API can then be accessed by: `curl "http://[server-ipv6-address]:5052/eth/v1/some_endpoint"` And the metrics server api can be accessed by: `curl "http://localhost:5054/metrics"` or by `curl "http://[::1]:5054/metrics"` ## Additional Info On most Linux distributions the `v6only` flag is set to `false` by default (see the section for the `IPV6_V6ONLY` flag in https://www.man7.org/linux/man-pages/man7/ipv6.7.html) which means IPv4 connections will continue to function on a IPv6 address (providing it is appropriately mapped). This means that even if the Lighthouse API is running on `::` it is also possible to accept IPv4 connections. However on Windows, this is not the case. The `v6only` flag is set to `true` so binding to `::` will only allow IPv6 connections.
This commit is contained in:
@@ -4,7 +4,7 @@ use crate::exec::CommandLineTestExec;
|
||||
use bls::{Keypair, PublicKeyBytes};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::IpAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::str::FromStr;
|
||||
@@ -320,7 +320,7 @@ fn http_flag() {
|
||||
}
|
||||
#[test]
|
||||
fn http_address_flag() {
|
||||
let addr = "127.0.0.99".parse::<Ipv4Addr>().unwrap();
|
||||
let addr = "127.0.0.99".parse::<IpAddr>().unwrap();
|
||||
CommandLineTest::new()
|
||||
.flag("http-address", Some("127.0.0.99"))
|
||||
.flag("unencrypted-http-transport", None)
|
||||
@@ -328,9 +328,18 @@ fn http_address_flag() {
|
||||
.with_config(|config| assert_eq!(config.http_api.listen_addr, addr));
|
||||
}
|
||||
#[test]
|
||||
fn http_address_ipv6_flag() {
|
||||
let addr = "::1".parse::<IpAddr>().unwrap();
|
||||
CommandLineTest::new()
|
||||
.flag("http-address", Some("::1"))
|
||||
.flag("unencrypted-http-transport", None)
|
||||
.run()
|
||||
.with_config(|config| assert_eq!(config.http_api.listen_addr, addr));
|
||||
}
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn missing_unencrypted_http_transport_flag() {
|
||||
let addr = "127.0.0.99".parse::<Ipv4Addr>().unwrap();
|
||||
let addr = "127.0.0.99".parse::<IpAddr>().unwrap();
|
||||
CommandLineTest::new()
|
||||
.flag("http-address", Some("127.0.0.99"))
|
||||
.run()
|
||||
@@ -373,13 +382,21 @@ fn metrics_flag() {
|
||||
}
|
||||
#[test]
|
||||
fn metrics_address_flag() {
|
||||
let addr = "127.0.0.99".parse::<Ipv4Addr>().unwrap();
|
||||
let addr = "127.0.0.99".parse::<IpAddr>().unwrap();
|
||||
CommandLineTest::new()
|
||||
.flag("metrics-address", Some("127.0.0.99"))
|
||||
.run()
|
||||
.with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr));
|
||||
}
|
||||
#[test]
|
||||
fn metrics_address_ipv6_flag() {
|
||||
let addr = "::1".parse::<IpAddr>().unwrap();
|
||||
CommandLineTest::new()
|
||||
.flag("metrics-address", Some("::1"))
|
||||
.run()
|
||||
.with_config(|config| assert_eq!(config.http_metrics.listen_addr, addr));
|
||||
}
|
||||
#[test]
|
||||
fn metrics_port_flag() {
|
||||
CommandLineTest::new()
|
||||
.flag("metrics-port", Some("9090"))
|
||||
|
||||
Reference in New Issue
Block a user