MCPcopy
hub / github.com/syncthing/syncthing / updateMapping

Method updateMapping

lib/nat/service.go:204–218  ·  view source on GitHub ↗

updateMapping compares the addresses of the existing mapping versus the natds discovered, and removes any addresses of natds that do not exist, or tries to acquire mappings for natds which the mapping was unaware of before. Optionally takes renew flag which indicates whether or not we should renew m

(ctx context.Context, mapping *Mapping, nats map[string]Device, renew bool)

Source from the content-addressed store, hash-verified

202// Optionally takes renew flag which indicates whether or not we should renew
203// mappings with existing natds
204func (s *Service) updateMapping(ctx context.Context, mapping *Mapping, nats map[string]Device, renew bool) {
205 renewalTime := time.Duration(s.cfg.Options().NATRenewalM) * time.Minute
206
207 mapping.mut.Lock()
208
209 mapping.expires = time.Now().Add(renewalTime)
210 change := s.verifyExistingLocked(ctx, mapping, nats, renew)
211 add := s.acquireNewLocked(ctx, mapping, nats)
212
213 mapping.mut.Unlock()
214
215 if change || add {
216 mapping.notify()
217 }
218}
219
220func (s *Service) verifyExistingLocked(ctx context.Context, mapping *Mapping, nats map[string]Device, renew bool) (change bool) {
221 leaseTime := time.Duration(s.cfg.Options().NATLeaseM) * time.Minute

Callers 1

processMethod · 0.95

Calls 7

verifyExistingLockedMethod · 0.95
acquireNewLockedMethod · 0.95
UnlockMethod · 0.80
OptionsMethod · 0.65
NowMethod · 0.65
AddMethod · 0.45
notifyMethod · 0.45

Tested by

no test coverage detected