discover.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 discover
  7. import (
  8. "time"
  9. "github.com/syncthing/syncthing/lib/protocol"
  10. "github.com/thejerf/suture"
  11. )
  12. // A Finder provides lookup services of some kind.
  13. type Finder interface {
  14. Lookup(deviceID protocol.DeviceID) (direct []string, relays []Relay, err error)
  15. Error() error
  16. String() string
  17. Cache() map[protocol.DeviceID]CacheEntry
  18. }
  19. type CacheEntry struct {
  20. Direct []string `json:"direct"`
  21. Relays []Relay `json:"relays"`
  22. when time.Time // When did we get the result
  23. found bool // Is it a success (cacheTime applies) or a failure (negCacheTime applies)?
  24. }
  25. // A FinderService is a Finder that has background activity and must be run as
  26. // a suture.Service.
  27. type FinderService interface {
  28. Finder
  29. suture.Service
  30. }
  31. type FinderMux interface {
  32. Finder
  33. ChildStatus() map[string]error
  34. }
  35. // The RelayStatusProvider answers questions about current relay status.
  36. type RelayStatusProvider interface {
  37. Relays() []string
  38. RelayStatus(uri string) (time.Duration, bool)
  39. }
  40. // The AddressLister answers questions about what addresses we are listening
  41. // on.
  42. type AddressLister interface {
  43. ExternalAddresses() []string
  44. AllAddresses() []string
  45. }