discover.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. "context"
  9. "time"
  10. "github.com/syncthing/syncthing/lib/protocol"
  11. "github.com/thejerf/suture/v4"
  12. )
  13. // A Finder provides lookup services of some kind.
  14. type Finder interface {
  15. Lookup(ctx context.Context, deviceID protocol.DeviceID) (address []string, err error)
  16. Error() error
  17. String() string
  18. Cache() map[protocol.DeviceID]CacheEntry
  19. }
  20. type CacheEntry struct {
  21. Addresses []string `json:"addresses"`
  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. instanceID int64 // for local discovery, the instance ID (random on each restart)
  26. }
  27. // A FinderService is a Finder that has background activity and must be run as
  28. // a suture.Service.
  29. type FinderService interface {
  30. Finder
  31. suture.Service
  32. }
  33. // The AddressLister answers questions about what addresses we are listening
  34. // on.
  35. type AddressLister interface {
  36. ExternalAddresses() []string
  37. AllAddresses() []string
  38. }