syncthing-bep.7 34 KB

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