Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: updating was wrongly restricted by detection timeout #159

Merged
merged 2 commits into from
May 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions cmd/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,31 @@ func setIP(ctx context.Context, ppfmt pp.PP, c *config.Config, h api.Handle, ipN

var ipv6MessageDisplayed = false //nolint:gochecknoglobals

func updateIP(ctx context.Context, ppfmt pp.PP, c *config.Config, h api.Handle, ipNet ipnet.Type) {
func detectIP(ctx context.Context, ppfmt pp.PP, c *config.Config, h api.Handle, ipNet ipnet.Type) netip.Addr {
ctx, cancel := context.WithTimeout(ctx, c.DetectionTimeout)
defer cancel()

ip := c.Policy[ipNet].GetIP(ctx, ppfmt, ipNet)
if !ip.IsValid() {
if ip.IsValid() {
ppfmt.Infof(pp.EmojiInternet, "Detected the %s address: %v", ipNet.Describe(), ip)
} else {
ppfmt.Errorf(pp.EmojiError, "Failed to detect the %s address", ipNet.Describe())
if !ipv6MessageDisplayed && ipNet == ipnet.IP6 {
ipv6MessageDisplayed = true
ppfmt.Infof(pp.EmojiConfig, "If you are using Docker, Kubernetes, or other frameworks, IPv6 networks often require additional setups.") //nolint:lll
ppfmt.Infof(pp.EmojiConfig, "Read more about IPv6 networks in the README at https://github.com/favonia/cloudflare-ddns") //nolint:lll
}
return
}

ppfmt.Infof(pp.EmojiInternet, "Detected the %s address: %v", ipNet.Describe(), ip)
setIP(ctx, ppfmt, c, h, ipNet, ip)
return ip
}

func updateIPs(ctx context.Context, ppfmt pp.PP, c *config.Config, h api.Handle) {
for _, ipNet := range []ipnet.Type{ipnet.IP4, ipnet.IP6} {
if c.Policy[ipNet] != nil {
updateIP(ctx, ppfmt, c, h, ipNet)
ip := detectIP(ctx, ppfmt, c, h, ipNet)
if ip.IsValid() {
setIP(ctx, ppfmt, c, h, ipNet, ip)
}
}
}
}
Expand Down