(ctx context.Context)
| 60 | } |
| 61 | |
| 62 | func (s *Service) Serve(ctx context.Context) error { |
| 63 | s.cfg.Subscribe(s) |
| 64 | defer s.cfg.Unsubscribe(s) |
| 65 | |
| 66 | var announce sync.Once |
| 67 | |
| 68 | timer := time.NewTimer(0) |
| 69 | |
| 70 | for { |
| 71 | select { |
| 72 | case <-timer.C: |
| 73 | case <-s.processScheduled: |
| 74 | if !timer.Stop() { |
| 75 | select { |
| 76 | case <-timer.C: |
| 77 | default: |
| 78 | } |
| 79 | } |
| 80 | case <-ctx.Done(): |
| 81 | timer.Stop() |
| 82 | s.mut.RLock() |
| 83 | for _, mapping := range s.mappings { |
| 84 | mapping.clearAddresses() |
| 85 | } |
| 86 | s.mut.RUnlock() |
| 87 | return ctx.Err() |
| 88 | } |
| 89 | s.mut.RLock() |
| 90 | enabled := s.enabled |
| 91 | s.mut.RUnlock() |
| 92 | if !enabled { |
| 93 | continue |
| 94 | } |
| 95 | found, renewIn := s.process(ctx) |
| 96 | timer.Reset(renewIn) |
| 97 | if found != -1 { |
| 98 | announce.Do(func() { |
| 99 | slog.Info("Detected NAT services", "count", found) |
| 100 | }) |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | func (s *Service) process(ctx context.Context) (int, time.Duration) { |
| 106 | // toRenew are mappings which are due for renewal |
nothing calls this directly
no test coverage detected