feat(publicip): PUBLICIP_ENABLED replaces PUBLICIP_PERIOD

- No point periodically fetch the public IP address. Could not find anything mentioning why this was added.
- Simplification of the publicip loop code
- `PUBLICIP_ENABLED` (on, off) can be set to enable or not public ip data fetching on VPN connection
- `PUBLICIP_PERIOD=0` still works to indicate to disable public ip fetching
- `PUBLICIP_PERIOD` != 0 means to enable public ip fetching
- Warnings logged when using `PUBLICIP_PERIOD`
This commit is contained in:
Quentin McGaw
2024-10-07 19:49:25 +00:00
parent cbdd1a933c
commit 03deb9aed0
8 changed files with 59 additions and 109 deletions

View File

@@ -79,9 +79,12 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, err error)
keepPortDoneCh := make(chan struct{})
s.keepPortDoneCh = keepPortDoneCh
readyCh := make(chan struct{})
go func(ctx context.Context, portForwarder PortForwarder,
obj utils.PortForwardObjects, runError chan<- error, doneCh chan<- struct{}) {
obj utils.PortForwardObjects, readyCh chan<- struct{},
runError chan<- error, doneCh chan<- struct{}) {
defer close(doneCh)
close(readyCh)
err = portForwarder.KeepPortForward(ctx, obj)
crashed := ctx.Err() == nil
if !crashed { // stopped by Stop call
@@ -91,7 +94,8 @@ func (s *Service) Start(ctx context.Context) (runError <-chan error, err error)
defer s.startStopMutex.Unlock()
_ = s.cleanup()
runError <- err
}(keepPortCtx, s.settings.PortForwarder, obj, runErrorCh, keepPortDoneCh)
}(keepPortCtx, s.settings.PortForwarder, obj, readyCh, runErrorCh, keepPortDoneCh)
<-readyCh
return runErrorCh, nil
}