2014-09-28 04:00:38 -07:00
|
|
|
Device Discovery Protocol v2
|
2014-02-20 09:40:15 -07:00
|
|
|
==========================
|
|
|
|
|
|
|
|
Mode of Operation
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
There are two distinct modes: "local discovery", performed on a LAN
|
|
|
|
segment (broadcast domain) and "global discovery" performed over the
|
|
|
|
Internet in general with the support of a well known server.
|
|
|
|
|
|
|
|
Local discovery does not use Query packets. Instead Announcement packets
|
2014-09-28 04:00:38 -07:00
|
|
|
are sent periodically and each participating device keeps a table of the
|
2014-02-20 09:40:15 -07:00
|
|
|
announcements it has seen. On multihomed hosts the announcement packets
|
|
|
|
should be sent on each interface that syncthing will accept connections.
|
|
|
|
|
|
|
|
It is recommended that local discovery Announcement packets are sent on
|
|
|
|
a 30 to 60 second interval, possibly with forced transmissions when a
|
2014-09-28 04:00:38 -07:00
|
|
|
previously unknown device is discovered.
|
2014-02-20 09:40:15 -07:00
|
|
|
|
|
|
|
Global discovery is made possible by periodically updating a global server
|
|
|
|
using Announcement packets indentical to those transmitted for local
|
2014-09-28 04:00:38 -07:00
|
|
|
discovery. The device performing discovery will transmit a Query packet to
|
2014-02-20 09:40:15 -07:00
|
|
|
the global server and expect an Announcement packet in response. In case
|
2014-09-28 04:00:38 -07:00
|
|
|
the global server has no knowledge of the queried device ID, there will be
|
2014-02-20 09:40:15 -07:00
|
|
|
no response. A timeout is to be used to determine lookup failure.
|
|
|
|
|
|
|
|
There is no message to unregister from the global server; instead
|
|
|
|
registrations are forgotten after 60 minutes. It is recommended to
|
|
|
|
send Announcement packets to the global server on a 30 minute interval.
|
|
|
|
|
|
|
|
Packet Formats
|
|
|
|
--------------
|
|
|
|
|
|
|
|
The Announcement packet has the following structure:
|
|
|
|
|
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-09-11 06:29:27 -07:00
|
|
|
| Magic (0x9D79BC39) |
|
2014-02-20 09:40:15 -07:00
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-05-11 15:55:43 -07:00
|
|
|
/ /
|
2014-09-28 04:39:39 -07:00
|
|
|
\ Device Structure \
|
2014-05-11 15:55:43 -07:00
|
|
|
/ /
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-09-28 04:39:39 -07:00
|
|
|
| Number of Extra Devices |
|
2014-02-20 09:40:15 -07:00
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
/ /
|
2014-09-28 04:39:39 -07:00
|
|
|
\ Zero or more Device Structures \
|
2014-05-11 15:55:43 -07:00
|
|
|
/ /
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
2014-09-28 04:00:38 -07:00
|
|
|
Device Structure:
|
2014-05-11 15:55:43 -07:00
|
|
|
|
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Length of ID |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
/ /
|
|
|
|
\ ID (variable length) \
|
2014-02-20 09:40:15 -07:00
|
|
|
/ /
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Number of Addresses |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
/ /
|
|
|
|
\ Zero or more Address Structures \
|
|
|
|
/ /
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
|
|
Address Structure:
|
|
|
|
|
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
| Length of IP |
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
/ /
|
|
|
|
\ IP (variable length) \
|
|
|
|
/ /
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-05-11 15:55:43 -07:00
|
|
|
| Port | 0x0000 |
|
2014-02-20 09:40:15 -07:00
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
|
|
This is the XDR encoding of:
|
|
|
|
|
|
|
|
struct Announcement {
|
2014-05-11 15:55:43 -07:00
|
|
|
unsigned int Magic;
|
2014-09-28 04:00:38 -07:00
|
|
|
Device This;
|
|
|
|
Device Extra<>;
|
2014-05-11 15:55:43 -07:00
|
|
|
}
|
|
|
|
|
2014-09-28 04:00:38 -07:00
|
|
|
struct Device {
|
2014-05-11 15:55:43 -07:00
|
|
|
string ID<>;
|
2014-02-20 09:40:15 -07:00
|
|
|
Address Addresses<>;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Address {
|
|
|
|
opaque IP<>;
|
2014-05-11 15:55:43 -07:00
|
|
|
unsigned short Port;
|
2014-02-20 09:40:15 -07:00
|
|
|
}
|
|
|
|
|
2014-09-28 04:00:38 -07:00
|
|
|
The first Device structure contains information about the sending device.
|
|
|
|
The following zero or more Extra devices contain information about other
|
|
|
|
devices known to the sending device.
|
2014-05-11 15:55:43 -07:00
|
|
|
|
|
|
|
In the Address structure, the IP field can be of three differnt kinds;
|
2014-02-20 09:40:15 -07:00
|
|
|
|
|
|
|
- A zero length indicates that the IP address should be taken from the
|
|
|
|
source address of the announcement packet, be it IPv4 or IPv6. The
|
2014-05-11 15:55:43 -07:00
|
|
|
source address must be a valid unicast address. This is only valid
|
2014-09-28 04:00:38 -07:00
|
|
|
in the first device structure, not in the list of extras.
|
2014-02-20 09:40:15 -07:00
|
|
|
|
|
|
|
- A four byte length indicates that the address is an IPv4 unicast
|
|
|
|
address.
|
|
|
|
|
|
|
|
- A sixteen byte length indicates that the address is an IPv6 unicast
|
|
|
|
address.
|
|
|
|
|
|
|
|
The Query packet has the following structure:
|
|
|
|
|
|
|
|
0 1 2 3
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-09-11 06:29:27 -07:00
|
|
|
| Magic Number (0x2CA856F5) |
|
2014-02-20 09:40:15 -07:00
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
2014-09-28 04:39:39 -07:00
|
|
|
| Length of Device ID |
|
2014-02-20 09:40:15 -07:00
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
/ /
|
2014-09-28 04:39:39 -07:00
|
|
|
\ Device ID (variable length) \
|
2014-02-20 09:40:15 -07:00
|
|
|
/ /
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
|
|
This is the XDR encoding of:
|
|
|
|
|
|
|
|
struct Announcement {
|
|
|
|
unsigned int MagicNumber;
|
2014-09-28 04:00:38 -07:00
|
|
|
string DeviceID<>;
|
2014-02-20 09:40:15 -07:00
|
|
|
}
|