@@ -2,6 +2,7 @@ package settings
22
33import (
44 "fmt"
5+ "net/netip"
56 "os"
67 "time"
78
@@ -24,16 +25,13 @@ type Health struct {
2425 // HTTP server. It defaults to 500 milliseconds.
2526 ReadTimeout time.Duration
2627 // TargetAddress is the address (host or host:port)
27- // to TCP dial to periodically for the health check.
28+ // to TCP TLS dial to periodically for the health check.
2829 // It cannot be the empty string in the internal state.
2930 TargetAddress string
30- // SuccessWait is the duration to wait to re-run the
31- // healthcheck after a successful healthcheck.
32- // It defaults to 5 seconds and cannot be zero in
33- // the internal state.
34- SuccessWait time.Duration
35- // VPN has health settings specific to the VPN loop.
36- VPN HealthyWait
31+ // ICMPTargetIP is the IP address to use for ICMP echo requests
32+ // in the health checker. It can be set to an unspecified address
33+ // such that the VPN server IP is used, which is also the default behavior.
34+ ICMPTargetIP netip.Addr
3735}
3836
3937func (h Health ) Validate () (err error ) {
@@ -42,11 +40,6 @@ func (h Health) Validate() (err error) {
4240 return fmt .Errorf ("server listening address is not valid: %w" , err )
4341 }
4442
45- err = h .VPN .validate ()
46- if err != nil {
47- return fmt .Errorf ("health VPN settings: %w" , err )
48- }
49-
5043 return nil
5144}
5245
@@ -56,8 +49,7 @@ func (h *Health) copy() (copied Health) {
5649 ReadHeaderTimeout : h .ReadHeaderTimeout ,
5750 ReadTimeout : h .ReadTimeout ,
5851 TargetAddress : h .TargetAddress ,
59- SuccessWait : h .SuccessWait ,
60- VPN : h .VPN .copy (),
52+ ICMPTargetIP : h .ICMPTargetIP ,
6153 }
6254}
6355
@@ -69,8 +61,7 @@ func (h *Health) OverrideWith(other Health) {
6961 h .ReadHeaderTimeout = gosettings .OverrideWithComparable (h .ReadHeaderTimeout , other .ReadHeaderTimeout )
7062 h .ReadTimeout = gosettings .OverrideWithComparable (h .ReadTimeout , other .ReadTimeout )
7163 h .TargetAddress = gosettings .OverrideWithComparable (h .TargetAddress , other .TargetAddress )
72- h .SuccessWait = gosettings .OverrideWithComparable (h .SuccessWait , other .SuccessWait )
73- h .VPN .overrideWith (other .VPN )
64+ h .ICMPTargetIP = gosettings .OverrideWithComparable (h .ICMPTargetIP , other .ICMPTargetIP )
7465}
7566
7667func (h * Health ) SetDefaults () {
@@ -80,9 +71,7 @@ func (h *Health) SetDefaults() {
8071 const defaultReadTimeout = 500 * time .Millisecond
8172 h .ReadTimeout = gosettings .DefaultComparable (h .ReadTimeout , defaultReadTimeout )
8273 h .TargetAddress = gosettings .DefaultComparable (h .TargetAddress , "cloudflare.com:443" )
83- const defaultSuccessWait = 5 * time .Second
84- h .SuccessWait = gosettings .DefaultComparable (h .SuccessWait , defaultSuccessWait )
85- h .VPN .setDefaults ()
74+ h .ICMPTargetIP = gosettings .DefaultComparable (h .ICMPTargetIP , netip .IPv4Unspecified ()) // use the VPN server IP
8675}
8776
8877func (h Health ) String () string {
@@ -93,27 +82,21 @@ func (h Health) toLinesNode() (node *gotree.Node) {
9382 node = gotree .New ("Health settings:" )
9483 node .Appendf ("Server listening address: %s" , h .ServerAddress )
9584 node .Appendf ("Target address: %s" , h .TargetAddress )
96- node .Appendf ("Duration to wait after success: %s" , h .SuccessWait )
97- node .Appendf ("Read header timeout: %s" , h .ReadHeaderTimeout )
98- node .Appendf ("Read timeout: %s" , h .ReadTimeout )
99- node .AppendNode (h .VPN .toLinesNode ("VPN" ))
85+ icmpTarget := "VPN server IP"
86+ if ! h .ICMPTargetIP .IsUnspecified () {
87+ icmpTarget = h .ICMPTargetIP .String ()
88+ }
89+ node .Appendf ("ICMP target IP: %s" , icmpTarget )
10090 return node
10191}
10292
10393func (h * Health ) Read (r * reader.Reader ) (err error ) {
10494 h .ServerAddress = r .String ("HEALTH_SERVER_ADDRESS" )
10595 h .TargetAddress = r .String ("HEALTH_TARGET_ADDRESS" ,
10696 reader .RetroKeys ("HEALTH_ADDRESS_TO_PING" ))
107-
108- h .SuccessWait , err = r .Duration ("HEALTH_SUCCESS_WAIT_DURATION" )
97+ h .ICMPTargetIP , err = r .NetipAddr ("HEALTH_ICMP_TARGET_IP" )
10998 if err != nil {
11099 return err
111100 }
112-
113- err = h .VPN .read (r )
114- if err != nil {
115- return fmt .Errorf ("VPN health settings: %w" , err )
116- }
117-
118101 return nil
119102}
0 commit comments