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)
| 202 | // Optionally takes renew flag which indicates whether or not we should renew |
| 203 | // mappings with existing natds |
| 204 | func (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 | |
| 220 | func (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 |
no test coverage detected