discover.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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"
  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. type FinderMux interface {
  34. Finder
  35. ChildStatus() map[string]error
  36. }
  37. // The AddressLister answers questions about what addresses we are listening
  38. // on.
  39. type AddressLister interface {
  40. ExternalAddresses() []string
  41. AllAddresses() []string
  42. }