registry.go 772 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. package nat
  7. import (
  8. "time"
  9. )
  10. type DiscoverFunc func(renewal, timeout time.Duration) []Device
  11. var providers []DiscoverFunc
  12. func Register(provider DiscoverFunc) {
  13. providers = append(providers, provider)
  14. }
  15. func discoverAll(renewal, timeout time.Duration) map[string]Device {
  16. nats := make(map[string]Device)
  17. for _, discoverFunc := range providers {
  18. discoveredNATs := discoverFunc(renewal, timeout)
  19. for _, discoveredNAT := range discoveredNATs {
  20. nats[discoveredNAT.ID()] = discoveredNAT
  21. }
  22. }
  23. return nats
  24. }