MCPcopy
hub / github.com/syncthing/syncthing / Serve

Method Serve

lib/nat/service.go:62–103  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

60}
61
62func (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
105func (s *Service) process(ctx context.Context) (int, time.Duration) {
106 // toRenew are mappings which are due for renewal

Callers

nothing calls this directly

Calls 8

processMethod · 0.95
DoneMethod · 0.80
DoMethod · 0.80
SubscribeMethod · 0.65
UnsubscribeMethod · 0.65
ResetMethod · 0.65
StopMethod · 0.45
clearAddressesMethod · 0.45

Tested by

no test coverage detected