syncthing-bep.7 30 KB

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