doc.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. /*
  7. Package discover implements the local and global device discovery protocols.
  8. Global Discovery
  9. ================
  10. Announcements
  11. -------------
  12. A device should announce itself at startup. It does this by an HTTPS POST to
  13. the announce server URL (with the path usually being "/", but this is of
  14. course up to the discovery server). The POST has a JSON payload listing direct
  15. connection addresses (if any) and relay addresses (if any).
  16. {
  17. direct: ["tcp://192.0.2.45:22000", "tcp://:22202"],
  18. relays: [{"url": "relay://192.0.2.99:22028", "latency": 142}]
  19. }
  20. It's OK for either of the "direct" or "relays" fields to be either the empty
  21. list ([]), null, or missing entirely. An announcement with both fields missing
  22. or empty is however not useful...
  23. Any empty or unspecified IP addresses (i.e. addresses like tcp://:22000,
  24. tcp://0.0.0.0:22000, tcp://[::]:22000) are interpreted as referring to the
  25. source IP address of the announcement.
  26. The device ID of the announcing device is not part of the announcement.
  27. Instead, the server requires that the client perform certificate
  28. authentication. The device ID is deduced from the presented certificate.
  29. The server response is empty, with code 200 (OK) on success. If no certificate
  30. was presented, status 403 (Forbidden) is returned. If the posted data doesn't
  31. conform to the expected format, 400 (Bad Request) is returned.
  32. In successful responses, the server may return a "Reannounce-After" header
  33. containing the number of seconds after which the client should perform a new
  34. announcement.
  35. In error responses, the server may return a "Retry-After" header containing
  36. the number of seconds after which the client should retry.
  37. Performing announcements significantly more often than indicated by the
  38. Reannounce-After or Retry-After headers may result in the client being
  39. throttled. In such cases the server may respond with status code 429 (Too Many
  40. Requests).
  41. Queries
  42. =======
  43. Queries are performed as HTTPS GET requests to the announce server URL. The
  44. requested device ID is passed as the query parameter "device", in canonical
  45. string form, i.e. https://announce.syncthing.net/?device=ABC12345-....
  46. Successful responses will have status code 200 (OK) and carry a JSON payload
  47. of the same format as the announcement above. The response will not contain
  48. empty or unspecified addresses.
  49. If the "device" query parameter is missing or malformed, the status code 400
  50. (Bad Request) is returned.
  51. If the device ID is of a valid format but not found in the registry, 404 (Not
  52. Found) is returned.
  53. If the client has exceeded a rate limit, the server may respond with 429 (Too
  54. Many Requests).
  55. */
  56. package discover