discover.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 https://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) (address []string, err error)
  15. Error() error
  16. String() string
  17. Cache() map[protocol.DeviceID]CacheEntry
  18. }
  19. type CacheEntry struct {
  20. Addresses []string `json:"addresses"`
  21. when time.Time // When did we get the result
  22. found bool // Is it a success (cacheTime applies) or a failure (negCacheTime applies)?
  23. validUntil time.Time // Validity time, overrides normal calculation
  24. instanceID int64 // for local discovery, the instance ID (random on each restart)
  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 AddressLister answers questions about what addresses we are listening
  37. // on.
  38. type AddressLister interface {
  39. ExternalAddresses() []string
  40. AllAddresses() []string
  41. }