syncthing-bep.7 31 KB

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