syncthing-bep.7 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .TH "SYNCTHING-BEP" "7" "Aug 16, 2020" "v1" "Syncthing"
  4. .SH NAME
  5. syncthing-bep \- Block Exchange Protocol v1
  6. .
  7. .nr rst2man-indent-level 0
  8. .
  9. .de1 rstReportMargin
  10. \\$1 \\n[an-margin]
  11. level \\n[rst2man-indent-level]
  12. level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
  13. -
  14. \\n[rst2man-indent0]
  15. \\n[rst2man-indent1]
  16. \\n[rst2man-indent2]
  17. ..
  18. .de1 INDENT
  19. .\" .rstReportMargin pre:
  20. . RS \\$1
  21. . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
  22. . nr rst2man-indent-level +1
  23. .\" .rstReportMargin post:
  24. ..
  25. .de UNINDENT
  26. . RE
  27. .\" indent \\n[an-margin]
  28. .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
  29. .nr rst2man-indent-level -1
  30. .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
  31. .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
  32. ..
  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 [RFC 2119](\fI\%https://tools.ietf.org/html/rfc2119\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 <\fBhttp://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. }
  301. enum Compression {
  302. METADATA = 0;
  303. NEVER = 1;
  304. ALWAYS = 2;
  305. }
  306. .ft P
  307. .fi
  308. .UNINDENT
  309. .UNINDENT
  310. .SS Fields (Cluster Config Message)
  311. .sp
  312. The \fBfolders\fP field contains the list of folders that will be synchronized
  313. over the current connection.
  314. .SS Fields (Folder Message)
  315. .sp
  316. The \fBid\fP field contains the folder ID, which is the unique identifier of
  317. the folder.
  318. .sp
  319. The \fBlabel\fP field contains the folder label, the human readable name of
  320. the folder.
  321. .sp
  322. The \fBread only\fP field is set for folders that the device will accept no
  323. updates from the network for.
  324. .sp
  325. The \fBignore permissions\fP field is set for folders that the device will not
  326. accept or announce file permissions for.
  327. .sp
  328. The \fBignore delete\fP field is set for folders that the device will ignore
  329. deletes for.
  330. .sp
  331. The \fBdisable temp indexes\fP field is set for folders that will not dispatch
  332. and do not wish to receive progress updates about partially downloaded files
  333. via Download Progress messages.
  334. .sp
  335. The \fBpaused\fP field is set for folders that are currently paused.
  336. .sp
  337. The \fBdevices\fP field is a list of devices participating in sharing this
  338. folder.
  339. .SS Fields (Device Message)
  340. .sp
  341. The device \fBid\fP field is a 32 byte number that uniquely identifies the
  342. device. For instance, the reference implementation uses the SHA\-256 of the
  343. device X.509 certificate.
  344. .sp
  345. The \fBname\fP field is a human readable name assigned to the described device
  346. by the sending device. It MAY be empty and it need not be unique.
  347. .sp
  348. The list of \fBaddresses\fP is that used by the sending device to connect to
  349. the described device.
  350. .sp
  351. The \fBcompression\fP field indicates the compression mode in use for this
  352. device and folder. The following values are valid:
  353. .INDENT 0.0
  354. .TP
  355. .B 0
  356. Compress metadata. This enables compression of metadata messages such as Index.
  357. .TP
  358. .B 1
  359. Compression disabled. No compression is used on any message.
  360. .TP
  361. .B 2
  362. Compress always. Metadata messages as well as Response messages are compressed.
  363. .UNINDENT
  364. .sp
  365. The \fBcert name\fP field indicates the expected certificate name for this
  366. device. It is commonly blank, indicating to use the implementation default.
  367. .sp
  368. The \fBmax sequence\fP field contains the highest sequence number of the files
  369. in the index. See \fI\%Delta Index Exchange\fP for the usage of this field.
  370. .sp
  371. The \fBintroducer\fP field is set for devices that are trusted as cluster
  372. introducers.
  373. .sp
  374. The \fBindex id\fP field contains the unique identifier for the current set of
  375. index data. See \fI\%Delta Index Exchange\fP for the usage of this field.
  376. .sp
  377. The \fBskip introduction removals\fP field signifies if the remote device has
  378. opted to ignore introduction removals for the given device. This setting is
  379. copied across as we are being introduced to a new device.
  380. .SS Index and Index Update
  381. .sp
  382. The Index and Index Update messages define the contents of the senders
  383. folder. An Index message represents the full contents of the folder and
  384. thus supersedes any previous index. An Index Update amends an existing
  385. index with new information, not affecting any entries not included in
  386. the message. An Index Update MAY NOT be sent unless preceded by an
  387. Index, unless a non\-zero Max Sequence has been announced for the
  388. given folder by the peer device.
  389. .sp
  390. The Index and Index Update messages are currently identical in format,
  391. although this is not guaranteed to be the case in the future.
  392. .SS Protocol Buffer Schema
  393. .INDENT 0.0
  394. .INDENT 3.5
  395. .sp
  396. .nf
  397. .ft C
  398. message Index {
  399. string folder = 1;
  400. repeated FileInfo files = 2;
  401. }
  402. message IndexUpdate {
  403. string folder = 1;
  404. repeated FileInfo files = 2;
  405. }
  406. message FileInfo {
  407. string name = 1;
  408. FileInfoType type = 2;
  409. int64 size = 3;
  410. uint32 permissions = 4;
  411. int64 modified_s = 5;
  412. int32 modified_ns = 11;
  413. uint64 modified_by = 12;
  414. bool deleted = 6;
  415. bool invalid = 7;
  416. bool no_permissions = 8;
  417. Vector version = 9;
  418. int64 sequence = 10;
  419. int32 block_size = 13;
  420. repeated BlockInfo Blocks = 16;
  421. string symlink_target = 17;
  422. }
  423. enum FileInfoType {
  424. FILE = 0;
  425. DIRECTORY = 1;
  426. SYMLINK_FILE = 2 [deprecated = true];
  427. SYMLINK_DIRECTORY = 3 [deprecated = true];
  428. SYMLINK = 4;
  429. }
  430. message BlockInfo {
  431. int64 offset = 1;
  432. int32 size = 2;
  433. bytes hash = 3;
  434. uint32 weak_hash = 4;
  435. }
  436. message Vector {
  437. repeated Counter counters = 1;
  438. }
  439. message Counter {
  440. uint64 id = 1;
  441. uint64 value = 2;
  442. }
  443. .ft P
  444. .fi
  445. .UNINDENT
  446. .UNINDENT
  447. .SS Fields (Index Message)
  448. .sp
  449. The \fBfolder\fP field identifies the folder that the index message pertains to.
  450. .sp
  451. The \fBfiles\fP field is a list of files making up the index information.
  452. .SS Fields (FileInfo Message)
  453. .sp
  454. The \fBname\fP is the file name path relative to the folder root. Like all
  455. strings in BEP, the Name is always in UTF\-8 NFC regardless of operating
  456. system or file system specific conventions. The name field uses the slash
  457. character (“/”) as path separator, regardless of the implementation’s
  458. operating system conventions. The combination of folder and name uniquely
  459. identifies each file in a cluster.
  460. .sp
  461. The \fBtype\fP field contains the type of the described item. The type is one
  462. of \fBfile (0)\fP, \fBdirectory (1)\fP, or \fBsymlink (4)\fP\&.
  463. .sp
  464. The \fBsize\fP field contains the size of the file, in bytes. For directories
  465. and symlinks the size is zero.
  466. .sp
  467. The \fBpermissions\fP field holds the common Unix permission bits. An
  468. implementation MAY ignore or interpret these as is suitable on the host
  469. operating system.
  470. .sp
  471. The \fBmodified_s\fP time is expressed as the number of seconds since the Unix
  472. Epoch (1970\-01\-01 00:00:00 UTC). The \fBmodified_ns\fP field holds the
  473. nanosecond part of the modification time.
  474. .sp
  475. The \fBmodified_by\fP field holds the short id of the client that last made
  476. any modification to the file whether add, change or delete. This will be
  477. overwritten every time a change is made to the file by the last client to do
  478. so and so does not hold history.
  479. .sp
  480. The \fBdeleted\fP field is set when the file has been deleted. The block list
  481. SHALL be of length zero and the modification time indicates the time of
  482. deletion or, if the time of deletion is not reliably determinable, the last
  483. known modification time.
  484. .sp
  485. The \fBinvalid\fP field is set when the file is invalid and unavailable for
  486. synchronization. A peer MAY set this bit to indicate that it can temporarily
  487. not serve data for the file.
  488. .sp
  489. The \fBno permissions\fP field is set when there is no permission information
  490. for the file. This is the case when it originates on a file system which
  491. does not support permissions. Changes to only permission bits SHOULD be
  492. disregarded on files with this bit set. The permissions bits MUST be set to
  493. the octal value 0666.
  494. .sp
  495. The \fBversion\fP field is a version vector describing the updates performed
  496. to a file by all members in the cluster. Each counter in the version vector
  497. is an ID\-Value tuple. The ID is the first 64 bits of the device ID. The
  498. Value is a simple incrementing counter, starting at zero. The combination of
  499. Folder, Name and Version uniquely identifies the contents of a file at a
  500. given point in time.
  501. .sp
  502. The \fBsequence\fP field is the value of a device local monotonic clock at the
  503. time of last local database update to a file. The clock ticks on every local
  504. database update, thus forming a sequence number over database updates.
  505. .sp
  506. The \fBblock_size\fP field is the size, in bytes, of each individual block in
  507. the block list (except, possibly, the last block). If this field is missing
  508. or zero, the block size is assumed to be 128 KiB (131072 bytes). Valid
  509. values of this field are the powers of two from 128 KiB through 16 MiB. See
  510. also \fI\%Selection of Block Size\fP\&.
  511. .sp
  512. The \fBblocks\fP list contains the size and hash for each block in the file.
  513. Each block represents a \fBblock_size\fP\-sized slice of the file, except for
  514. the last block which may represent a smaller amount of data. The block list
  515. is empty for directories and symlinks.
  516. .sp
  517. The \fBsymlink_target\fP field contains the symlink target, for entries of
  518. symlink type. It is empty for all other entry types.
  519. .SS Request
  520. .sp
  521. The Request message expresses the desire to receive a data block
  522. corresponding to a part of a certain file in the peer’s folder.
  523. .SS Protocol Buffer Schema
  524. .INDENT 0.0
  525. .INDENT 3.5
  526. .sp
  527. .nf
  528. .ft C
  529. message Request {
  530. int32 id = 1;
  531. string folder = 2;
  532. string name = 3;
  533. int64 offset = 4;
  534. int32 size = 5;
  535. bytes hash = 6;
  536. bool from_temporary = 7;
  537. }
  538. .ft P
  539. .fi
  540. .UNINDENT
  541. .UNINDENT
  542. .SS Fields
  543. .sp
  544. The \fBid\fP is the request identifier. It will be matched in the
  545. corresponding \fBResponse\fP message. Each outstanding request must have a
  546. unique ID.
  547. .sp
  548. The \fBfolder\fP and \fBname\fP fields are as documented for the Index message.
  549. The \fBoffset\fP and \fBsize\fP fields specify the region of the file to be
  550. transferred. This SHOULD equate to exactly one block as seen in an Index
  551. message.
  552. .sp
  553. The \fIhash\fP field MAY be set to the expected hash value of the block. If set,
  554. the other device SHOULD ensure that the transmitted block matches the
  555. requested hash. The other device MAY reuse a block from a different file and
  556. offset having the same size and hash, if one exists.
  557. .sp
  558. The \fBfrom temporary\fP field is set to indicate that the read should be
  559. performed from the temporary file (converting name to it’s temporary form)
  560. and falling back to the non temporary file if any error occurs. Knowledge of
  561. contents of temporary files comes from DownloadProgress messages.
  562. .SS Response
  563. .sp
  564. The Response message is sent in response to a Request message.
  565. .SS Protocol Buffer Schema
  566. .INDENT 0.0
  567. .INDENT 3.5
  568. .sp
  569. .nf
  570. .ft C
  571. message Response {
  572. int32 id = 1;
  573. bytes data = 2;
  574. ErrorCode code = 3;
  575. }
  576. enum ErrorCode {
  577. NO_ERROR = 0;
  578. GENERIC = 1;
  579. NO_SUCH_FILE = 2;
  580. INVALID_FILE = 3;
  581. }
  582. .ft P
  583. .fi
  584. .UNINDENT
  585. .UNINDENT
  586. .SS Fields
  587. .sp
  588. The \fBid\fP field is the request identifier. It must match the ID of the
  589. \fBRequest\fP that is being responded to.
  590. .sp
  591. The \fBdata\fP field contains either the requested data block or is empty if
  592. the requested block is not available.
  593. .sp
  594. The \fBcode\fP field contains an error code describing the reason a Request
  595. could not be fulfilled, in the case where zero length data was returned. The
  596. following values are defined:
  597. .INDENT 0.0
  598. .TP
  599. .B 0
  600. No Error (data should be present)
  601. .TP
  602. .B 1
  603. Generic Error
  604. .TP
  605. .B 2
  606. No Such File (the requested file does not exist, or the offset is
  607. outside the acceptable range for the file)
  608. .TP
  609. .B 3
  610. Invalid (file exists but has invalid bit set or is otherwise
  611. unavailable)
  612. .UNINDENT
  613. .SS DownloadProgress
  614. .sp
  615. The DownloadProgress message is used to notify remote devices about partial
  616. availability of files. By default, these messages are sent every 5 seconds,
  617. and only in the cases where progress or state changes have been detected.
  618. Each DownloadProgress message is addressed to a specific folder and MUST
  619. contain zero or more FileDownloadProgressUpdate messages.
  620. .SS Protocol Buffer Schema
  621. .INDENT 0.0
  622. .INDENT 3.5
  623. .sp
  624. .nf
  625. .ft C
  626. message DownloadProgress {
  627. string folder = 1;
  628. repeated FileDownloadProgressUpdate updates = 2;
  629. }
  630. message FileDownloadProgressUpdate {
  631. FileDownloadProgressUpdateType update_type = 1;
  632. string name = 2;
  633. Vector version = 3;
  634. repeated int32 block_indexes = 4;
  635. }
  636. enum FileDownloadProgressUpdateType {
  637. APPEND = 0;
  638. FORGET = 1;
  639. }
  640. .ft P
  641. .fi
  642. .UNINDENT
  643. .UNINDENT
  644. .SS Fields (DownloadProgress Message)
  645. .sp
  646. The \fBfolder\fP field represents the ID of the folder for which the update is
  647. being provided.
  648. .sp
  649. The \fBupdates\fP field is a list of progress update messages.
  650. .SS Fields (FileDownloadProgressUpdate Message)
  651. .sp
  652. The \fBupdate type\fP indicates whether the update is of type \fBappend (0)\fP
  653. (new blocks are available) or \fBforget (1)\fP (the file transfer has
  654. completed or failed).
  655. .sp
  656. The \fBname\fP field defines the file name from the global index for which
  657. this update is being sent.
  658. .sp
  659. The \fBversion\fP message defines the version of the file for which this
  660. update is being sent.
  661. .sp
  662. The \fBblock indexes\fP field is a list of positive integers, where each
  663. integer represents the index of the block in the FileInfo message Blocks
  664. array that has become available for download.
  665. .sp
  666. For example an integer with value 3 represents that the data defined in the
  667. fourth BlockInfo message of the FileInfo message of that file is now
  668. available. Please note that matching should be done on \fBname\fP AND
  669. \fBversion\fP\&. Furthermore, each update received is incremental, for example
  670. the initial update message might contain indexes 0, 1, 2, an update 5
  671. seconds later might contain indexes 3, 4, 5 which should be appended to the
  672. original list, which implies that blocks 0\-5 are currently available.
  673. .sp
  674. Block indexes MAY be added in any order. An implementation MUST NOT assume
  675. that block indexes are added in any specific order.
  676. .sp
  677. The \fBforget\fP field being set implies that previously advertised file is no
  678. longer available, therefore the list of block indexes should be truncated.
  679. .sp
  680. Messages with the \fBforget\fP field set MUST NOT have any block indexes.
  681. .sp
  682. Any update message which is being sent for a different \fBversion\fP of the
  683. same file name must be preceded with an update message for the old version
  684. of that file with the \fBforget\fP field set.
  685. .sp
  686. As a safeguard on the receiving side, the value of \fBversion\fP changing
  687. between update messages implies that the file has changed and that any
  688. indexes previously advertised are no longer available. The list of available
  689. block indexes MUST be replaced (rather than appended) with the indexes
  690. specified in this message.
  691. .SS Ping
  692. .sp
  693. The Ping message is used to determine that a connection is alive, and to
  694. keep connections alive through state tracking network elements such as
  695. firewalls and NAT gateways. A Ping message is sent every 90 seconds, if no
  696. other message has been sent in the preceding 90 seconds.
  697. .SS Protocol Buffer Schema
  698. .INDENT 0.0
  699. .INDENT 3.5
  700. .sp
  701. .nf
  702. .ft C
  703. message Ping {
  704. }
  705. .ft P
  706. .fi
  707. .UNINDENT
  708. .UNINDENT
  709. .SS Close
  710. .sp
  711. The Close message MAY be sent to indicate that the connection will be torn
  712. down due to an error condition. A Close message MUST NOT be followed by
  713. further messages.
  714. .SS Protocol Buffer Schema
  715. .INDENT 0.0
  716. .INDENT 3.5
  717. .sp
  718. .nf
  719. .ft C
  720. message Close {
  721. string reason = 1;
  722. }
  723. .ft P
  724. .fi
  725. .UNINDENT
  726. .UNINDENT
  727. .SS Fields
  728. .sp
  729. The \fBreason\fP field contains a human readable description of the error
  730. condition.
  731. .SH SHARING MODES
  732. .SS Trusted
  733. .sp
  734. Trusted mode is the default sharing mode. Updates are exchanged in both
  735. directions.
  736. .INDENT 0.0
  737. .INDENT 3.5
  738. .sp
  739. .nf
  740. .ft C
  741. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  742. | | \-\-\-\-\-\-\-\-\-\-\-> / \e
  743. | Device | | Cluster |
  744. | | <\-\-\-\-\-\-\-\-\-\-\- \e /
  745. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates \e\-\-\-\-\-\-\-\-\-/
  746. .ft P
  747. .fi
  748. .UNINDENT
  749. .UNINDENT
  750. .SS Send Only
  751. .sp
  752. In send only mode, a device does not apply any updates from the cluster, but
  753. publishes changes of its local folder to the cluster as usual.
  754. .INDENT 0.0
  755. .INDENT 3.5
  756. .sp
  757. .nf
  758. .ft C
  759. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  760. | | \-\-\-\-\-\-\-\-\-\-\-> / \e
  761. | Device | | Cluster |
  762. | | \e /
  763. +\-\-\-\-\-\-\-\-\-\-\-\-+ \e\-\-\-\-\-\-\-\-\-/
  764. .ft P
  765. .fi
  766. .UNINDENT
  767. .UNINDENT
  768. .SS Receive Only
  769. .sp
  770. In receive only mode, a device does not send any updates to the cluster, but
  771. accepts changes to its local folder from the cluster as usual.
  772. .INDENT 0.0
  773. .INDENT 3.5
  774. .sp
  775. .nf
  776. .ft C
  777. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  778. | | <\-\-\-\-\-\-\-\-\-\-\- / \e
  779. | Device | | Cluster |
  780. | | \e /
  781. +\-\-\-\-\-\-\-\-\-\-\-\-+ \e\-\-\-\-\-\-\-\-\-/
  782. .ft P
  783. .fi
  784. .UNINDENT
  785. .UNINDENT
  786. .SH DELTA INDEX EXCHANGE
  787. .sp
  788. Index data must be exchanged whenever two devices connect so that one knows
  789. the files available on the other. In the most basic case this happens by way
  790. of sending an \fBIndex\fP message followed by one or more \fBIndex Update\fP
  791. messages. Any previous index data known for a remote device is removed and
  792. replaced with the new index data received in an \fBIndex\fP message, while the
  793. contents of an \fBIndex Update\fP message is simply added to the existing
  794. index data.
  795. .sp
  796. For situations with large indexes or frequent reconnects this can be quite
  797. inefficient. A mechanism can then be used to retain index data between
  798. connections and only transmit any changes since that data on connection
  799. start. This is called “delta indexes”. To enable this mechanism the
  800. \fBsequence\fP and \fBindex ID\fP fields are used.
  801. .INDENT 0.0
  802. .TP
  803. .B Sequence:
  804. Each index item (i.e., file, directory or symlink) has a sequence number
  805. field. It contains the value of a counter at the time the index item was
  806. updated. The counter increments by one for each change. That is, as files
  807. are scanned and added to the index they get assigned sequence numbers
  808. 1, 2, 3 and so on. The next file to be changed or detected gets sequence
  809. number 4, and future updates continue in the same fashion.
  810. .TP
  811. .B Index ID:
  812. Each folder has an Index ID. This is a 64 bit random identifier set at
  813. index creation time.
  814. .UNINDENT
  815. .sp
  816. Given the above, we know that the tuple {index ID, maximum sequence number}
  817. uniquely identifies a point in time of a given index. Any further changes
  818. will increase the sequence number of some item, and thus the maximum
  819. sequence number for the index itself. Should the index be reset or removed
  820. (i.e., the sequence number reset to zero), a new index ID must be generated.
  821. .sp
  822. By letting a device know the {index ID, maximum sequence number} we have for
  823. their index data, that device can arrange to only transmit \fBIndex Update\fP
  824. messages for items with a higher sequence number. This is the delta index
  825. mechanism.
  826. .sp
  827. The index ID and maximum sequence number known for each device is
  828. transmitted in the \fBCluster Config\fP message at connection start.
  829. .sp
  830. For this mechanism to be reliable it is essential that outgoing index
  831. information is ordered by increasing sequence number. Devices announcing a
  832. non\-zero index ID in the \fBCluster Config\fP message MUST send all index data
  833. ordered by increasing sequence number. Devices not intending to participate
  834. in delta index exchange MUST send a zero index ID or, equivalently, not send
  835. the \fBindex_id\fP attribute at all.
  836. .SH MESSAGE LIMITS
  837. .sp
  838. An implementation MAY impose reasonable limits on the length of messages and
  839. message fields to aid robustness in the face of corruption or broken
  840. implementations. An implementation should strive to keep messages short
  841. and to the point, favouring more and smaller messages over fewer and larger.
  842. For example, favour a smaller Index message followed by one or more Index
  843. Update messages rather than sending a very large Index message.
  844. .sp
  845. The Syncthing implementation imposes a hard limit of 500,000,000 bytes on
  846. all messages. Attempting to send or receive a larger message will result in
  847. a connection close. This size was chosen to accommodate Index messages
  848. containing a large block list. It’s intended that the limit may be further
  849. reduced in a future protocol update supporting variable block sizes (and
  850. thus shorter block lists for large files).
  851. .SH SELECTION OF BLOCK SIZE
  852. .sp
  853. The desired block size for any given file is the smallest block size that
  854. results in fewer than 2000 blocks, or the maximum block size for larger
  855. files. This rule results in the following table of block sizes per file
  856. size:
  857. .TS
  858. center;
  859. |l|l|.
  860. _
  861. T{
  862. File Size
  863. T} T{
  864. Block Size
  865. T}
  866. _
  867. T{
  868. 0 \- 250 MiB
  869. T} T{
  870. 128 KiB
  871. T}
  872. _
  873. T{
  874. 250 MiB \- 500 MiB
  875. T} T{
  876. 256 KiB
  877. T}
  878. _
  879. T{
  880. 500 MiB \- 1 GiB
  881. T} T{
  882. 512 KiB
  883. T}
  884. _
  885. T{
  886. 1 GiB \- 2 GiB
  887. T} T{
  888. 1 MiB
  889. T}
  890. _
  891. T{
  892. 2 GiB \- 4 GiB
  893. T} T{
  894. 2 MiB
  895. T}
  896. _
  897. T{
  898. 4 GiB \- 8 GiB
  899. T} T{
  900. 4 MiB
  901. T}
  902. _
  903. T{
  904. 8 GiB \- 16 GiB
  905. T} T{
  906. 8 MiB
  907. T}
  908. _
  909. T{
  910. 16 GiB \- up
  911. T} T{
  912. 16 MiB
  913. T}
  914. _
  915. .TE
  916. .sp
  917. An implementation MAY deviate from the block size rule when there is good
  918. reason to do so. For example, if a file has been indexed at a certain block
  919. size and grows beyond 2000 blocks it may be retained at the current block
  920. size for practical reasons. When there is no overriding reason to the
  921. contrary, such as when indexing a new file for the first time, the block
  922. size rule above SHOULD be followed.
  923. .sp
  924. An implementation MUST therefore accept files with a block size differing
  925. from the above rule. This does not mean that arbitrary block sizes are
  926. allowed. The block size used MUST be exactly one of the power\-of\-two block
  927. sizes listed in the table above.
  928. .SH EXAMPLE EXCHANGE
  929. .TS
  930. center;
  931. |l|l|l|.
  932. _
  933. T{
  934. #
  935. T} T{
  936. A
  937. T} T{
  938. B
  939. T}
  940. _
  941. T{
  942. 1
  943. T} T{
  944. ClusterConfiguration\->
  945. T} T{
  946. <\-ClusterConfiguration
  947. T}
  948. _
  949. T{
  950. 2
  951. T} T{
  952. Index\->
  953. T} T{
  954. <\-Index
  955. T}
  956. _
  957. T{
  958. 3
  959. T} T{
  960. IndexUpdate\->
  961. T} T{
  962. <\-IndexUpdate
  963. T}
  964. _
  965. T{
  966. 4
  967. T} T{
  968. IndexUpdate\->
  969. T} T{
  970. T}
  971. _
  972. T{
  973. 5
  974. T} T{
  975. Request\->
  976. T} T{
  977. T}
  978. _
  979. T{
  980. 6
  981. T} T{
  982. Request\->
  983. T} T{
  984. T}
  985. _
  986. T{
  987. 7
  988. T} T{
  989. Request\->
  990. T} T{
  991. T}
  992. _
  993. T{
  994. 8
  995. T} T{
  996. Request\->
  997. T} T{
  998. T}
  999. _
  1000. T{
  1001. 9
  1002. T} T{
  1003. T} T{
  1004. <\-Response
  1005. T}
  1006. _
  1007. T{
  1008. 10
  1009. T} T{
  1010. T} T{
  1011. <\-Response
  1012. T}
  1013. _
  1014. T{
  1015. 11
  1016. T} T{
  1017. T} T{
  1018. <\-Response
  1019. T}
  1020. _
  1021. T{
  1022. 12
  1023. T} T{
  1024. T} T{
  1025. <\-Response
  1026. T}
  1027. _
  1028. T{
  1029. 13
  1030. T} T{
  1031. Index Update\->
  1032. T} T{
  1033. T}
  1034. _
  1035. T{
  1036. T} T{
  1037. T} T{
  1038. T}
  1039. _
  1040. T{
  1041. 14
  1042. T} T{
  1043. T} T{
  1044. <\-Ping
  1045. T}
  1046. _
  1047. T{
  1048. 15
  1049. T} T{
  1050. Ping\->
  1051. T} T{
  1052. T}
  1053. _
  1054. .TE
  1055. .sp
  1056. The connection is established and at 1. both peers send ClusterConfiguration
  1057. messages and then Index records. The Index records are received and both
  1058. peers recompute their knowledge of the data in the cluster. In this example,
  1059. peer A has four missing or outdated blocks. At 5 through 8 peer A sends
  1060. requests for these blocks. The requests are received by peer B, who
  1061. retrieves the data from the folder and transmits Response records (9 through
  1062. 12). Device A updates their folder contents and transmits an Index Update
  1063. message (13). Both peers enter idle state after 13. At some later time 14,
  1064. the ping timer on device B expires and a Ping message is sent. The same
  1065. process occurs for device A at 15.
  1066. .SH EXAMPLES OF STRONG CIPHER SUITES
  1067. .TS
  1068. center;
  1069. |l|l|l|.
  1070. _
  1071. T{
  1072. ID
  1073. T} T{
  1074. Name
  1075. T} T{
  1076. Description
  1077. T}
  1078. _
  1079. T{
  1080. 0x009F
  1081. T} T{
  1082. DHE\-RSA\-AES256\-GCM\-SHA384
  1083. T} T{
  1084. TLSv1.2 DH RSA AESGCM(256) AEAD
  1085. T}
  1086. _
  1087. T{
  1088. 0x006B
  1089. T} T{
  1090. DHE\-RSA\-AES256\-SHA256
  1091. T} T{
  1092. TLSv1.2 DH RSA AES(256) SHA256
  1093. T}
  1094. _
  1095. T{
  1096. 0xC030
  1097. T} T{
  1098. ECDHE\-RSA\-AES256\-GCM\-SHA384
  1099. T} T{
  1100. TLSv1.2 ECDH RSA AESGCM(256) AEAD
  1101. T}
  1102. _
  1103. T{
  1104. 0xC028
  1105. T} T{
  1106. ECDHE\-RSA\-AES256\-SHA384
  1107. T} T{
  1108. TLSv1.2 ECDH RSA AES(256) SHA384
  1109. T}
  1110. _
  1111. T{
  1112. 0x009E
  1113. T} T{
  1114. DHE\-RSA\-AES128\-GCM\-SHA256
  1115. T} T{
  1116. TLSv1.2 DH RSA AESGCM(128) AEAD
  1117. T}
  1118. _
  1119. T{
  1120. 0x0067
  1121. T} T{
  1122. DHE\-RSA\-AES128\-SHA256
  1123. T} T{
  1124. TLSv1.2 DH RSA AES(128) SHA256
  1125. T}
  1126. _
  1127. T{
  1128. 0xC02F
  1129. T} T{
  1130. ECDHE\-RSA\-AES128\-GCM\-SHA256
  1131. T} T{
  1132. TLSv1.2 ECDH RSA AESGCM(128) AEAD
  1133. T}
  1134. _
  1135. T{
  1136. 0xC027
  1137. T} T{
  1138. ECDHE\-RSA\-AES128\-SHA256
  1139. T} T{
  1140. TLSv1.2 ECDH RSA AES(128) SHA256
  1141. T}
  1142. _
  1143. .TE
  1144. .SH AUTHOR
  1145. The Syncthing Authors
  1146. .SH COPYRIGHT
  1147. 2014-2019, The Syncthing Authors
  1148. .\" Generated by docutils manpage writer.
  1149. .