Skip to content

Commit

Permalink
restart on public ip change
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Jun 7, 2024
1 parent f35229c commit 8883748
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
9 changes: 2 additions & 7 deletions functions/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
updateConfig = true
}

ipv6, err := ncutils.GetPublicIPv6()
ipv6, err := GetPublicIP(6)
if err != nil {
slog.Error("GetPublicIPv6 error: ", "error", err.Error())
} else {
Expand Down Expand Up @@ -536,12 +536,7 @@ func holePunchWgPort() (pubIP net.IP, pubPort int, natType string) {
portToStun := config.Netclient().ListenPort
pubIP, pubPort, natType = stun.HolePunch(portToStun)
if pubIP == nil { // if stun has failed fallback to ip service to get publicIP
var api string
server := config.GetServer(config.CurrServer)
if server != nil {
api = server.API
}
publicIP, err := ncutils.GetPublicIP(api)
publicIP, err := GetPublicIP(4)
if err != nil {
slog.Error("failed to get publicIP", "error", err)
return
Expand Down
12 changes: 8 additions & 4 deletions functions/mqpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) {
case <-ipTicker.C:
//
if !config.Netclient().IsStatic {
restart := false
ip4, err := GetPublicIP(4)
if err == nil && ip4 != nil && !ip4.IsUnspecified() {
config.HostPublicIP = ip4
if err == nil && ip4 != nil && !ip4.IsUnspecified() && !config.HostPublicIP.Equal(ip4) {
restart = true
}
ip6, err := GetPublicIP(6)
if err == nil && ip6 != nil && !ip6.IsUnspecified() {
config.HostPublicIP6 = ip6
if err == nil && ip6 != nil && !ip6.IsUnspecified() && !config.HostPublicIP6.Equal(ip6) {
restart = true
}
if restart {
daemon.Restart()
}
}
}
Expand Down

0 comments on commit 8883748

Please sign in to comment.