syncthing-bep.7 30 KB

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