syncthing-bep.7 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .
  4. .nr rst2man-indent-level 0
  5. .
  6. .de1 rstReportMargin
  7. \\$1 \\n[an-margin]
  8. level \\n[rst2man-indent-level]
  9. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  10. -
  11. \\n[rst2man-indent0]
  12. \\n[rst2man-indent1]
  13. \\n[rst2man-indent2]
  14. ..
  15. .de1 INDENT
  16. .\" .rstReportMargin pre:
  17. . RS \\$1
  18. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  19. . nr rst2man-indent-level +1
  20. .\" .rstReportMargin post:
  21. ..
  22. .de UNINDENT
  23. . RE
  24. .\" indent \\n[an-margin]
  25. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  26. .nr rst2man-indent-level -1
  27. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  28. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  29. ..
  30. .TH "SYNCTHING-BEP" "7" "Feb 29, 2024" "v1.27.3" "Syncthing"
  31. .SH NAME
  32. syncthing-bep \- Block Exchange Protocol v1
  33. .SH INTRODUCTION AND DEFINITIONS
  34. .sp
  35. The Block Exchange Protocol (BEP) is used between two or more \fIdevices\fP thus
  36. forming a \fIcluster\fP\&. Each device has one or more \fIfolders\fP of files
  37. described by the \fIlocal model\fP, containing metadata and block hashes. The
  38. local model is sent to the other devices in the cluster. The union of all
  39. files in the local models, with files selected for highest change version,
  40. forms the \fIglobal model\fP\&. Each device strives to get its folders in sync
  41. with the global model by requesting missing or outdated blocks from the
  42. other devices in the cluster.
  43. .sp
  44. File data is described and transferred in units of \fIblocks\fP, each being from
  45. 128 KiB (131072 bytes) to 16 MiB in size, in steps of powers of two. The
  46. block size may vary between files but is constant in any given file, except
  47. for the last block which may be smaller.
  48. .sp
  49. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”,
  50. “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this
  51. document are to be interpreted as described in \fI\%RFC 2119\fP <\fBhttps://datatracker.ietf.org/doc/html/rfc2119.html\fP>\&.
  52. .SH TRANSPORT AND AUTHENTICATION
  53. .sp
  54. BEP is deployed as the highest level in a protocol stack, with the lower
  55. level protocols providing encryption and authentication.
  56. .INDENT 0.0
  57. .INDENT 3.5
  58. .sp
  59. .nf
  60. .ft C
  61. +\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-+
  62. | Block Exchange Protocol |
  63. |\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|
  64. | Encryption & Auth (TLS 1.2) |
  65. |\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|
  66. | Reliable Transport |
  67. |\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-|
  68. v ... v
  69. .ft P
  70. .fi
  71. .UNINDENT
  72. .UNINDENT
  73. .sp
  74. The encryption and authentication layer SHALL use TLS 1.2 or a higher
  75. revision. A strong cipher suite SHALL be used, with “strong cipher
  76. suite” being defined as being without known weaknesses and providing
  77. Perfect Forward Secrecy (PFS). Examples of strong cipher suites are
  78. given at the end of this document. This is not to be taken as an
  79. exhaustive list of allowed cipher suites but represents best practices
  80. at the time of writing.
  81. .sp
  82. The exact nature of the authentication is up to the application, however
  83. it SHALL be based on the TLS certificate presented at the start of the
  84. connection. Possibilities include certificates signed by a common
  85. trusted CA, preshared certificates, preshared certificate fingerprints
  86. or certificate pinning combined with some out of band first
  87. verification. The reference implementation uses preshared certificate
  88. fingerprints (SHA\-256) referred to as “Device IDs”.
  89. .sp
  90. There is no required order or synchronization among BEP messages except
  91. as noted per message type \- any message type may be sent at any time and
  92. the sender need not await a response to one message before sending
  93. another.
  94. .sp
  95. The underlying transport protocol MUST guarantee reliable packet delivery.
  96. .sp
  97. In this document, in diagrams and text, “bit 0” refers to the \fImost
  98. significant\fP bit of a word; “bit 15” is thus the least significant bit of a
  99. 16 bit word (int16) and “bit 31” is the least significant bit of a 32 bit
  100. word (int32). Non protocol buffer integers are always represented in network
  101. byte order (i.e., big endian) and are signed unless stated otherwise, but
  102. when describing message lengths negative values do not make sense and the
  103. most significant bit MUST be zero.
  104. .sp
  105. The protocol buffer schemas in this document are in \fBproto3\fP syntax. This
  106. means, among other things, that all fields are optional and will assume
  107. their default value when missing. This does not necessarily mean that a
  108. message is \fIvalid\fP with all fields empty \- for example, an index entry for a
  109. file that does not have a name is not useful and MAY be rejected by the
  110. implementation. However the folder label is for human consumption only so an
  111. empty label should be accepted \- the implementation will have to choose some
  112. way to represent the folder, perhaps by using the ID in it’s place or
  113. automatically generating a label.
  114. .SH PRE-AUTHENTICATION MESSAGES
  115. .sp
  116. AFTER establishing a connection, but BEFORE performing any authentication,
  117. devices MUST exchange Hello messages.
  118. .sp
  119. Hello messages are used to carry additional information about the peer,
  120. which might be of interest to the user even if the peer is not permitted to
  121. communicate due to failing authentication. Note that the certificate based
  122. authentication may be considered part of the TLS handshake that precedes the
  123. Hello message exchange, but even in the case that a connection is rejected a
  124. Hello message must be sent before the connection is terminated.
  125. .sp
  126. Hello messages MUST be prefixed with an int32 containing the magic number
  127. \fB0x2EA7D90B\fP, followed by an int16 representing the size of the message,
  128. followed by the contents of the Hello message itself.
  129. .INDENT 0.0
  130. .INDENT 3.5
  131. .sp
  132. .nf
  133. .ft C
  134. 0 1
  135. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  136. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  137. | Magic |
  138. | (32 bits) |
  139. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  140. | Length |
  141. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  142. / /
  143. \e Hello \e
  144. / /
  145. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  146. .ft P
  147. .fi
  148. .UNINDENT
  149. .UNINDENT
  150. .sp
  151. The Hello message itself is in protocol buffer format with the following schema:
  152. .INDENT 0.0
  153. .INDENT 3.5
  154. .sp
  155. .nf
  156. .ft C
  157. message Hello {
  158. string device_name = 1;
  159. string client_name = 2;
  160. string client_version = 3;
  161. }
  162. .ft P
  163. .fi
  164. .UNINDENT
  165. .UNINDENT
  166. .SS Fields (Hello message)
  167. .sp
  168. The \fBdevice_name\fP is a human readable (configured or auto detected) device
  169. name or host name, for the remote device.
  170. .sp
  171. The \fBclient_name\fP and \fBclient_version\fP identifies the implementation. The
  172. values SHOULD be simple strings identifying the implementation name, as a
  173. user would expect to see it, and the version string in the same manner. An
  174. example client name is “syncthing” and an example client version is “v0.7.2”.
  175. The client version field SHOULD follow the patterns laid out in the \fI\%Semantic
  176. Versioning\fP <\fBhttps://semver.org/\fP> standard.
  177. .sp
  178. Immediately after exchanging Hello messages, the connection MUST be dropped
  179. if the remote device does not pass authentication.
  180. .SH POST-AUTHENTICATION MESSAGES
  181. .sp
  182. Every message post authentication is made up of several parts:
  183. .INDENT 0.0
  184. .IP \(bu 2
  185. A header length word
  186. .IP \(bu 2
  187. A \fBHeader\fP
  188. .IP \(bu 2
  189. A message length word
  190. .IP \(bu 2
  191. A \fBMessage\fP
  192. .UNINDENT
  193. .INDENT 0.0
  194. .INDENT 3.5
  195. .sp
  196. .nf
  197. .ft C
  198. 0 1
  199. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
  200. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  201. | Header Length |
  202. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  203. / /
  204. \e Header \e
  205. / /
  206. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  207. | Message Length |
  208. | (32 bits) |
  209. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  210. / /
  211. \e Message \e
  212. / /
  213. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  214. .ft P
  215. .fi
  216. .UNINDENT
  217. .UNINDENT
  218. .sp
  219. The header length word is 16 bits. It indicates the length of the following
  220. \fBHeader\fP message. The Header is in protocol buffer format. The Header
  221. describes the type and compression status of the following message.
  222. .sp
  223. The message is preceded by the 32 bit message length word and is one of the
  224. concrete BEP messages described below, identified by the \fBtype\fP field of
  225. the Header.
  226. .sp
  227. As always, the length words are in network byte order (big endian).
  228. .INDENT 0.0
  229. .INDENT 3.5
  230. .sp
  231. .nf
  232. .ft C
  233. message Header {
  234. MessageType type = 1;
  235. MessageCompression compression = 2;
  236. }
  237. enum MessageType {
  238. CLUSTER_CONFIG = 0;
  239. INDEX = 1;
  240. INDEX_UPDATE = 2;
  241. REQUEST = 3;
  242. RESPONSE = 4;
  243. DOWNLOAD_PROGRESS = 5;
  244. PING = 6;
  245. CLOSE = 7;
  246. }
  247. enum MessageCompression {
  248. NONE = 0;
  249. LZ4 = 1;
  250. }
  251. .ft P
  252. .fi
  253. .UNINDENT
  254. .UNINDENT
  255. .sp
  256. When the \fBcompression\fP field is \fBNONE\fP, the message is directly in
  257. protocol buffer format.
  258. .sp
  259. When the compression field is \fBLZ4\fP, the message consists of a 32 bit
  260. integer describing the uncompressed message length followed by a single LZ4
  261. block. After decompressing the LZ4 block it should be interpreted as a
  262. protocol buffer message just as in the uncompressed case.
  263. .SH MESSAGE SUBTYPES
  264. .SS Cluster Config
  265. .sp
  266. This informational message provides information about the cluster
  267. configuration as it pertains to the current connection. A Cluster Config
  268. message MUST be the first post authentication message sent on a BEP
  269. connection. Additional Cluster Config messages MUST NOT be sent after the
  270. initial exchange.
  271. .SS Protocol Buffer Schema
  272. .INDENT 0.0
  273. .INDENT 3.5
  274. .sp
  275. .nf
  276. .ft C
  277. message ClusterConfig {
  278. repeated Folder folders = 1;
  279. }
  280. message Folder {
  281. string id = 1;
  282. string label = 2;
  283. bool read_only = 3;
  284. bool ignore_permissions = 4;
  285. bool ignore_delete = 5;
  286. bool disable_temp_indexes = 6;
  287. bool paused = 7;
  288. repeated Device devices = 16;
  289. }
  290. message Device {
  291. bytes id = 1;
  292. string name = 2;
  293. repeated string addresses = 3;
  294. Compression compression = 4;
  295. string cert_name = 5;
  296. int64 max_sequence = 6;
  297. bool introducer = 7;
  298. uint64 index_id = 8;
  299. bool skip_introduction_removals = 9;
  300. bytes encryption_password_token = 10;
  301. }
  302. enum Compression {
  303. METADATA = 0;
  304. NEVER = 1;
  305. ALWAYS = 2;
  306. }
  307. .ft P
  308. .fi
  309. .UNINDENT
  310. .UNINDENT
  311. .SS Fields (Cluster Config Message)
  312. .sp
  313. The \fBfolders\fP field contains the list of folders that will be synchronized
  314. over the current connection.
  315. .SS Fields (Folder Message)
  316. .sp
  317. The \fBid\fP field contains the folder ID, which is the unique identifier of
  318. the folder.
  319. .sp
  320. The \fBlabel\fP field contains the folder label, the human readable name of
  321. the folder.
  322. .sp
  323. The \fBread_only\fP field is set for folders that the device will accept no
  324. updates from the network for.
  325. .sp
  326. The \fBignore_permissions\fP field is set for folders that the device will not
  327. accept or announce file permissions for.
  328. .sp
  329. The \fBignore_delete\fP field is set for folders that the device will ignore
  330. deletes for.
  331. .sp
  332. The \fBdisable_temp_indexes\fP field is set for folders that will not dispatch
  333. and do not wish to receive progress updates about partially downloaded files
  334. via Download Progress messages.
  335. .sp
  336. The \fBpaused\fP field is set for folders that are currently paused.
  337. .sp
  338. The \fBdevices\fP field is a list of devices participating in sharing this
  339. folder.
  340. .SS Fields (Device Message)
  341. .sp
  342. The device \fBid\fP field is a 32 byte number that uniquely identifies the
  343. device. For instance, the reference implementation uses the SHA\-256 of the
  344. device X.509 certificate.
  345. .sp
  346. The \fBname\fP field is a human readable name assigned to the described device
  347. by the sending device. It MAY be empty and it need not be unique.
  348. .sp
  349. The list of \fBaddresses\fP is that used by the sending device to connect to
  350. the described device.
  351. .sp
  352. The \fBcompression\fP field indicates the compression mode in use for this
  353. device and folder. The following values are valid:
  354. .INDENT 0.0
  355. .TP
  356. .B 0
  357. Compress metadata. This enables compression of metadata messages such as Index.
  358. .TP
  359. .B 1
  360. Compression disabled. No compression is used on any message.
  361. .TP
  362. .B 2
  363. Compress always. Metadata messages as well as Response messages are compressed.
  364. .UNINDENT
  365. .sp
  366. The \fBcert_name\fP field indicates the expected certificate name for this
  367. device. It is commonly blank, indicating to use the implementation default.
  368. .sp
  369. The \fBmax_sequence\fP field contains the highest sequence number of the files
  370. in the index. See \fI\%Delta Index Exchange\fP for the usage of this field.
  371. .sp
  372. The \fBintroducer\fP field is set for devices that are trusted as cluster
  373. introducers.
  374. .sp
  375. The \fBindex_id\fP field contains the unique identifier for the current set of
  376. index data. See \fI\%Delta Index Exchange\fP for the usage of this field.
  377. .sp
  378. The \fBskip_introduction_removals\fP field signifies if the remote device has
  379. opted to ignore introduction removals for the given device. This setting is
  380. copied across as we are being introduced to a new device.
  381. .sp
  382. The \fBencryption_password_token\fP field contains a token derived from the password, that is
  383. used to encrypt data sent to this device. If the device is the same as the
  384. device sending the message, it signifies that the device itself has encrypted
  385. data that was encrypted with the given token. It is empty or missing if there is
  386. no encryption. See \fI\%Untrusted Device Encryption\fP for details on the encryption scheme.
  387. .SS Index and Index Update
  388. .sp
  389. The Index and Index Update messages define the contents of the senders
  390. folder. An Index message represents the full contents of the folder and
  391. thus supersedes any previous index. An Index Update amends an existing
  392. index with new information, not affecting any entries not included in
  393. the message. An Index Update MAY NOT be sent unless preceded by an
  394. Index, unless a non\-zero Max Sequence has been announced for the
  395. given folder by the peer device.
  396. .sp
  397. The Index and Index Update messages are currently identical in format,
  398. although this is not guaranteed to be the case in the future.
  399. .SS Protocol Buffer Schema
  400. .INDENT 0.0
  401. .INDENT 3.5
  402. .sp
  403. .nf
  404. .ft C
  405. message Index {
  406. string folder = 1;
  407. repeated FileInfo files = 2;
  408. }
  409. message IndexUpdate {
  410. string folder = 1;
  411. repeated FileInfo files = 2;
  412. }
  413. message FileInfo {
  414. string name = 1;
  415. FileInfoType type = 2;
  416. int64 size = 3;
  417. uint32 permissions = 4;
  418. int64 modified_s = 5;
  419. int32 modified_ns = 11;
  420. uint64 modified_by = 12;
  421. bool deleted = 6;
  422. bool invalid = 7;
  423. bool no_permissions = 8;
  424. Vector version = 9;
  425. int64 sequence = 10;
  426. int32 block_size = 13;
  427. repeated BlockInfo Blocks = 16;
  428. string symlink_target = 17;
  429. }
  430. enum FileInfoType {
  431. FILE = 0;
  432. DIRECTORY = 1;
  433. SYMLINK_FILE = 2 [deprecated = true];
  434. SYMLINK_DIRECTORY = 3 [deprecated = true];
  435. SYMLINK = 4;
  436. }
  437. message BlockInfo {
  438. int64 offset = 1;
  439. int32 size = 2;
  440. bytes hash = 3;
  441. uint32 weak_hash = 4;
  442. }
  443. message Vector {
  444. repeated Counter counters = 1;
  445. }
  446. message Counter {
  447. uint64 id = 1;
  448. uint64 value = 2;
  449. }
  450. .ft P
  451. .fi
  452. .UNINDENT
  453. .UNINDENT
  454. .SS Fields (Index Message)
  455. .sp
  456. The \fBfolder\fP field identifies the folder that the index message pertains to.
  457. .sp
  458. The \fBfiles\fP field is a list of files making up the index information.
  459. .SS Fields (FileInfo Message)
  460. .sp
  461. The \fBname\fP is the file name path relative to the folder root. Like all
  462. strings in BEP, the Name is always in UTF\-8 NFC regardless of operating
  463. system or file system specific conventions. The name field uses the slash
  464. character (“/”) as path separator, regardless of the implementation’s
  465. operating system conventions. The combination of folder and name uniquely
  466. identifies each file in a cluster.
  467. .sp
  468. The \fBtype\fP field contains the type of the described item. The type is one
  469. of \fBfile (0)\fP, \fBdirectory (1)\fP, or \fBsymlink (4)\fP\&.
  470. .sp
  471. The \fBsize\fP field contains the size of the file, in bytes. For directories
  472. and symlinks the size is zero.
  473. .sp
  474. The \fBpermissions\fP field holds the common Unix permission bits. An
  475. implementation MAY ignore or interpret these as is suitable on the host
  476. operating system.
  477. .sp
  478. The \fBmodified_s\fP time is expressed as the number of seconds since the Unix
  479. Epoch (1970\-01\-01 00:00:00 UTC). The \fBmodified_ns\fP field holds the
  480. nanosecond part of the modification time.
  481. .sp
  482. The \fBmodified_by\fP field holds the short id of the client that last made
  483. any modification to the file whether add, change or delete. This will be
  484. overwritten every time a change is made to the file by the last client to do
  485. so and so does not hold history.
  486. .sp
  487. The \fBdeleted\fP field is set when the file has been deleted. The block list
  488. SHALL be of length zero and the modification time indicates the time of
  489. deletion or, if the time of deletion is not reliably determinable, the last
  490. known modification time.
  491. .sp
  492. The \fBinvalid\fP field is set when the file is invalid and unavailable for
  493. synchronization. A peer MAY set this bit to indicate that it can temporarily
  494. not serve data for the file.
  495. .sp
  496. The \fBno_permissions\fP field is set when there is no permission information
  497. for the file. This is the case when it originates on a file system which
  498. does not support permissions. Changes to only permission bits SHOULD be
  499. disregarded on files with this bit set. The permissions bits MUST be set to
  500. the octal value 0666.
  501. .sp
  502. The \fBversion\fP field is a version vector describing the updates performed
  503. to a file by all members in the cluster. Each counter in the version vector
  504. is an ID\-Value tuple. The ID is the first 64 bits of the device ID. The
  505. Value is a simple incrementing counter, starting at zero. The combination of
  506. Folder, Name and Version uniquely identifies the contents of a file at a
  507. given point in time.
  508. .sp
  509. The \fBsequence\fP field is the value of a device local monotonic clock at the
  510. time of last local database update to a file. The clock ticks on every local
  511. database update, thus forming a sequence number over database updates.
  512. .sp
  513. The \fBblock_size\fP field is the size, in bytes, of each individual block in
  514. the block list (except, possibly, the last block). If this field is missing
  515. or zero, the block size is assumed to be 128 KiB (131072 bytes). Valid
  516. values of this field are the powers of two from 128 KiB through 16 MiB. See
  517. also \fI\%Selection of Block Size\fP\&.
  518. .sp
  519. The \fBblocks\fP list contains the size and hash for each block in the file.
  520. Each block represents a \fBblock_size\fP\-sized slice of the file, except for
  521. the last block which may represent a smaller amount of data. The block list
  522. is empty for directories and symlinks.
  523. .sp
  524. The \fBsymlink_target\fP field contains the symlink target, for entries of
  525. symlink type. It is empty for all other entry types.
  526. .SS Request
  527. .sp
  528. The Request message expresses the desire to receive a data block
  529. corresponding to a part of a certain file in the peer’s folder.
  530. .SS Protocol Buffer Schema
  531. .INDENT 0.0
  532. .INDENT 3.5
  533. .sp
  534. .nf
  535. .ft C
  536. message Request {
  537. int32 id = 1;
  538. string folder = 2;
  539. string name = 3;
  540. int64 offset = 4;
  541. int32 size = 5;
  542. bytes hash = 6;
  543. bool from_temporary = 7;
  544. }
  545. .ft P
  546. .fi
  547. .UNINDENT
  548. .UNINDENT
  549. .SS Fields
  550. .sp
  551. The \fBid\fP is the request identifier. It will be matched in the
  552. corresponding \fBResponse\fP message. Each outstanding request must have a
  553. unique ID.
  554. .sp
  555. The \fBfolder\fP and \fBname\fP fields are as documented for the Index message.
  556. The \fBoffset\fP and \fBsize\fP fields specify the region of the file to be
  557. transferred. This SHOULD equate to exactly one block as seen in an Index
  558. message.
  559. .sp
  560. The \fIhash\fP field MAY be set to the expected hash value of the block. If set,
  561. the other device SHOULD ensure that the transmitted block matches the
  562. requested hash. The other device MAY reuse a block from a different file and
  563. offset having the same size and hash, if one exists.
  564. .sp
  565. The \fBfrom_temporary\fP field is set to indicate that the read should be
  566. performed from the temporary file (converting name to it’s temporary form)
  567. and falling back to the non temporary file if any error occurs. Knowledge of
  568. contents of temporary files comes from DownloadProgress messages.
  569. .SS Response
  570. .sp
  571. The Response message is sent in response to a Request message.
  572. .SS Protocol Buffer Schema
  573. .INDENT 0.0
  574. .INDENT 3.5
  575. .sp
  576. .nf
  577. .ft C
  578. message Response {
  579. int32 id = 1;
  580. bytes data = 2;
  581. ErrorCode code = 3;
  582. }
  583. enum ErrorCode {
  584. NO_ERROR = 0;
  585. GENERIC = 1;
  586. NO_SUCH_FILE = 2;
  587. INVALID_FILE = 3;
  588. }
  589. .ft P
  590. .fi
  591. .UNINDENT
  592. .UNINDENT
  593. .SS Fields
  594. .sp
  595. The \fBid\fP field is the request identifier. It must match the ID of the
  596. \fBRequest\fP that is being responded to.
  597. .sp
  598. The \fBdata\fP field contains either the requested data block or is empty if
  599. the requested block is not available.
  600. .sp
  601. The \fBcode\fP field contains an error code describing the reason a Request
  602. could not be fulfilled, in the case where zero length data was returned. The
  603. following values are defined:
  604. .INDENT 0.0
  605. .TP
  606. .B 0
  607. No Error (data should be present)
  608. .TP
  609. .B 1
  610. Generic Error
  611. .TP
  612. .B 2
  613. No Such File (the requested file does not exist, or the offset is
  614. outside the acceptable range for the file)
  615. .TP
  616. .B 3
  617. Invalid (file exists but has invalid bit set or is otherwise
  618. unavailable)
  619. .UNINDENT
  620. .SS DownloadProgress
  621. .sp
  622. The DownloadProgress message is used to notify remote devices about partial
  623. availability of files. By default, these messages are sent every 5 seconds,
  624. and only in the cases where progress or state changes have been detected.
  625. Each DownloadProgress message is addressed to a specific folder and MUST
  626. contain zero or more FileDownloadProgressUpdate messages.
  627. .SS Protocol Buffer Schema
  628. .INDENT 0.0
  629. .INDENT 3.5
  630. .sp
  631. .nf
  632. .ft C
  633. message DownloadProgress {
  634. string folder = 1;
  635. repeated FileDownloadProgressUpdate updates = 2;
  636. }
  637. message FileDownloadProgressUpdate {
  638. FileDownloadProgressUpdateType update_type = 1;
  639. string name = 2;
  640. Vector version = 3;
  641. repeated int32 block_indexes = 4;
  642. }
  643. enum FileDownloadProgressUpdateType {
  644. APPEND = 0;
  645. FORGET = 1;
  646. }
  647. .ft P
  648. .fi
  649. .UNINDENT
  650. .UNINDENT
  651. .SS Fields (DownloadProgress Message)
  652. .sp
  653. The \fBfolder\fP field represents the ID of the folder for which the update is
  654. being provided.
  655. .sp
  656. The \fBupdates\fP field is a list of progress update messages.
  657. .SS Fields (FileDownloadProgressUpdate Message)
  658. .sp
  659. The \fBupdate_type\fP indicates whether the update is of type \fBappend (0)\fP
  660. (new blocks are available) or \fBforget (1)\fP (the file transfer has
  661. completed or failed).
  662. .sp
  663. The \fBname\fP field defines the file name from the global index for which
  664. this update is being sent.
  665. .sp
  666. The \fBversion\fP message defines the version of the file for which this
  667. update is being sent.
  668. .sp
  669. The \fBblock_indexes\fP field is a list of positive integers, where each
  670. integer represents the index of the block in the FileInfo message Blocks
  671. array that has become available for download.
  672. .sp
  673. For example an integer with value 3 represents that the data defined in the
  674. fourth BlockInfo message of the FileInfo message of that file is now
  675. available. Please note that matching should be done on \fBname\fP AND
  676. \fBversion\fP\&. Furthermore, each update received is incremental, for example
  677. the initial update message might contain indexes 0, 1, 2, an update 5
  678. seconds later might contain indexes 3, 4, 5 which should be appended to the
  679. original list, which implies that blocks 0\-5 are currently available.
  680. .sp
  681. Block indexes MAY be added in any order. An implementation MUST NOT assume
  682. that block indexes are added in any specific order.
  683. .sp
  684. The \fBforget\fP field being set implies that previously advertised file is no
  685. longer available, therefore the list of block indexes should be truncated.
  686. .sp
  687. Messages with the \fBforget\fP field set MUST NOT have any block indexes.
  688. .sp
  689. Any update message which is being sent for a different \fBversion\fP of the
  690. same file name must be preceded with an update message for the old version
  691. of that file with the \fBforget\fP field set.
  692. .sp
  693. As a safeguard on the receiving side, the value of \fBversion\fP changing
  694. between update messages implies that the file has changed and that any
  695. indexes previously advertised are no longer available. The list of available
  696. block indexes MUST be replaced (rather than appended) with the indexes
  697. specified in this message.
  698. .SS Ping
  699. .sp
  700. The Ping message is used to determine that a connection is alive, and to
  701. keep connections alive through state tracking network elements such as
  702. firewalls and NAT gateways. A Ping message is sent every 90 seconds, if no
  703. other message has been sent in the preceding 90 seconds.
  704. .SS Protocol Buffer Schema
  705. .INDENT 0.0
  706. .INDENT 3.5
  707. .sp
  708. .nf
  709. .ft C
  710. message Ping {
  711. }
  712. .ft P
  713. .fi
  714. .UNINDENT
  715. .UNINDENT
  716. .SS Close
  717. .sp
  718. The Close message MAY be sent to indicate that the connection will be torn
  719. down due to an error condition. A Close message MUST NOT be followed by
  720. further messages.
  721. .SS Protocol Buffer Schema
  722. .INDENT 0.0
  723. .INDENT 3.5
  724. .sp
  725. .nf
  726. .ft C
  727. message Close {
  728. string reason = 1;
  729. }
  730. .ft P
  731. .fi
  732. .UNINDENT
  733. .UNINDENT
  734. .SS Fields
  735. .sp
  736. The \fBreason\fP field contains a human readable description of the error
  737. condition.
  738. .SH SHARING MODES
  739. .SS Trusted
  740. .sp
  741. Trusted mode is the default sharing mode. Updates are exchanged in both
  742. directions.
  743. .INDENT 0.0
  744. .INDENT 3.5
  745. .sp
  746. .nf
  747. .ft C
  748. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  749. | | \-\-\-\-\-\-\-\-\-\-\-> / \e
  750. | Device | | Cluster |
  751. | | <\-\-\-\-\-\-\-\-\-\-\- \e /
  752. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates \e\-\-\-\-\-\-\-\-\-/
  753. .ft P
  754. .fi
  755. .UNINDENT
  756. .UNINDENT
  757. .SS Send Only
  758. .sp
  759. In send only mode, a device does not apply any updates from the cluster, but
  760. publishes changes of its local folder to the cluster as usual.
  761. .INDENT 0.0
  762. .INDENT 3.5
  763. .sp
  764. .nf
  765. .ft C
  766. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  767. | | \-\-\-\-\-\-\-\-\-\-\-> / \e
  768. | Device | | Cluster |
  769. | | \e /
  770. +\-\-\-\-\-\-\-\-\-\-\-\-+ \e\-\-\-\-\-\-\-\-\-/
  771. .ft P
  772. .fi
  773. .UNINDENT
  774. .UNINDENT
  775. .SS Receive Only
  776. .sp
  777. In receive only mode, a device does not send any updates to the cluster, but
  778. accepts changes to its local folder from the cluster as usual.
  779. .INDENT 0.0
  780. .INDENT 3.5
  781. .sp
  782. .nf
  783. .ft C
  784. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  785. | | <\-\-\-\-\-\-\-\-\-\-\- / \e
  786. | Device | | Cluster |
  787. | | \e /
  788. +\-\-\-\-\-\-\-\-\-\-\-\-+ \e\-\-\-\-\-\-\-\-\-/
  789. .ft P
  790. .fi
  791. .UNINDENT
  792. .UNINDENT
  793. .SH DELTA INDEX EXCHANGE
  794. .sp
  795. Index data must be exchanged whenever two devices connect so that one knows
  796. the files available on the other. In the most basic case this happens by way
  797. of sending an \fBIndex\fP message followed by one or more \fBIndex Update\fP
  798. messages. Any previous index data known for a remote device is removed and
  799. replaced with the new index data received in an \fBIndex\fP message, while the
  800. contents of an \fBIndex Update\fP message is simply added to the existing
  801. index data.
  802. .sp
  803. For situations with large indexes or frequent reconnects this can be quite
  804. inefficient. A mechanism can then be used to retain index data between
  805. connections and only transmit any changes since that data on connection
  806. start. This is called “delta indexes”. To enable this mechanism the
  807. \fBsequence\fP and \fBindex ID\fP fields are used.
  808. .INDENT 0.0
  809. .TP
  810. .B Sequence:
  811. Each index item (i.e., file, directory or symlink) has a sequence number
  812. field. It contains the value of a counter at the time the index item was
  813. updated. The counter increments by one for each change. That is, as files
  814. are scanned and added to the index they get assigned sequence numbers
  815. 1, 2, 3 and so on. The next file to be changed or detected gets sequence
  816. number 4, and future updates continue in the same fashion.
  817. .TP
  818. .B Index ID:
  819. Each folder has an Index ID. This is a 64 bit random identifier set at
  820. index creation time.
  821. .UNINDENT
  822. .sp
  823. Given the above, we know that the tuple {index ID, maximum sequence number}
  824. uniquely identifies a point in time of a given index. Any further changes
  825. will increase the sequence number of some item, and thus the maximum
  826. sequence number for the index itself. Should the index be reset or removed
  827. (i.e., the sequence number reset to zero), a new index ID must be generated.
  828. .sp
  829. By letting a device know the {index ID, maximum sequence number} we have for
  830. their index data, that device can arrange to only transmit \fBIndex Update\fP
  831. messages for items with a higher sequence number. This is the delta index
  832. mechanism.
  833. .sp
  834. The index ID and maximum sequence number known for each device is
  835. transmitted in the \fBCluster Config\fP message at connection start.
  836. .sp
  837. For this mechanism to be reliable it is essential that outgoing index
  838. information is ordered by increasing sequence number. Devices announcing a
  839. non\-zero index ID in the \fBCluster Config\fP message MUST send all index data
  840. ordered by increasing sequence number. Devices not intending to participate
  841. in delta index exchange MUST send a zero index ID or, equivalently, not send
  842. the \fBindex_id\fP attribute at all.
  843. .SH MESSAGE LIMITS
  844. .sp
  845. An implementation MAY impose reasonable limits on the length of messages and
  846. message fields to aid robustness in the face of corruption or broken
  847. implementations. An implementation should strive to keep messages short
  848. and to the point, favouring more and smaller messages over fewer and larger.
  849. For example, favour a smaller Index message followed by one or more Index
  850. Update messages rather than sending a very large Index message.
  851. .sp
  852. The Syncthing implementation imposes a hard limit of 500,000,000 bytes on
  853. all messages. Attempting to send or receive a larger message will result in
  854. a connection close. This size was chosen to accommodate Index messages
  855. containing a large block list. It’s intended that the limit may be further
  856. reduced in a future protocol update supporting variable block sizes (and
  857. thus shorter block lists for large files).
  858. .SH SELECTION OF BLOCK SIZE
  859. .sp
  860. The desired block size for any given file is the smallest block size that
  861. results in fewer than 2000 blocks, or the maximum block size for larger
  862. files. This rule results in the following table of block sizes per file
  863. size:
  864. .TS
  865. center;
  866. |l|l|.
  867. _
  868. T{
  869. File Size
  870. T} T{
  871. Block Size
  872. T}
  873. _
  874. T{
  875. 0 \- 250 MiB
  876. T} T{
  877. 128 KiB
  878. T}
  879. _
  880. T{
  881. 250 MiB \- 500 MiB
  882. T} T{
  883. 256 KiB
  884. T}
  885. _
  886. T{
  887. 500 MiB \- 1 GiB
  888. T} T{
  889. 512 KiB
  890. T}
  891. _
  892. T{
  893. 1 GiB \- 2 GiB
  894. T} T{
  895. 1 MiB
  896. T}
  897. _
  898. T{
  899. 2 GiB \- 4 GiB
  900. T} T{
  901. 2 MiB
  902. T}
  903. _
  904. T{
  905. 4 GiB \- 8 GiB
  906. T} T{
  907. 4 MiB
  908. T}
  909. _
  910. T{
  911. 8 GiB \- 16 GiB
  912. T} T{
  913. 8 MiB
  914. T}
  915. _
  916. T{
  917. 16 GiB \- up
  918. T} T{
  919. 16 MiB
  920. T}
  921. _
  922. .TE
  923. .sp
  924. An implementation MAY deviate from the block size rule when there is good
  925. reason to do so. For example, if a file has been indexed at a certain block
  926. size and grows beyond 2000 blocks it may be retained at the current block
  927. size for practical reasons. When there is no overriding reason to the
  928. contrary, such as when indexing a new file for the first time, the block
  929. size rule above SHOULD be followed.
  930. .sp
  931. An implementation MUST therefore accept files with a block size differing
  932. from the above rule. This does not mean that arbitrary block sizes are
  933. allowed. The block size used MUST be exactly one of the power\-of\-two block
  934. sizes listed in the table above.
  935. .SH EXAMPLE EXCHANGE
  936. .TS
  937. center;
  938. |l|l|l|.
  939. _
  940. T{
  941. #
  942. T} T{
  943. A
  944. T} T{
  945. B
  946. T}
  947. _
  948. T{
  949. 1
  950. T} T{
  951. ClusterConfiguration\->
  952. T} T{
  953. <\-ClusterConfiguration
  954. T}
  955. _
  956. T{
  957. 2
  958. T} T{
  959. Index\->
  960. T} T{
  961. <\-Index
  962. T}
  963. _
  964. T{
  965. 3
  966. T} T{
  967. IndexUpdate\->
  968. T} T{
  969. <\-IndexUpdate
  970. T}
  971. _
  972. T{
  973. 4
  974. T} T{
  975. IndexUpdate\->
  976. T} T{
  977. T}
  978. _
  979. T{
  980. 5
  981. T} T{
  982. Request\->
  983. T} T{
  984. T}
  985. _
  986. T{
  987. 6
  988. T} T{
  989. Request\->
  990. T} T{
  991. T}
  992. _
  993. T{
  994. 7
  995. T} T{
  996. Request\->
  997. T} T{
  998. T}
  999. _
  1000. T{
  1001. 8
  1002. T} T{
  1003. Request\->
  1004. T} T{
  1005. T}
  1006. _
  1007. T{
  1008. 9
  1009. T} T{
  1010. T} T{
  1011. <\-Response
  1012. T}
  1013. _
  1014. T{
  1015. 10
  1016. T} T{
  1017. T} T{
  1018. <\-Response
  1019. T}
  1020. _
  1021. T{
  1022. 11
  1023. T} T{
  1024. T} T{
  1025. <\-Response
  1026. T}
  1027. _
  1028. T{
  1029. 12
  1030. T} T{
  1031. T} T{
  1032. <\-Response
  1033. T}
  1034. _
  1035. T{
  1036. 13
  1037. T} T{
  1038. Index Update\->
  1039. T} T{
  1040. T}
  1041. _
  1042. T{
  1043. T} T{
  1044. T} T{
  1045. T}
  1046. _
  1047. T{
  1048. 14
  1049. T} T{
  1050. T} T{
  1051. <\-Ping
  1052. T}
  1053. _
  1054. T{
  1055. 15
  1056. T} T{
  1057. Ping\->
  1058. T} T{
  1059. T}
  1060. _
  1061. .TE
  1062. .sp
  1063. The connection is established and at 1. both peers send ClusterConfiguration
  1064. messages and then Index records. The Index records are received and both
  1065. peers recompute their knowledge of the data in the cluster. In this example,
  1066. peer A has four missing or outdated blocks. At 5 through 8 peer A sends
  1067. requests for these blocks. The requests are received by peer B, who
  1068. retrieves the data from the folder and transmits Response records (9 through
  1069. 12). Device A updates their folder contents and transmits an Index Update
  1070. message (13). Both peers enter idle state after 13. At some later time 14,
  1071. the ping timer on device B expires and a Ping message is sent. The same
  1072. process occurs for device A at 15.
  1073. .SH EXAMPLES OF STRONG CIPHER SUITES
  1074. .TS
  1075. center;
  1076. |l|l|l|.
  1077. _
  1078. T{
  1079. ID
  1080. T} T{
  1081. Name
  1082. T} T{
  1083. Description
  1084. T}
  1085. _
  1086. T{
  1087. 0x009F
  1088. T} T{
  1089. DHE\-RSA\-AES256\-GCM\-SHA384
  1090. T} T{
  1091. TLSv1.2 DH RSA AESGCM(256) AEAD
  1092. T}
  1093. _
  1094. T{
  1095. 0x006B
  1096. T} T{
  1097. DHE\-RSA\-AES256\-SHA256
  1098. T} T{
  1099. TLSv1.2 DH RSA AES(256) SHA256
  1100. T}
  1101. _
  1102. T{
  1103. 0xC030
  1104. T} T{
  1105. ECDHE\-RSA\-AES256\-GCM\-SHA384
  1106. T} T{
  1107. TLSv1.2 ECDH RSA AESGCM(256) AEAD
  1108. T}
  1109. _
  1110. T{
  1111. 0xC028
  1112. T} T{
  1113. ECDHE\-RSA\-AES256\-SHA384
  1114. T} T{
  1115. TLSv1.2 ECDH RSA AES(256) SHA384
  1116. T}
  1117. _
  1118. T{
  1119. 0x009E
  1120. T} T{
  1121. DHE\-RSA\-AES128\-GCM\-SHA256
  1122. T} T{
  1123. TLSv1.2 DH RSA AESGCM(128) AEAD
  1124. T}
  1125. _
  1126. T{
  1127. 0x0067
  1128. T} T{
  1129. DHE\-RSA\-AES128\-SHA256
  1130. T} T{
  1131. TLSv1.2 DH RSA AES(128) SHA256
  1132. T}
  1133. _
  1134. T{
  1135. 0xC02F
  1136. T} T{
  1137. ECDHE\-RSA\-AES128\-GCM\-SHA256
  1138. T} T{
  1139. TLSv1.2 ECDH RSA AESGCM(128) AEAD
  1140. T}
  1141. _
  1142. T{
  1143. 0xC027
  1144. T} T{
  1145. ECDHE\-RSA\-AES128\-SHA256
  1146. T} T{
  1147. TLSv1.2 ECDH RSA AES(128) SHA256
  1148. T}
  1149. _
  1150. .TE
  1151. .SH AUTHOR
  1152. The Syncthing Authors
  1153. .SH COPYRIGHT
  1154. 2014-2019, The Syncthing Authors
  1155. .\" Generated by docutils manpage writer.
  1156. .