syncthing-bep.7 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439
  1. .\" Man page generated from reStructuredText.
  2. .
  3. .TH "SYNCTHING-BEP" "7" "January 30, 2016" "v0.12" "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. | TCP |
  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 be TCP.
  94. .SH MESSAGES
  95. .sp
  96. Every message starts with one 32 bit word indicating the message version, type
  97. and ID, followed by the length of the message. The header is in network byte
  98. order, i.e. big endian. In this document, in diagrams and text, "bit 0" refers
  99. to the \fImost significant\fP bit of a word; "bit 31" is thus the least
  100. significant bit of a 32 bit word.
  101. .INDENT 0.0
  102. .INDENT 3.5
  103. .sp
  104. .nf
  105. .ft C
  106. 0 1 2 3
  107. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  108. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  109. | Ver | Message ID | Type | Reserved |C|
  110. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  111. | Length |
  112. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  113. .ft P
  114. .fi
  115. .UNINDENT
  116. .UNINDENT
  117. .sp
  118. For BEP v1 the \fBVersion\fP field is set to zero. Future versions with
  119. incompatible message formats will increment the Version field. A message
  120. with an unknown version is a protocol error and MUST result in the
  121. connection being terminated. A client supporting multiple versions MAY
  122. retry with a different protocol version upon disconnection.
  123. .sp
  124. The \fBMessage ID\fP is set to a unique value for each transmitted Request
  125. message. In Response messages it is set to the Message ID of the corresponding
  126. Request message. The uniqueness requirement implies that no more than 4096
  127. request messages may be outstanding at any given moment. For message types
  128. that do not have a corresponding response (Cluster Configuration, Index, etc.)
  129. the Message ID field is irrelevant and SHOULD be set to zero.
  130. .sp
  131. The \fBType\fP field indicates the type of data following the message header
  132. and is one of the integers defined below. A message of an unknown type
  133. is a protocol error and MUST result in the connection being terminated.
  134. .sp
  135. The \fBCompression\fP bit "C" indicates the compression used for the message.
  136. .sp
  137. For C=0:
  138. .INDENT 0.0
  139. .IP \(bu 2
  140. The Length field contains the length, in bytes, of the uncompressed
  141. message data.
  142. .IP \(bu 2
  143. The message is not compressed.
  144. .UNINDENT
  145. .sp
  146. For C=1:
  147. .INDENT 0.0
  148. .IP \(bu 2
  149. The Length field contains the length, in bytes, of the compressed
  150. message data plus a four byte uncompressed length field.
  151. .IP \(bu 2
  152. The compressed message data is preceeded by a 32 bit field denoting
  153. the length of the uncompressed message.
  154. .IP \(bu 2
  155. The message data is compressed using the LZ4 format and algorithm
  156. described in \fI\%http://www.lz4.org/\fP\&.
  157. .UNINDENT
  158. .sp
  159. All data within the message (post decompression, if compression is in
  160. use) MUST be in XDR (RFC 1014) encoding. All fields shorter than 32 bits
  161. and all variable length data MUST be padded to a multiple of 32 bits.
  162. The actual data types in use by BEP, in XDR naming convention, are the
  163. following:
  164. .INDENT 0.0
  165. .TP
  166. .B (unsigned) int:
  167. (unsigned) 32 bit integer
  168. .TP
  169. .B (unsigned) hyper:
  170. (unsigned) 64 bit integer
  171. .TP
  172. .B opaque<>
  173. variable length opaque data
  174. .TP
  175. .B string<>
  176. variable length string
  177. .UNINDENT
  178. .sp
  179. The transmitted length of string and opaque data is the length of actual
  180. data, excluding any added padding. The encoding of opaque<> and string<>
  181. are identical, the distinction being solely one of interpretation.
  182. Opaque data should not be interpreted but can be compared bytewise to
  183. other opaque data. All strings MUST use the Unicode UTF\-8 encoding,
  184. normalization form C.
  185. .SS Cluster Config (Type = 0)
  186. .sp
  187. This informational message provides information about the cluster
  188. configuration as it pertains to the current connection. A Cluster Config
  189. message MUST be the first message sent on a BEP connection. Additional
  190. Cluster Config messages MUST NOT be sent after the initial exchange.
  191. .SS Graphical Representation
  192. .INDENT 0.0
  193. .INDENT 3.5
  194. .sp
  195. .nf
  196. .ft C
  197. ClusterConfigMessage Structure:
  198. 0 1 2 3
  199. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  200. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  201. | Length of Device Name |
  202. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  203. / /
  204. \e Device Name (variable length) \e
  205. / /
  206. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  207. | Length of Client Name |
  208. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  209. / /
  210. \e Client Name (variable length) \e
  211. / /
  212. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  213. | Length of Client Version |
  214. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  215. / /
  216. \e Client Version (variable length) \e
  217. / /
  218. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  219. | Number of Folders |
  220. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  221. / /
  222. \e Zero or more Folder Structures \e
  223. / /
  224. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  225. | Number of Options |
  226. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  227. / /
  228. \e Zero or more Option Structures \e
  229. / /
  230. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  231. Folder Structure:
  232. 0 1 2 3
  233. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  234. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  235. | Length of ID |
  236. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  237. / /
  238. \e ID (variable length) \e
  239. / /
  240. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  241. | Number of Devices |
  242. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  243. / /
  244. \e Zero or more Device Structures \e
  245. / /
  246. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  247. | Flags |
  248. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  249. | Number of Options |
  250. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  251. / /
  252. \e Zero or more Option Structures \e
  253. / /
  254. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  255. Device Structure:
  256. 0 1 2 3
  257. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  258. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  259. | Length of ID |
  260. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  261. / /
  262. \e ID (variable length) \e
  263. / /
  264. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  265. | Length of Name |
  266. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  267. / /
  268. \e Name (variable length) \e
  269. / /
  270. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  271. | Number of Addresses |
  272. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  273. | Length of Address |
  274. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  275. / /
  276. \e Address (variable length) \e
  277. / /
  278. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  279. | Compression |
  280. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  281. | Length of Cert Name |
  282. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  283. / /
  284. \e Cert Name (variable length) \e
  285. / /
  286. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  287. | |
  288. + Max Local Version (64 bits) +
  289. | |
  290. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  291. | Flags |
  292. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  293. | Number of Options |
  294. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  295. / /
  296. \e Zero or more Option Structures \e
  297. / /
  298. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  299. Option Structure:
  300. 0 1 2 3
  301. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  302. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  303. | Length of Key |
  304. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  305. / /
  306. \e Key (variable length) \e
  307. / /
  308. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  309. | Length of Value |
  310. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  311. / /
  312. \e Value (variable length) \e
  313. / /
  314. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  315. .ft P
  316. .fi
  317. .UNINDENT
  318. .UNINDENT
  319. .SS Fields (ClusterConfigMessage)
  320. .sp
  321. The \fBDevice Name\fP is a human readable (configured or auto detected) device
  322. name or host name, for the sending device.
  323. .sp
  324. The \fBClient Name\fP and \fBClient Version\fP identifies the implementation. The
  325. values SHOULD be simple strings identifying the implementation name, as a
  326. user would expect to see it, and the version string in the same manner. An
  327. example Client Name is "syncthing" and an example Client Version is "v0.7.2".
  328. The Client Version field SHOULD follow the patterns laid out in the \fI\%Semantic
  329. Versioning\fP <\fBhttp://semver.org/\fP> standard.
  330. .sp
  331. The \fBFolders\fP field contains the list of folders that will be synchronized
  332. over the current connection.
  333. .sp
  334. The \fBOptions\fP field is a list of options that apply to the current
  335. connection. The options are used in an implementation specific manner. The
  336. options list is conceptually a map of keys to values, although it is
  337. transmitted in the form of a list of key and value pairs, both of string type.
  338. Key ID:s are implementation specific. An implementation MUST ignore unknown
  339. keys. An implementation MAY impose limits on the length keys and values. The
  340. options list may be used to inform devices of relevant local configuration
  341. options such as rate limiting or make recommendations about request
  342. parallelism, device priorities, etc. An empty options list is valid for
  343. devices not having any such information to share. Devices MAY NOT make any
  344. assumptions about peers acting in a specific manner as a result of sent
  345. options.
  346. .SS Fields (Folder Structure)
  347. .sp
  348. The \fBID\fP field contains the folder ID, as a human readable string.
  349. .sp
  350. The \fBDevices\fP field is list of devices participating in sharing this folder.
  351. .sp
  352. The \fBFlags\fP field contains flags that affect the behavior of the folder. The
  353. folder Flags field contains the following single bit flags:
  354. .INDENT 0.0
  355. .INDENT 3.5
  356. .sp
  357. .nf
  358. .ft C
  359. 0 1 2 3
  360. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  361. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  362. | Reserved |D|P|R|
  363. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  364. .ft P
  365. .fi
  366. .UNINDENT
  367. .UNINDENT
  368. .INDENT 0.0
  369. .TP
  370. .B Bit 31 ("R", Read Only)
  371. is set for folders that the device will accept no updates from the network
  372. for.
  373. .TP
  374. .B Bit 30 ("P", Ignore Permissions)
  375. is set for folders that the device will not accept or announce file
  376. permissions for.
  377. .TP
  378. .B Bit 29 ("D", Ignore Deletes)
  379. is set for folders that the device will ignore deletes for.
  380. .UNINDENT
  381. .sp
  382. The \fBOptions\fP field contains a list of options that apply to the folder.
  383. .SS Fields (Device Structure)
  384. .sp
  385. The device \fBID\fP field is a 32 byte number that uniquely identifies the
  386. device. For instance, the reference implementation uses the SHA\-256 of the
  387. device X.509 certificate.
  388. .sp
  389. The \fBName\fP field is a human readable name assigned to the described device
  390. by the sending device. It MAY be empty and it need not be unique.
  391. .sp
  392. The list of \fBAddressess\fP is that used by the sending device to connect to
  393. the described device.
  394. .sp
  395. The \fBCompression\fP field indicates the compression mode in use for this
  396. device and folder. The following values are valid:
  397. .INDENT 0.0
  398. .TP
  399. .B 0
  400. Compress metadata. This enables compression of metadata messages such as Index.
  401. .TP
  402. .B 1
  403. Compression disabled. No compression is used on any message.
  404. .TP
  405. .B 2
  406. Compress always. Metadata messages as well as Response messages are compressed.
  407. .UNINDENT
  408. .sp
  409. The \fBCert Name\fP field indicates the expected certificate name for this
  410. device. It is commonly blank, indicating to use the implementation default.
  411. .sp
  412. The \fBMax Local Version\fP field contains the highest local file
  413. version number of the files already known to be in the index sent by
  414. this device. If nothing is known about the index of a given device, this
  415. field MUST be set to zero. When receiving a Cluster Config message with
  416. a non\-zero Max Local Version for the local device ID, a device MAY elect
  417. to send an Index Update message containing only files with higher local
  418. version numbers in place of the initial Index message.
  419. .sp
  420. The \fBFlags\fP field indicates the sharing mode of the folder and other device
  421. & folder specific settings. See the discussion on Sharing Modes. The Device
  422. Flags field contains the following single bit flags:
  423. .INDENT 0.0
  424. .INDENT 3.5
  425. .sp
  426. .nf
  427. .ft C
  428. 0 1 2 3
  429. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  430. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  431. | Reserved |Pri| Reserved |I|R|T|
  432. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  433. .ft P
  434. .fi
  435. .UNINDENT
  436. .UNINDENT
  437. .INDENT 0.0
  438. .TP
  439. .B Bit 31 ("T", Trusted)
  440. is set for devices that participate in trusted
  441. mode.
  442. .TP
  443. .B Bit 30 ("R", Read Only)
  444. is set for devices that participate in read
  445. only mode.
  446. .TP
  447. .B Bit 29 ("I", Introducer)
  448. is set for devices that are trusted as
  449. cluster introducers.
  450. .TP
  451. .B Bits 16 through 28
  452. are reserved and MUST be set to zero.
  453. .TP
  454. .B Bits 14\-15 ("Pri)
  455. indicate the device\(aqs upload priority for this
  456. folder. Possible values are:
  457. .INDENT 7.0
  458. .TP
  459. .B 00
  460. The default. Normal priority.
  461. .TP
  462. .B 01
  463. High priority. Other devices SHOULD favour requesting files
  464. from this device over devices with normal or low priority.
  465. .TP
  466. .B 10
  467. Low priority. Other devices SHOULD avoid requesting files from
  468. this device when they are available from other devices.
  469. .TP
  470. .B 11
  471. Sharing disabled. Other devices SHOULD NOT request files from
  472. this device.
  473. .UNINDENT
  474. .TP
  475. .B Bits 0 through 14
  476. are reserved and MUST be set to zero.
  477. .UNINDENT
  478. .sp
  479. Exactly one of the T and R bits MUST be set.
  480. .sp
  481. The \fBOptions\fP field contains a list of options that apply to the device.
  482. .SS XDR
  483. .INDENT 0.0
  484. .INDENT 3.5
  485. .sp
  486. .nf
  487. .ft C
  488. struct ClusterConfigMessage {
  489. string DeviceName<64>;
  490. string ClientName<64>;
  491. string ClientVersion<64>;
  492. Folder Folders<1000000>;
  493. Option Options<64>;
  494. }
  495. struct Folder {
  496. string ID<256>;
  497. Device Devices<1000000>;
  498. unsigned int Flags;
  499. Option Options<64>;
  500. }
  501. struct Device {
  502. opaque ID<32>;
  503. string Name<64>;
  504. string Addresses<64>;
  505. unsigned int Compression;
  506. string CertName<64>;
  507. hyper MaxLocalVersion;
  508. unsigned int Flags;
  509. Option Options<64>;
  510. }
  511. struct Option {
  512. string Key<64>;
  513. string Value<1024>;
  514. }
  515. .ft P
  516. .fi
  517. .UNINDENT
  518. .UNINDENT
  519. .SS Index (Type = 1) and Index Update (Type = 6)
  520. .sp
  521. The Index and Index Update messages define the contents of the senders
  522. folder. An Index message represents the full contents of the folder and
  523. thus supersedes any previous index. An Index Update amends an existing
  524. index with new information, not affecting any entries not included in
  525. the message. An Index Update MAY NOT be sent unless preceded by an
  526. Index, unless a non\-zero Max Local Version has been announced for the
  527. given folder by the peer device.
  528. .SS Graphical Representation
  529. .INDENT 0.0
  530. .INDENT 3.5
  531. .sp
  532. .nf
  533. .ft C
  534. IndexMessage Structure:
  535. 0 1 2 3
  536. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  537. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  538. | Length of Folder |
  539. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  540. / /
  541. \e Folder (variable length) \e
  542. / /
  543. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  544. | Number of Files |
  545. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  546. / /
  547. \e Zero or more FileInfo Structures \e
  548. / /
  549. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  550. | Flags |
  551. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  552. | Number of Options |
  553. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  554. / /
  555. \e Zero or more Option Structures \e
  556. / /
  557. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  558. FileInfo Structure:
  559. 0 1 2 3
  560. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  561. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  562. | Length of Name |
  563. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  564. / /
  565. \e Name (variable length) \e
  566. / /
  567. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  568. | Flags |
  569. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  570. | |
  571. + Modified (64 bits) +
  572. | |
  573. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  574. / /
  575. \e Version (variable length) \e
  576. / /
  577. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  578. | |
  579. + Local Version (64 bits) +
  580. | |
  581. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  582. | Number of Blocks |
  583. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  584. / /
  585. \e Zero or more BlockInfo Structures \e
  586. / /
  587. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  588. Vector Structure:
  589. 0 1 2 3
  590. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  591. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  592. | Number of Counters |
  593. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  594. / /
  595. \e Zero or more Counter Structures \e
  596. / /
  597. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  598. Counter Structure:
  599. 0 1 2 3
  600. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  601. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  602. | |
  603. + ID (64 bits) +
  604. | |
  605. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  606. | |
  607. + Value (64 bits) +
  608. | |
  609. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  610. BlockInfo Structure:
  611. 0 1 2 3
  612. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  613. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  614. | Size |
  615. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  616. | Length of Hash |
  617. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  618. / /
  619. \e Hash (variable length) \e
  620. / /
  621. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  622. .ft P
  623. .fi
  624. .UNINDENT
  625. .UNINDENT
  626. .SS Fields (Index Message)
  627. .sp
  628. The \fBFolder\fP field identifies the folder that the index message pertains to.
  629. .sp
  630. \fBFiles\fP
  631. .sp
  632. The \fBFlags\fP field is reserved for future use and MUST currently be set to
  633. zero.
  634. .sp
  635. The \fBOptions\fP list is implementation defined and as described in the
  636. ClusterConfig message section.
  637. .SS Fields (FileInfo Structure)
  638. .sp
  639. The \fBName\fP is the file name path relative to the folder root. Like all
  640. strings in BEP, the Name is always in UTF\-8 NFC regardless of operating
  641. system or file system specific conventions. The Name field uses the
  642. slash character ("/") as path separator, regardless of the
  643. implementation\(aqs operating system conventions. The combination of Folder
  644. and Name uniquely identifies each file in a cluster.
  645. .sp
  646. The \fBFlags\fP field is made up of the following single bit flags:
  647. .INDENT 0.0
  648. .INDENT 3.5
  649. .sp
  650. .nf
  651. .ft C
  652. 0 1 2 3
  653. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  654. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  655. | Reserved |U|S|P|I|D| Unix Perm. & Mode |
  656. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  657. .ft P
  658. .fi
  659. .UNINDENT
  660. .UNINDENT
  661. .INDENT 0.0
  662. .TP
  663. .B The lower 12 bits
  664. hold the common Unix permission and mode bits. An
  665. implementation MAY ignore or interpret these as is suitable on the
  666. host operating system.
  667. .TP
  668. .B Bit 19 ("D")
  669. is set when the file has been deleted. The block list
  670. SHALL be of length zero and the modification time indicates the time
  671. of deletion or, if the time of deletion is not reliably determinable,
  672. the last known modification time.
  673. .TP
  674. .B Bit 18 ("I")
  675. is set when the file is invalid and unavailable for
  676. synchronization. A peer MAY set this bit to indicate that it can
  677. temporarily not serve data for the file.
  678. .TP
  679. .B Bit 17 ("P")
  680. is set when there is no permission information for the
  681. file. This is the case when it originates on a file system which
  682. does not support permissions. Changes to only permission bits SHOULD
  683. be disregarded on files with this bit set. The permissions bits MUST
  684. be set to the octal value 0666.
  685. .TP
  686. .B Bit 16 ("S")
  687. is set when the file is a symbolic link. The block list
  688. SHALL be of one or more blocks since the target of the symlink is
  689. stored within the blocks of the file.
  690. .TP
  691. .B Bit 15 ("U")
  692. is set when the symbolic links target does not exist. On
  693. systems where symbolic links have types, this bit being means that
  694. the default file symlink SHALL be used. If this bit is unset bit 19
  695. will decide the type of symlink to be created.
  696. .TP
  697. .B Bit 0 through 14
  698. are reserved for future use and SHALL be set to
  699. zero.
  700. .UNINDENT
  701. .sp
  702. The \fBModified\fP time is expressed as the number of seconds since the Unix
  703. Epoch (1970\-01\-01 00:00:00 UTC).
  704. .sp
  705. The \fBVersion\fP field is a version vector describing the updates performed
  706. to a file by all members in the cluster. Each counter in the version
  707. vector is an ID\-Value tuple. The ID is used the first 64 bits of the
  708. device ID. The Value is a simple incrementing counter, starting at zero.
  709. The combination of Folder, Name and Version uniquely identifies the
  710. contents of a file at a given point in time.
  711. .sp
  712. The \fBLocal Version\fP field is the value of a device local monotonic clock
  713. at the time of last local database update to a file. The clock ticks on
  714. every local database update.
  715. .sp
  716. The \fBBlocks\fP list contains the size and hash for each block in the file.
  717. Each block represents a 128 KiB slice of the file, except for the last
  718. block which may represent a smaller amount of data.
  719. .sp
  720. The hash algorithm is implied by the \fBHash\fP length. Currently, the hash
  721. MUST be 32 bytes long and computed by SHA256.
  722. .SS XDR
  723. .INDENT 0.0
  724. .INDENT 3.5
  725. .sp
  726. .nf
  727. .ft C
  728. struct IndexMessage {
  729. string Folder<256>;
  730. FileInfo Files<1000000>;
  731. unsigned int Flags;
  732. Option Options<64>;
  733. }
  734. struct FileInfo {
  735. string Name<8192>;
  736. unsigned int Flags;
  737. hyper Modified;
  738. Vector Version;
  739. hyper LocalVersion;
  740. BlockInfo Blocks<1000000>;
  741. }
  742. struct Vector {
  743. Counter Counters<>
  744. }
  745. struct Counter {
  746. unsigned hyper ID
  747. unsigned hyper Value
  748. }
  749. struct BlockInfo {
  750. unsigned int Size;
  751. opaque Hash<64>;
  752. }
  753. .ft P
  754. .fi
  755. .UNINDENT
  756. .UNINDENT
  757. .SS Request (Type = 2)
  758. .sp
  759. The Request message expresses the desire to receive a data block
  760. corresponding to a part of a certain file in the peer\(aqs folder.
  761. .SS Graphical Representation
  762. .INDENT 0.0
  763. .INDENT 3.5
  764. .sp
  765. .nf
  766. .ft C
  767. RequestMessage Structure:
  768. 0 1 2 3
  769. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  770. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  771. | Length of Folder |
  772. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  773. / /
  774. \e Folder (variable length) \e
  775. / /
  776. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  777. | Length of Name |
  778. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  779. / /
  780. \e Name (variable length) \e
  781. / /
  782. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  783. | |
  784. + Offset (64 bits) +
  785. | |
  786. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  787. | Size |
  788. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  789. | Length of Hash |
  790. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  791. / /
  792. \e Hash (variable length) \e
  793. / /
  794. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  795. | Flags |
  796. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  797. | Number of Options |
  798. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  799. / /
  800. \e Zero or more Option Structures \e
  801. / /
  802. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  803. .ft P
  804. .fi
  805. .UNINDENT
  806. .UNINDENT
  807. .SS Fields
  808. .sp
  809. The Folder and Name fields are as documented for the Index message. The
  810. Offset and Size fields specify the region of the file to be transferred.
  811. This SHOULD equate to exactly one block as seen in an Index message.
  812. .sp
  813. The Hash field MAY be set to the expected hash value of the block, or
  814. may be left empty (zero length). If set, the other device SHOULD ensure
  815. that the transmitted block matches the requested hash. The other device
  816. MAY reuse a block from a different file and offset having the same size
  817. and hash, if one exists.
  818. .sp
  819. The Flags field is reserved for future use and MUST currently be set to
  820. zero. The Options list is implementation defined and as described in the
  821. ClusterConfig message section.
  822. .SS XDR
  823. .INDENT 0.0
  824. .INDENT 3.5
  825. .sp
  826. .nf
  827. .ft C
  828. struct RequestMessage {
  829. string Folder<64>;
  830. string Name<8192>;
  831. hyper Offset;
  832. int Size;
  833. opaque Hash<64>;
  834. unsigned int Flags;
  835. Option Options<64>;
  836. }
  837. .ft P
  838. .fi
  839. .UNINDENT
  840. .UNINDENT
  841. .SS Response (Type = 3)
  842. .sp
  843. The Response message is sent in response to a Request message.
  844. .SS Graphical Representation
  845. .sp
  846. ResponseMessage Structure:
  847. .INDENT 0.0
  848. .INDENT 3.5
  849. .sp
  850. .nf
  851. .ft C
  852. 0 1 2 3
  853. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  854. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  855. | Length of Data |
  856. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  857. / /
  858. \e Data (variable length) \e
  859. / /
  860. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  861. | Code |
  862. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  863. .ft P
  864. .fi
  865. .UNINDENT
  866. .UNINDENT
  867. .SS Fields
  868. .sp
  869. The \fBData\fP field contains either a full 128 KiB block, a shorter block in
  870. the case of the last block in a file, or is empty (zero length) if the
  871. requested block is not available.
  872. .sp
  873. The \fBCode\fP field contains an error code describing the reason a Request
  874. could not be fulfilled, in the case where a zero length Data was
  875. returned. The following values are defined:
  876. .INDENT 0.0
  877. .TP
  878. .B 0
  879. No Error (Data should be present)
  880. .TP
  881. .B 1
  882. Generic Error
  883. .TP
  884. .B 2
  885. No Such File (the requested file does not exist, or the offset is
  886. outside the acceptable range for the file)
  887. .TP
  888. .B 3
  889. Invalid (file exists but has invalid bit set or is otherwise
  890. unavailable)
  891. .UNINDENT
  892. .SS XDR
  893. .INDENT 0.0
  894. .INDENT 3.5
  895. .sp
  896. .nf
  897. .ft C
  898. struct ResponseMessage {
  899. opaque Data<>;
  900. int Code;
  901. }
  902. .ft P
  903. .fi
  904. .UNINDENT
  905. .UNINDENT
  906. .SS Ping (Type = 4)
  907. .sp
  908. The Ping message is used to determine that a connection is alive, and to keep
  909. connections alive through state tracking network elements such as firewalls
  910. and NAT gateways. The Ping message has no contents. A Ping message is sent
  911. every 90 seconds, if no other message has been sent in the preceding 90
  912. seconds.
  913. .SS Close (Type = 7)
  914. .sp
  915. The Close message MAY be sent to indicate that the connection will be
  916. torn down due to an error condition. A Close message MUST NOT be
  917. followed by further messages.
  918. .SS Graphical Representation
  919. .INDENT 0.0
  920. .INDENT 3.5
  921. .sp
  922. .nf
  923. .ft C
  924. CloseMessage Structure:
  925. 0 1 2 3
  926. 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  927. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  928. | Length of Reason |
  929. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  930. / /
  931. \e Reason (variable length) \e
  932. / /
  933. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  934. | Code |
  935. +\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+\-+
  936. .ft P
  937. .fi
  938. .UNINDENT
  939. .UNINDENT
  940. .SS Fields
  941. .sp
  942. The \fBReason\fP field contains a human description of the error condition,
  943. suitable for consumption by a human. The \fBCode\fP field is for a machine
  944. readable error code. Codes are reserved for future use and MUST
  945. currently be set to zero.
  946. .INDENT 0.0
  947. .INDENT 3.5
  948. .sp
  949. .nf
  950. .ft C
  951. struct CloseMessage {
  952. string Reason<1024>;
  953. int Code;
  954. }
  955. .ft P
  956. .fi
  957. .UNINDENT
  958. .UNINDENT
  959. .SH SHARING MODES
  960. .SS Trusted
  961. .sp
  962. Trusted mode is the default sharing mode. Updates are exchanged in both
  963. directions.
  964. .INDENT 0.0
  965. .INDENT 3.5
  966. .sp
  967. .nf
  968. .ft C
  969. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  970. | | \-\-\-\-\-\-\-\-\-\-\-> / \e
  971. | Device | | Cluster |
  972. | | <\-\-\-\-\-\-\-\-\-\-\- \e /
  973. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates \e\-\-\-\-\-\-\-\-\-/
  974. .ft P
  975. .fi
  976. .UNINDENT
  977. .UNINDENT
  978. .SS Read Only
  979. .sp
  980. In read only mode, a device does not apply any updates from the cluster,
  981. but publishes changes of its local folder to the cluster as usual.
  982. The local folder can be seen as a "master copy" that is never affected
  983. by the actions of other cluster devices.
  984. .INDENT 0.0
  985. .INDENT 3.5
  986. .sp
  987. .nf
  988. .ft C
  989. +\-\-\-\-\-\-\-\-\-\-\-\-+ Updates /\-\-\-\-\-\-\-\-\-\e
  990. | | \-\-\-\-\-\-\-\-\-\-\-> / \e
  991. | Device | | Cluster |
  992. | | \e /
  993. +\-\-\-\-\-\-\-\-\-\-\-\-+ \e\-\-\-\-\-\-\-\-\-/
  994. .ft P
  995. .fi
  996. .UNINDENT
  997. .UNINDENT
  998. .SH MESSAGE LIMITS
  999. .sp
  1000. An implementation MAY impose reasonable limits on the length of messages
  1001. and message fields to aid robustness in the face of corruption or broken
  1002. implementations. These limits, if imposed, SHOULD NOT be more
  1003. restrictive than the following. An implementation should strive to keep
  1004. messages short and to the point, favouring more and smaller messages
  1005. over fewer and larger. For example, favour a smaller Index message
  1006. followed by one or more Index Update messages rather than sending a very
  1007. large Index message.
  1008. .TS
  1009. center;
  1010. |l|l|l|.
  1011. _
  1012. T{
  1013. Message Type
  1014. T} T{
  1015. Field
  1016. T} T{
  1017. Limit
  1018. T}
  1019. _
  1020. T{
  1021. \fBAll Messages\fP
  1022. T}
  1023. _
  1024. T{
  1025. .nf
  1026. .fi
  1027. T} T{
  1028. Total length
  1029. T} T{
  1030. 64 MiB
  1031. T}
  1032. _
  1033. T{
  1034. \fBIndex and Index Update Messages\fP
  1035. T}
  1036. _
  1037. T{
  1038. .nf
  1039. .fi
  1040. T} T{
  1041. Folder
  1042. T} T{
  1043. 64 bytes
  1044. T}
  1045. _
  1046. T{
  1047. .nf
  1048. .fi
  1049. T} T{
  1050. Number of Files
  1051. T} T{
  1052. 1.000.000
  1053. T}
  1054. _
  1055. T{
  1056. .nf
  1057. .fi
  1058. T} T{
  1059. Name
  1060. T} T{
  1061. 8192 bytes
  1062. T}
  1063. _
  1064. T{
  1065. .nf
  1066. .fi
  1067. T} T{
  1068. Number of Blocks
  1069. T} T{
  1070. 1.000.000
  1071. T}
  1072. _
  1073. T{
  1074. .nf
  1075. .fi
  1076. T} T{
  1077. Hash
  1078. T} T{
  1079. 64 bytes
  1080. T}
  1081. _
  1082. T{
  1083. .nf
  1084. .fi
  1085. T} T{
  1086. Number of Counters
  1087. T} T{
  1088. 1.000.000
  1089. T}
  1090. _
  1091. T{
  1092. \fBRequest Messages\fP
  1093. T}
  1094. _
  1095. T{
  1096. .nf
  1097. .fi
  1098. T} T{
  1099. Folder
  1100. T} T{
  1101. 64 bytes
  1102. T}
  1103. _
  1104. T{
  1105. .nf
  1106. .fi
  1107. T} T{
  1108. Name
  1109. T} T{
  1110. 8192 bytes
  1111. T}
  1112. _
  1113. T{
  1114. \fBResponse Messages\fP
  1115. T}
  1116. _
  1117. T{
  1118. .nf
  1119. .fi
  1120. T} T{
  1121. Data
  1122. T} T{
  1123. 256 KiB
  1124. T}
  1125. _
  1126. T{
  1127. \fBCluster Config Message\fP
  1128. T}
  1129. _
  1130. T{
  1131. .nf
  1132. .fi
  1133. T} T{
  1134. Number of Folders
  1135. T} T{
  1136. 1.000.000
  1137. T}
  1138. _
  1139. T{
  1140. .nf
  1141. .fi
  1142. T} T{
  1143. Number of Devices
  1144. T} T{
  1145. 1.000.000
  1146. T}
  1147. _
  1148. T{
  1149. .nf
  1150. .fi
  1151. T} T{
  1152. Number of Options
  1153. T} T{
  1154. 64
  1155. T}
  1156. _
  1157. T{
  1158. .nf
  1159. .fi
  1160. T} T{
  1161. Key
  1162. T} T{
  1163. 64 bytes
  1164. T}
  1165. _
  1166. T{
  1167. .nf
  1168. .fi
  1169. T} T{
  1170. Value
  1171. T} T{
  1172. 1024 bytes
  1173. T}
  1174. _
  1175. .TE
  1176. .SH EXAMPLE EXCHANGE
  1177. .TS
  1178. center;
  1179. |l|l|l|.
  1180. _
  1181. T{
  1182. #
  1183. T} T{
  1184. A
  1185. T} T{
  1186. B
  1187. T}
  1188. _
  1189. T{
  1190. 1
  1191. T} T{
  1192. ClusterConfiguration\->
  1193. T} T{
  1194. <\-ClusterConfiguration
  1195. T}
  1196. _
  1197. T{
  1198. 2
  1199. T} T{
  1200. Index\->
  1201. T} T{
  1202. <\-Index
  1203. T}
  1204. _
  1205. T{
  1206. 3
  1207. T} T{
  1208. IndexUpdate\->
  1209. T} T{
  1210. <\-IndexUpdate
  1211. T}
  1212. _
  1213. T{
  1214. 4
  1215. T} T{
  1216. IndexUpdate\->
  1217. T} T{
  1218. T}
  1219. _
  1220. T{
  1221. 5
  1222. T} T{
  1223. Request\->
  1224. T} T{
  1225. T}
  1226. _
  1227. T{
  1228. 6
  1229. T} T{
  1230. Request\->
  1231. T} T{
  1232. T}
  1233. _
  1234. T{
  1235. 7
  1236. T} T{
  1237. Request\->
  1238. T} T{
  1239. T}
  1240. _
  1241. T{
  1242. 8
  1243. T} T{
  1244. Request\->
  1245. T} T{
  1246. T}
  1247. _
  1248. T{
  1249. 9
  1250. T} T{
  1251. T} T{
  1252. <\-Response
  1253. T}
  1254. _
  1255. T{
  1256. 10
  1257. T} T{
  1258. T} T{
  1259. <\-Response
  1260. T}
  1261. _
  1262. T{
  1263. 11
  1264. T} T{
  1265. T} T{
  1266. <\-Response
  1267. T}
  1268. _
  1269. T{
  1270. 12
  1271. T} T{
  1272. T} T{
  1273. <\-Response
  1274. T}
  1275. _
  1276. T{
  1277. 13
  1278. T} T{
  1279. Index Update\->
  1280. T} T{
  1281. T}
  1282. _
  1283. T{
  1284. \&...
  1285. T} T{
  1286. T} T{
  1287. T}
  1288. _
  1289. T{
  1290. 14
  1291. T} T{
  1292. T} T{
  1293. <\-Ping
  1294. T}
  1295. _
  1296. T{
  1297. 15
  1298. T} T{
  1299. Ping\->
  1300. T} T{
  1301. T}
  1302. _
  1303. .TE
  1304. .sp
  1305. The connection is established and at 1. both peers send ClusterConfiguration
  1306. messages and then Index records. The Index records are received and both peers
  1307. recompute their knowledge of the data in the cluster. In this example, peer A
  1308. has four missing or outdated blocks. At 5 through 8 peer A sends requests for
  1309. these blocks. The requests are received by peer B, who retrieves the data from
  1310. the folder and transmits Response records (9 through 12). Device A updates
  1311. their folder contents and transmits an Index Update message (13). Both peers
  1312. enter idle state after 13. At some later time 14, the ping timer on device B
  1313. expires and a Ping message is sent. The same process occurs for device A at
  1314. 15.
  1315. .SH EXAMPLES OF STRONG CIPHER SUITES
  1316. .TS
  1317. center;
  1318. |l|l|l|.
  1319. _
  1320. T{
  1321. ID
  1322. T} T{
  1323. Name
  1324. T} T{
  1325. Description
  1326. T}
  1327. _
  1328. T{
  1329. 0x009F
  1330. T} T{
  1331. DHE\-RSA\-AES256\-GCM\-SHA384
  1332. T} T{
  1333. TLSv1.2 DH RSA AESGCM(256) AEAD
  1334. T}
  1335. _
  1336. T{
  1337. 0x006B
  1338. T} T{
  1339. DHE\-RSA\-AES256\-SHA256
  1340. T} T{
  1341. TLSv1.2 DH RSA AES(256) SHA256
  1342. T}
  1343. _
  1344. T{
  1345. 0xC030
  1346. T} T{
  1347. ECDHE\-RSA\-AES256\-GCM\-SHA384
  1348. T} T{
  1349. TLSv1.2 ECDH RSA AESGCM(256) AEAD
  1350. T}
  1351. _
  1352. T{
  1353. 0xC028
  1354. T} T{
  1355. ECDHE\-RSA\-AES256\-SHA384
  1356. T} T{
  1357. TLSv1.2 ECDH RSA AES(256) SHA384
  1358. T}
  1359. _
  1360. T{
  1361. 0x009E
  1362. T} T{
  1363. DHE\-RSA\-AES128\-GCM\-SHA256
  1364. T} T{
  1365. TLSv1.2 DH RSA AESGCM(128) AEAD
  1366. T}
  1367. _
  1368. T{
  1369. 0x0067
  1370. T} T{
  1371. DHE\-RSA\-AES128\-SHA256
  1372. T} T{
  1373. TLSv1.2 DH RSA AES(128) SHA256
  1374. T}
  1375. _
  1376. T{
  1377. 0xC02F
  1378. T} T{
  1379. ECDHE\-RSA\-AES128\-GCM\-SHA256
  1380. T} T{
  1381. TLSv1.2 ECDH RSA AESGCM(128) AEAD
  1382. T}
  1383. _
  1384. T{
  1385. 0xC027
  1386. T} T{
  1387. ECDHE\-RSA\-AES128\-SHA256
  1388. T} T{
  1389. TLSv1.2 ECDH RSA AES(128) SHA256
  1390. T}
  1391. _
  1392. .TE
  1393. .SH AUTHOR
  1394. The Syncthing Authors
  1395. .SH COPYRIGHT
  1396. 2015, The Syncthing Authors
  1397. .\" Generated by docutils manpage writer.
  1398. .