discover.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. validUntil time.Time // Validity time, overrides normal calculation
  25. }
  26. // A FinderService is a Finder that has background activity and must be run as
  27. // a suture.Service.
  28. type FinderService interface {
  29. Finder
  30. suture.Service
  31. }
  32. type FinderMux interface {
  33. Finder
  34. ChildStatus() map[string]error
  35. }
  36. // The RelayStatusProvider answers questions about current relay status.
  37. type RelayStatusProvider interface {
  38. Relays() []string
  39. RelayStatus(uri string) (time.Duration, bool)
  40. }
  41. // The AddressLister answers questions about what addresses we are listening
  42. // on.
  43. type AddressLister interface {
  44. ExternalAddresses() []string
  45. AllAddresses() []string
  46. }