syncthing-bep.7 31 KB

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