lib/connections, lib/nat: Correctly dis-/enable nat (fixes #6552) (#6719)

This commit is contained in:
Simon Frei
2020-06-07 20:29:53 +02:00
committed by GitHub
parent 74ea9c5f67
commit 3065b127b5
3 changed files with 41 additions and 12 deletions
+27
View File
@@ -45,9 +45,36 @@ func NewService(id protocol.DeviceID, cfg config.Wrapper) *Service {
mut: sync.NewRWMutex(),
}
s.Service = util.AsService(s.serve, s.String())
cfg.Subscribe(s)
return s
}
func (s *Service) VerifyConfiguration(from, to config.Configuration) error {
return nil
}
func (s *Service) CommitConfiguration(from, to config.Configuration) bool {
if !from.Options.NATEnabled && to.Options.NATEnabled {
s.mut.Lock()
l.Debugln("Starting NAT service")
s.timer.Reset(0)
s.mut.Unlock()
} else if from.Options.NATEnabled && !to.Options.NATEnabled {
s.mut.Lock()
l.Debugln("Stopping NAT service")
if !s.timer.Stop() {
<-s.timer.C
}
s.mut.Unlock()
}
return true
}
func (s *Service) Stop() {
s.cfg.Unsubscribe(s)
s.Service.Stop()
}
func (s *Service) serve(ctx context.Context) {
announce := stdsync.Once{}