How does the Announce packet work?

Recently I have been trying to understand how syncthing works under the hood. I started with the Local Discovery Protocol v4. While reading, I got stuck trying to understand how the Announcement message conveys its length without explicitly transmitting the length in a protobuf field or a length-prefixed frame.

I looked into the source code but couldn’t figure out much. So I ran wireshark on to study the packets sent. I got the magic number that syncthing uses. After stripping the magic number from the byte sequence, I ran the protobuf decoder (protoc --decode) on the message and it decoded fine. So I want to know how syncthing distinguishes between two announce packets.

I am a newbie in networking and stuff so please bear with me. Thanks

Local discovery uses UDP, and UDP has its own length field. The discovery packets are always single UDP packets, so each layer 4 packet is one layer 7 packet as well.

1 Like

Ahh! Thank you, I didnt knew that in UDP a single recieve call will return a single UDP packet and excess bytes that can’t be held in the storage buffer are discarded. That clarifies a lot. Thanks again for all the points that you shared.

1 Like

Yup, UDP doesn’t use the “stream” semantics like TCP or other high level protocols.

1 Like