A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.md 45KB

4 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. title: How Dat Works
  2. url: https://datprotocol.github.io/how-dat-works/
  3. hash_url: 87310ff690bc7663b397af17121a5a09
  4. <p id="introduction"><strong>Dat is a protocol for sharing data between computers.</strong> Dat’s strengths are that data is hosted and distributed by many computers on the network, that it can work offline or with poor connectivity, that the original uploader can add or modify data while keeping a full history and that it can handle large amounts of data.</p>
  5. <div>
  6. <p>Dat is compelling because the people working on it have a dedication to user experience and ease-of-use. The software around Dat brings publishing within reach for people with a wide range of skills, not just technical. Although first designed with scientific data in mind, the Dat community is testing the waters and has begun to use it for websites, art, music releases, peer-to-peer chat programs and many other experiments.</p>
  7. <p>This guide is an in-depth tour through the bits and bytes of the Dat protocol, starting from a blank slate and ending with being able to download and share files with other peers running Dat. There will be enough detail for readers who are considering writing their own implementation of Dat, but if you are just curious how it works or want to learn from Dat’s design then I hope you will find this guide useful too!</p>
  8. </div>
  9. <aside class="basealign">
  10. <h2>More documentation about Dat</h2>
  11. </aside>
  12. <div class="feedback">
  13. <div>
  14. <h2>Feedback</h2>
  15. <p>This guide was published only a few days ago! There are probably lots of little improvements that will be obvious to you as you read through it but weren’t obvious to me as I wrote it. Please <strong><a href="https://goo.gl/forms/R22N7C3e0trxNn9h1">send feedback</a></strong> about what you liked, found confusing or would change.</p>
  16. <p><strong>New Zealanders:</strong> Would you be willing to read through this guide together, in person, with me the author? <a href="https://goo.gl/forms/VT1UcGgMPTziILxH2">More info.</a></p>
  17. </div>
  18. </div>
  19. <h1 id="urls" class="section"><span>URLs</span></h1>
  20. <p>To fetch a file in Dat you need to know its URL. Here is an example:</p>
  21. <svg class="smallmargin pagewidth">
  22. <text class="code" x="0" y="18"><tspan>dat://</tspan><tspan fill="#007fff">778f8d955175c92e4ced5e4f5563f69bfec0c86cc6f670352c457943666fe639</tspan><tspan>/dat_intro.gif</tspan></text>
  23. <path stroke="#93a0b6" strokewidth="1" fill="none" d="M0.5,24 v4.5 h60 v-4.5 m0,4.5 h640 v-4.5 m0,4.5 h140 v-4.5"/>
  24. <text y="44" text-anchor="middle"><tspan x="30">protocol</tspan><tspan x="30" dy="1.2em">identifier</tspan></text>
  25. <text y="44" text-anchor="middle"><tspan x="380">ed25519 public key</tspan><tspan x="380" dy="1.2em">(hexadecimal)</tspan></text>
  26. <text y="44" text-anchor="middle"><tspan x="770">optional suffix</tspan><tspan x="770" dy="1.2em">path to data within Dat</tspan></text>
  27. </svg>
  28. <ul>
  29. <li><strong>Protocol identifier.</strong> Makes Dat URLs easily recognizable. Dat-capable applications can register with the operating system to handle <code>dat://</code> links, like <a href="https://beakerbrowser.com/">Beaker</a> does. In Dat-specific applications the protocol identifier can be left off.</li>
  30. <li><strong>Public key.</strong> An ed25519 public key unique to this Dat, used by the author to create and update data within it. The public key enables you to discover other peers who have the data and is also verify that the data was not corrupted or tampered with as it passed through the network.</li>
  31. <li><strong>Suffix.</strong> Identifies specific data within this Dat. For most Dats which contain a directory of files, the suffix is a slash-separated file path. Dats can also contain data in structures that don’t use the concept of files or directories, in which case the suffix would use some other format as understood by the applications that handle that sort of data.</li>
  32. </ul>
  33. <aside class="impl">
  34. <img class="icon" src="png/spanner_icon.png"/>
  35. <h3>Implementations</h3>
  36. <p class="lang">JS</p>
  37. </aside>
  38. <h1 id="discovery" class="section"><span>Discovery</span></h1>
  39. <p>Dat clients use several different methods for discovering peers who they can download data from. Each discovery method has strengths and weaknesses, but combined they form a reasonably robust way of finding peers.</p>
  40. <h2 id="discovery-keys">Discovery keys</h2>
  41. <div>
  42. <p>Discovery keys are used for finding other peers who are interested in the same Dat as you.</p>
  43. <p>If you know a Dat’s public key then you can calculate the discovery key easily, however if you only know a discovery key you cannot work backwards to find the corresponding public key. This prevents eavesdroppers learning of Dat URLs (and therefore being able to read their contents) by observing network traffic.</p>
  44. </div>
  45. <aside class="impl">
  46. <img class="icon" src="png/spanner_icon.png"/>
  47. <h3>Implementations</h3>
  48. <p class="lang">JS</p>
  49. </aside>
  50. <p>However eavesdroppers can confirm that peers are talking about a specific Dat and read all communications between those peers if they know its public key already. Eavesdroppers who do not know the public key can still get an idea of how many Dats are popular on the network, their approximate sizes, which IP addresses are interested in them and potentially the IP address of the creator by observing handshakes, traffic timing and volumes. Dat makes no attempt to hide IP addresses.</p>
  51. <p>Calculate a Dat’s discovery key using the <strong>BLAKE2b</strong> hashing function, keyed with the public key (as 32 bytes, not 64 hexadecimal characters), to hash the word “hypercore”:</p>
  52. <aside class="basealign">Dat uses the BLAKE2b variant that accepts both a key and input to be hashed, returning 256 bits (32 bytes) of output.</aside>
  53. <img id="blake2b" src="png/blake2b.png"/>
  54. <aside>
  55. <h3>Byte notation</h3>
  56. <img src="png/notation_byte.png"/>
  57. <p>Throughout this guide bytes are shown as a number inside a square. The number is always in decimal (base‑10) and can range from 0 to 255.</p>
  58. </aside>
  59. <h2 id="local-network-discovery">Local network discovery</h2>
  60. <div>
  61. <p>Peers broadcast which Dats they are interested in via their local network.</p>
  62. <ul>
  63. <li><strong>Strengths.</strong> Fast, finds physically nearby peers, doesn’t need special infrastructure, works offline.</li>
  64. <li><strong>Weaknesses.</strong> Limited reach.</li>
  65. <li><strong>Deployment status.</strong> Currently in use, will be replaced by <a href="https://pfrazee.hashbase.io/blog/hyperswarm">Hyperswarm</a> in the future.</li>
  66. </ul>
  67. </div>
  68. <aside class="impl">
  69. <img class="icon" src="png/spanner_icon.png"/>
  70. <h3>Implementations</h3>
  71. <p class="lang">JS</p>
  72. </aside>
  73. <p>Local network discovery uses multicast DNS, which is like a regular DNS query except instead of sending queries to a nameserver they are broadcast to the local network with the hope that someone else on the network sees it and responds.</p>
  74. <figure id="mdns-request" class="pagewidth">
  75. <figcaption>Client asking for peers</figcaption>
  76. <img src="png/mdns_request.png"/>
  77. </figure>
  78. <p>Multicast DNS packets are sent to the special broadcast MAC and IP addresses shown above. Both the source and destination ports are 5353.</p>
  79. <p>Essentially the computer is asking “Does anybody have any TXT records for the domain name <em>25a78aa81615847eba00995df29dd41d7ee30f3b.dat.local</em>?” Other Dat clients on the network will recognize requests following this pattern and know that the client who sent it is looking for peers.</p>
  80. <figure id="mdns-response" class="pagewidth">
  81. <figcaption>Peer reporting that they are also interested in this Dat</figcaption>
  82. <img src="png/mdns_response.png"/>
  83. </figure>
  84. <p id="mdns-peers-record">Responses contain two TXT records:</p>
  85. <ul>
  86. <li>The <strong>token</strong> record is a random value that makes it easier for clients to avoid connecting to themselves. If a client sees a response with the same token as a response they just sent out, they will know it came from them and ignore it.</li>
  87. <li>The <strong>peers</strong> record is a base64-encoded list of IP addresses and ports of peers interested in this Dat:</li>
  88. </ul>
  89. <aside class="impl">
  90. <img class="icon" src="png/spanner_icon.png"/>
  91. <h3>Implementations</h3>
  92. <p class="lang">JS</p>
  93. </aside>
  94. <div>
  95. <img src="png/mdns_peers_record.png"/>
  96. <p>The special IP address 0.0.0.0 means “use the address this mDNS response came from”. When discovering peers on the local network all mDNS responses will contain only one peer and will use the 0.0.0.0 address.</p>
  97. </div>
  98. <aside>
  99. <p>Base64 encoding in Dat uses the variant with plus <code>+</code> and slash <code>/</code> characters. Padding equals <code>=</code> characters are required.</p>
  100. <p>Only IPv4 addresses are supported by this discovery mechanism.</p>
  101. <h3>Multi-byte numbers</h3>
  102. <p>Port numbers go from 0 to 65,535 which is larger than can fit inside a single byte, so in this case two bytes are used.</p>
  103. <p>The first byte is how many 256’s there are and the second byte is how many ones there are:</p>
  104. <img src="png/notation_multi_byte_number.png"/>
  105. <p>In the Dat protocol multi-byte numbers are big-endian meaning the most significant byte comes first.</p>
  106. </aside>
  107. <h2 id="centralized-dns-discovery">Centralized DNS discovery</h2>
  108. <p>Peers ask a server on the internet for other peers using a DNS-based protocol.</p>
  109. <ul>
  110. <li><strong>Strengths.</strong> Fast, global reach.</li>
  111. <li><strong>Weaknesses.</strong> Must be online, centralized point of failure, one server sees everyone’s metadata.</li>
  112. <li><strong>Deployment status.</strong> Currently in use, will be replaced by <a href="https://pfrazee.hashbase.io/blog/hyperswarm">Hyperswarm</a> in the future.</li>
  113. </ul>
  114. <p>Currently the server running this is <strong>discovery1.datprotocol.com</strong>. If that goes offline then <strong>discovery2.datprotocol.com</strong> can be used as a fallback.</p>
  115. <p>Here is a typical message flow between a Dat peer and the DNS discovery server:</p>
  116. <img class="pagewidth" src="png/centralized_dns_conversation.png"/>
  117. <p>To stay subscribed, peers should re-announce themselves every 60 seconds. The discovery server will also cycle its tokens periodically so peers should remember the token they last received and update it when the receive a new one.</p>
  118. <p id="centralized-dns-peers-record">The <em>peers</em> record returned by the discovery server uses the same structure as in mDNS:</p>
  119. <img src="png/mdns_peers_record_multi.png"/>
  120. <aside>In this case the server sent back a list of five peers. DNS TXT records are limited to 255 characters so the server is limited to sending back 31 peers at a time. If the server knows more than this it will have to choose which to send, for example the most recent, longest lived or by picking at random.</aside>
  121. <p>Following are three examples showing how these DNS requests appear as bytes sent over the network:</p>
  122. <figure id="centralized-dns-request">
  123. <figcaption>Peer announce request to discovery server</figcaption>
  124. <img src="png/centralized_dns_request.png"/>
  125. </figure>
  126. <figure id="centralized-dns-response">
  127. <figcaption>Discovery server response to announce</figcaption>
  128. <img src="png/centralized_dns_response.png"/>
  129. </figure>
  130. <figure id="centralized-dns-srv">
  131. <figcaption>Discovery server SRV push notification</figcaption>
  132. <img src="png/centralized_dns_srv.png"/>
  133. </figure>
  134. <h1 id="wire-protocol" class="section"><span>Wire protocol</span></h1>
  135. <p>Once a peer has discovered another peer’s IP address and port number it will open a TCP connection to the other peer. Each half of the conversation has this structure which repeats until the end of the connection:</p>
  136. <aside class="impl">
  137. <img class="icon" src="png/spanner_icon.png"/>
  138. <h3>Implementations</h3>
  139. <p class="lang">JS</p>
  140. </aside>
  141. <img class="pagewidth" src="png/wire_protocol_structure.png"/>
  142. <ul>
  143. <li><strong>Length.</strong> Number of bytes until the start of the next length field.</li>
  144. <li><strong>Channel and type.</strong> A single number (up to 11 bits long) that encodes two sub-fields as:</li>
  145. <img src="png/channel_type_field.png"/>
  146. <ul>
  147. <li><strong>Channel.</strong> Peers can talk about multiple Dats using the same TCP connection. The channel number is 0 for the first Dat talked about, 1 for the next Dat and so on.</li>
  148. <li id="message-type"><strong>Type.</strong> Number that says what the purpose of the message is.</li>
  149. <table>
  150. <thead>
  151. <tr>
  152. <th>Type</th>
  153. <th>Name</th>
  154. <th>Meaning</th>
  155. </tr>
  156. </thead>
  157. <tbody>
  158. <tr>
  159. <td>0</td>
  160. <td><strong>Feed</strong></td>
  161. <td>I want to talk to you about this particular Dat</td>
  162. </tr>
  163. <tr>
  164. <td>1</td>
  165. <td><strong>Handshake</strong></td>
  166. <td>I want to negotiate how we will communicate on this TCP connection</td>
  167. </tr>
  168. <tr>
  169. <td>2</td>
  170. <td><strong>Info</strong></td>
  171. <td>I am either starting or stopping uploading or downloading</td>
  172. </tr>
  173. <tr>
  174. <td>3</td>
  175. <td><strong>Have</strong></td>
  176. <td>I have some data that you said you wanted</td>
  177. </tr>
  178. <tr>
  179. <td>4</td>
  180. <td><strong>Unhave</strong></td>
  181. <td>I no longer have some data that I previously said I had (alternatively: I didn’t store that data you just sent, please stop sending me data preemptively)</td>
  182. </tr>
  183. <tr>
  184. <td>5</td>
  185. <td><strong>Want</strong></td>
  186. <td>This is what data I want</td>
  187. </tr>
  188. <tr>
  189. <td>6</td>
  190. <td><strong>Unwant</strong></td>
  191. <td>I no longer want this data</td>
  192. </tr>
  193. <tr>
  194. <td>7</td>
  195. <td><strong>Request</strong></td>
  196. <td>Please send me this data now</td>
  197. </tr>
  198. <tr>
  199. <td>8</td>
  200. <td><strong>Cancel</strong></td>
  201. <td>Actually, don’t send me that data</td>
  202. </tr>
  203. <tr>
  204. <td>9</td>
  205. <td><strong>Data</strong></td>
  206. <td>Here is the data you requested</td>
  207. </tr>
  208. <tr>
  209. <td>10–14</td>
  210. <td/>
  211. <td><em>(Unused)</em></td>
  212. </tr>
  213. <tr>
  214. <td>15</td>
  215. <td><strong>Extension</strong></td>
  216. <td>Some other message that is not part of the core protocol</td>
  217. </tr>
  218. </tbody>
  219. </table>
  220. </ul>
  221. <li><strong>Body.</strong> Contents of the message.</li>
  222. </ul>
  223. <aside>
  224. <h3>Bit notation</h3>
  225. <p>In several parts of the Dat protocol multiple fields are packed into a single number. It helps to look at the number as a sequence of bits because this makes the fields visible.</p>
  226. <img src="png/notation_bits.png"/>
  227. <p>Throughout this guide bit sequences are shown as 1’s and 0’s in a box, grouped into fields. The most significant bit is always on the left.</p>
  228. <p>Eight bits make up a byte, however this number and many others are varints which can be up to 64 bits long. The fields on the right are always a fixed number of bits but the leftmost field can take up as many of the remaining 64 bits as it needs.</p>
  229. </aside>
  230. <h2 id="varints">Varints</h2>
  231. <div>
  232. <p>The first two fields are encoded as variable-length integers and therefore do not have a fixed size. You must read each field starting from the beginning to determine how long the field is and where the next field starts.</p>
  233. <p>The advantage of varints is that they only require a few bytes to represent small numbers, while still being able to represent large numbers by using more bytes. The disadvantage of varints is that they take more work to encode and decode compared to regular integers.</p>
  234. </div>
  235. <aside>
  236. <div class="impl">
  237. <img class="icon" src="png/spanner_icon.png"/>
  238. <h3>Implementations</h3>
  239. <p class="lang">JS</p>
  240. <p class="lang">Rust</p>
  241. </div>
  242. <p>In Dat, varints are between 1 and 10 bytes long and represent integers from 0 to 2<sup>64</sup> - 1. Negative numbers aren’t used.</p>
  243. </aside>
  244. <p>Here’s how to decode a varint:</p>
  245. <img class="pagewidth" src="png/varint.png"/>
  246. <h2 id="keepalive">Keepalive</h2>
  247. <p>Keepalive messages are empty messages containing no channel number, type or body. They are discarded upon being received. Sending keepalives is necessary when there is a network middlebox that kills TCP connections which haven’t sent any data in a while. In these cases each peer periodically sends keepalive messages when no other data is being sent.</p>
  248. <aside>How frequently to send keepalive messages is essentially a guess based on what types of middleboxes are commonly used on the internet today. Other TCP-based protocols typically send keepalives every 30 to 120 seconds.</aside>
  249. <p>Here’s an example of several keepalive messages interleaved with messages containing actual data. Each keepalive message is a single byte of zero:</p>
  250. <img class="pagewidth" src="png/wire_protocol_keepalive.png"/>
  251. <h2 id="message-structure">Message structure</h2>
  252. <p>Within each message body is a series of field tags and values:</p>
  253. <img class="pagewidth" src="png/wire_protocol_field_value_structure.png"/>
  254. <p id="message-structure-field-tag">The field tag is a varint. The most significant bits indicate which field within the message this is, for example: 1 = <em>discovery key</em>, 2 = <em>nonce</em>. This is needed because messages can have missing or repeated fields. The 3 least significant bits are the type of field.</p>
  255. <img src="png/field_type_field.png"/>
  256. <p id="message-field-types">The two types of field are:</p>
  257. <ul>
  258. <li><strong>Varint.</strong> The field tag followed by a varint value. Used for simple numeric values and booleans.</li>
  259. <img src="png/field_structure_varint.png"/>
  260. <li><strong>Length-prefixed.</strong> The field tag followed by a varint to say how many bytes the field contains, followed by the bytes themselves. Used for strings, bytes and embedded messages.</li>
  261. <img src="png/field_structure_length_prefixed.png"/>
  262. </ul>
  263. <aside class="basealign">
  264. <p>If you are familiar with the <a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a> data serialization format you might recognize that this message structure adheres to it. Dat only uses a small subset of the features available with Protocol Buffers, however if you are writing an implementation you may be interested in the <a href="https://github.com/mafintosh/hypercore-protocol/blob/master/schema.proto">.proto file</a> that describes the wire protocol.</p>
  265. <p>Over time new fields could be added to messages in the wire protocol. Field tags enable this to happen in a backwards-compatible way. If your implementation sees a field number that it doesn’t know about it can use the field type to find out how long the unknown field is and skip over it.</p>
  266. <div class="impl">
  267. <img class="icon" src="png/spanner_icon.png"/>
  268. <h3>Implementations</h3>
  269. <p class="lang">JS</p>
  270. </div>
  271. </aside>
  272. <h2 id="feed-message">Feed message</h2>
  273. <p>After opening the TCP connection the first message is always a <strong>feed</strong> message.</p>
  274. <p>Feed messages have two fields:</p>
  275. <div class="pagewidth msgfields">
  276. <table>
  277. <thead>
  278. <tr>
  279. <th>No.</th>
  280. <th>Name</th>
  281. <th>Type</th>
  282. <th>Description</th>
  283. </tr>
  284. </thead>
  285. <tbody>
  286. <tr>
  287. <td>1</td>
  288. <td><strong>Discovery key</strong></td>
  289. <td>Length-prefixed</td>
  290. <td>32-byte discovery key for this Dat.</td>
  291. </tr>
  292. <tr>
  293. <td>2</td>
  294. <td><strong>Nonce</strong></td>
  295. <td>Length-prefixed</td>
  296. <td>24-byte random nonce generated for this TCP connection. Only present for the first feed message.</td>
  297. </tr>
  298. </tbody>
  299. </table>
  300. </div>
  301. <p>Putting everything together, this is how each side of the TCP connection begins:</p>
  302. <img class="pagewidth" src="png/feed_message.png"/>
  303. <p>Or, as the bytes actually sent over the wire:</p>
  304. <img id="feed-message-bytes" class="pagewidth" src="png/feed_message_bytes.png"/>
  305. <h2 id="encryption">Encryption</h2>
  306. <div>
  307. <p>Each side of the TCP connection is encrypted starting from the second message and continuing until the end of the connection. This prevents network eavesdroppers from finding out what data a Dat contains unless they already know its public key.</p>
  308. <p><strong>XSalsa20</strong> is the encryption cipher used. Given a 32-byte key and a 24-byte nonce, XSalsa20 produces a never-ending stream of pseudorandom bytes called the keystream.</p>
  309. </div>
  310. <aside class="basealign">The encryption scheme is not authenticated, meaning a man-in-the-middle can flip bits to disrupt the connection. This is mitigated because data integrity in a Dat is verified using a separate mechanism. If there is an attacker who is in a position to modify bits on the network they have lots of other options for disrupting connections, for example by simply dropping packets.</aside>
  311. <img class="pagewidth" src="png/encryption.png"/>
  312. <p id="encryption-sender">The <strong>sender</strong> generates a random 24-byte value for the nonce and includes it in their first message (which is always a feed message). The Dat’s 32-byte public key is used as the XSalsa20 key. From the second message onwards all bytes they send are XORed with the keystream.</p>
  313. <aside class="impl">
  314. <img class="icon" src="png/spanner_icon.png"/>
  315. <h3>Implementations</h3>
  316. <p class="lang">JS</p>
  317. </aside>
  318. <img class="pagewidth" src="png/encryption_send.png"/>
  319. <p id="encryption-receiver">The <strong>receiver</strong> reads the nonce from the sender’s first message and uses this with their knowledge of the Dat’s public key to set up an identical XSalsa20 keystream. Then they XOR the keystream with the bytes received to decrypt the stream.</p>
  320. <img class="pagewidth" src="png/encryption_receive.png"/>
  321. <h2 id="handshake-message">Handshake message</h2>
  322. <p>After the initial feed message, the second message sent on each side of the TCP connection is always a <strong>handshake</strong> message.</p>
  323. <div class="pagewidth msgfields">
  324. <table>
  325. <thead>
  326. <tr>
  327. <th>No.</th>
  328. <th>Name</th>
  329. <th>Type</th>
  330. <th>Description</th>
  331. </tr>
  332. </thead>
  333. <tbody>
  334. <tr>
  335. <td>1</td>
  336. <td><strong>ID</strong></td>
  337. <td>Length-prefixed</td>
  338. <td>Random ID generated by this peer upon starting, 32 bytes long. Used to detect multiple connections to the same peer or accidental connections to itself.</td>
  339. </tr>
  340. <tr>
  341. <td>2</td>
  342. <td><strong>Live</strong></td>
  343. <td>Varint</td>
  344. <td>0 = End the connection when neither peer is downloading, 1 = Keep the connection open indefinitely (only takes effect if both peers set to 1).</td>
  345. </tr>
  346. <tr>
  347. <td>3</td>
  348. <td><strong>User data</strong></td>
  349. <td>Length-prefixed</td>
  350. <td>Arbitrary bytes that can be used by higher-level applications for any purpose. Remember that any data put in here is not protected from tampering as it passes through the network. Additionally, any eavesdropper who knows the Dat’s public key can read this.</td>
  351. </tr>
  352. <tr>
  353. <td>4</td>
  354. <td><strong>Extensions</strong></td>
  355. <td>Length-prefixed</td>
  356. <td>Names of any extensions the peer wants to use, for example: “session-data”. This field can appear multiple times, one for each extension. Both peers need to request an extension in their handshake messages for it to become active.</td>
  357. </tr>
  358. <tr>
  359. <td>5</td>
  360. <td><strong>Acknowledge</strong></td>
  361. <td>Varint</td>
  362. <td>0 = No need to acknowledge each chunk of data received, 1 = Must acknowledge each chunk of data received.</td>
  363. </tr>
  364. </tbody>
  365. </table>
  366. </div>
  367. <h1 id="data-model" class="section"><span>Data model</span></h1>
  368. <p>After completing the handshake peers begin requesting data from each other. Dats contain a list of variable-sized chunks of bytes. New chunks can be added to the end by the Dat’s author, but existing chunks can’t be deleted or modified.</p>
  369. <aside>Boundaries between chunks are preserved. This can be useful for dividing up the Dat into a series of messages, for example one message per chunk.</aside>
  370. <img src="png/chunk_structure.png"/>
  371. <p>Hashes are used to verify the integrity of data within a Dat. Each chunk of data has a corresponding hash. There are also parent hashes which verify the integrity of two other hashes. Parent hashes form a tree structure. In this example the integrity of all the data can be verified if you know hash number 3:</p>
  372. <img id="chunk-structure-hashes" src="png/chunk_structure_hashes.png"/>
  373. <aside>
  374. <p>Chunk hashes are even-numbered. Parent hashes are odd-numbered.</p>
  375. <p>Hash trees allow downloaders to download and verify a specific chunk without needing to also download hashes of every other chunk.</p>
  376. </aside>
  377. <p>Each time the author adds new chunks they calculate a root hash and sign it with the Dat’s secret key. Downloaders can use the Dat’s public key to verify the signature, which in turn verifies the integrity of all the other hashes and chunks.</p>
  378. <img id="chunk-structure-signature" src="png/chunk_structure_signature.png"/>
  379. <p>Depending on the number of chunks, the root hash can have more than one input. The root hash combines as many parent or chunk hashes as necessary to cover all the chunks. Here is how the hash tree looks with different numbers of chunks:</p>
  380. <img id="hash-tree-1" class="pagewidth" src="png/hash_tree_1.png"/>
  381. <img id="hash-tree-2" class="pagewidth" src="png/hash_tree_2.png"/>
  382. <h2 id="hashes-and-signatures">Hashes and signatures</h2>
  383. <div>
  384. <p>The three types of hash seen in the hash tree are:</p>
  385. <ul>
  386. <li><strong>Chunk hashes</strong>, which hash the contents of a single chunk.</li>
  387. <li><strong>Parent hashes</strong>, which hash two other hashes forming a tree structure.</li>
  388. <li><strong>Root hashes</strong>, which sit at the root of the tree and are signed by the Dat’s author.</li>
  389. </ul>
  390. </div>
  391. <aside class="impl">
  392. <img class="icon" src="png/spanner_icon.png"/>
  393. <h3>Implementations</h3>
  394. <p class="lang">JS</p>
  395. <p class="lang">Rust</p>
  396. </aside>
  397. <p>Each type of hash has a specific way to construct it:</p>
  398. <h1 id="exchanging-data" class="section"><span>Exchanging data</span></h1>
  399. <p>Peers exchange chunks in multi-step process where the downloader and uploader negotiate what chunks they want and have:</p>
  400. <img src="png/chunk_conversation.png"/>
  401. <aside>
  402. <p>In this example one peer is a downloader and the other is an uploader. In other cases both peers will be uploading and downloading at the same time as they each have some of the chunks but not all of them.</p>
  403. <p>Each request message can only request a single chunk per message. Downloaders may want to queue up several request messages at a time. When the uploader finishes sending a chunk this lets them immediately start sending the next one without waiting for a round-trip.</p>
  404. </aside>
  405. <h2 id="want-and-have">Want and have</h2>
  406. <p>Each peer remembers which chunks the other peer wants and has.</p>
  407. <ul>
  408. <li><strong>Wanting</strong> a chunk means “I want to download this chunk, please tell me if you have it”.</li>
  409. <li><strong>Having</strong> a chunk means “I know you want this chunk and I will send it if you ask for it”. If a peer tells you they are only interested in a small range of chunks then you only have to tell them about chunks within that range.</li>
  410. </ul>
  411. <p>As peers download (or even delete) data, the list of chunks they want and have will change. This state is communicated with four message types: <strong>want</strong>, <strong>unwant</strong>, <strong>have</strong> and <strong>unhave</strong>. Each of these four messages has the same structure which indicates a contiguous range of chunks:</p>
  412. <div class="pagewidth msgfields">
  413. <table>
  414. <thead>
  415. <tr>
  416. <th>No.</th>
  417. <th>Name</th>
  418. <th>Type</th>
  419. <th>Description</th>
  420. </tr>
  421. </thead>
  422. <tbody>
  423. <tr>
  424. <td>1</td>
  425. <td><strong>Start</strong></td>
  426. <td>Varint</td>
  427. <td>Number of the first chunk you want/unwant/have/unhave. Chunk numbering starts at 0.</td>
  428. </tr>
  429. <tr>
  430. <td>2</td>
  431. <td><strong>Length</strong></td>
  432. <td>Varint</td>
  433. <td>1 = Just the <em>start</em> chunk, 2 = The <em>start</em> chunk and the next one, and so on. Omit this field to select all following chunks to the end of the Dat, including new chunks as they are added.</td>
  434. </tr>
  435. </tbody>
  436. </table>
  437. </div>
  438. <p>Here is an example showing typical use of have and want messages between two peers:</p>
  439. <img id="want-have-conversation-1" class="pagewidth" src="png/want_have_1.png"/>
  440. <img id="want-have-conversation-2" class="pagewidth" src="png/want_have_2.png"/>
  441. <h2 id="have-bitfield">Have bitfield</h2>
  442. <div>
  443. <p>If you have lots of little, non-contiguous ranges of data it can take a lot of have messages to tell your peer exactly what you have. There is an alternate form of the have message for this purpose. It is efficient at representing both contiguous and non-contiguous ranges of data.</p>
  444. <p>This form of the have message only has one field:</p>
  445. </div>
  446. <aside class="impl">
  447. <img class="icon" src="png/spanner_icon.png"/>
  448. <h3>Implementations</h3>
  449. <p class="lang">JS</p>
  450. <p class="lang">Rust</p>
  451. </aside>
  452. <div class="pagewidth msgfields">
  453. <table>
  454. <thead>
  455. <tr>
  456. <th>No.</th>
  457. <th>Name</th>
  458. <th>Type</th>
  459. <th>Description</th>
  460. </tr>
  461. </thead>
  462. <tbody>
  463. <tr>
  464. <td>3</td>
  465. <td><strong>Bitfield</strong></td>
  466. <td>Length-prefixed</td>
  467. <td>A sequence of contiguous and non-contiguous chunk ranges.</td>
  468. </tr>
  469. </tbody>
  470. </table>
  471. </div>
  472. <p>For example, let’s look at the chunks this peer has. Normally this would take 11 messages to represent:</p>
  473. <img class="pagewidth" src="png/run_length_encoding_bitfield.png"/>
  474. <p>Instead, divide the chunks into ranges where each range is either contiguous (all chunks present or none present), or non-contiguous (some chunks present). The ranges must be multiples of 8 chunks long.</p>
  475. <aside>In this case the ranges alternate between contiguous and non-contiguous, but this does not always happen. It is possible for contiguous ranges to be next to each other if one has all chunks present and the other has no chunks present.</aside>
  476. <img class="pagewidth" src="png/run_length_encoding_bitfield_segment.png"/>
  477. <p id="have-bitfield-range-types">Ranges are encoded as:</p>
  478. <ul>
  479. <li><strong>Contiguous.</strong> A single varint that contains sub-fields saying how many 8-chunk spans there are and whether all the chunks are present or absent.</li>
  480. <img src="png/run_length_encoding_contiguous_range.png"/>
  481. <li><strong>Non-contiguous.</strong> A varint saying how many 8-chunk spans the following bitfield represents (which is also its length in bytes), followed by the bitfield.</li>
  482. <img src="png/run_length_encoding_non_contiguous_range.png"/>
  483. </ul>
  484. <aside>The first byte in the bitfield represents the first 8-chunk span. The most significant bit of each byte represents the first chunk of each 8-chunk span.</aside>
  485. <p>Putting everything together, here are the bits used to encode the chunks this peer has:</p>
  486. <img id="have-bitfield-bits" class="pagewidth" src="png/run_length_encoding_bitfield_bits.png"/>
  487. <p>And here is how the final have message would appear on the wire:</p>
  488. <img id="have-bitfield-bytes" class="pagewidth" src="png/have_message_bytes.png"/>
  489. <h2 id="requesting-data">Requesting data</h2>
  490. <p>Once your peer has told you that they have a chunk you want, send a <strong>request</strong> message to ask them for it:
  491. </p><div class="pagewidth msgfields">
  492. <table>
  493. <thead>
  494. <tr>
  495. <th>No.</th>
  496. <th>Name</th>
  497. <th>Type</th>
  498. <th>Description</th>
  499. </tr>
  500. </thead>
  501. <tbody>
  502. <tr>
  503. <td>1</td>
  504. <td><strong>Index</strong></td>
  505. <td>Varint</td>
  506. <td>Number of the chunk to send back. This field must be present even when using the <em>bytes</em> field below.</td>
  507. </tr>
  508. <tr>
  509. <td>2</td>
  510. <td><strong>Bytes</strong></td>
  511. <td>Varint</td>
  512. <td>If this field is present, ignore the <em>index</em> field and send back the chunk containing this byte. Useful if you don’t know how big each chunk is but you want to seek to a specific byte.</td>
  513. </tr>
  514. <tr>
  515. <td>3</td>
  516. <td><strong>Hash</strong></td>
  517. <td>Varint</td>
  518. <td>0 = Send back the data in this chunk as well as hashes needed to verify it, 1 = Don’t send back the data in this chunk, only send the hashes.</td>
  519. </tr>
  520. <tr>
  521. <td>4</td>
  522. <td><strong>Nodes</strong></td>
  523. <td>Varint</td>
  524. <td>Used to request additional hashes needed to verify the integrity of this chunk. 0 = Send back all hashes needed to verify this chunk, 1 = Just send the data, no hashes. For other values that can be used to request specific hashes from the hash tree, see the <a href="https://github.com/pfrazee/DEPs/blob/dep-wire-protocol/proposals/0000-wire-protocol.md#block-tree-digest">Wire Protocol specification</a>.</td>
  525. </tr>
  526. </tbody>
  527. </table>
  528. </div>
  529. <p id="cancel-message">If you no longer want a chunk you requested, send a <strong>cancel</strong> message:</p>
  530. <div class="pagewidth msgfields">
  531. <table>
  532. <thead>
  533. <tr>
  534. <th>No.</th>
  535. <th>Name</th>
  536. <th>Type</th>
  537. <th>Description</th>
  538. </tr>
  539. </thead>
  540. <tbody>
  541. <tr>
  542. <td>1</td>
  543. <td><strong>Index</strong></td>
  544. <td>Varint</td>
  545. <td>Number of the chunk to cancel. This field must be present even when using the <em>bytes</em> field below.</td>
  546. </tr>
  547. <tr>
  548. <td>2</td>
  549. <td><strong>Bytes</strong></td>
  550. <td>Varint</td>
  551. <td>If this field is present, ignore the <em>index</em> field and cancel the request for the chunk containing this byte.</td>
  552. </tr>
  553. <tr>
  554. <td>3</td>
  555. <td><strong>Hash</strong></td>
  556. <td>Varint</td>
  557. <td>Set to the same value as the <em>hash</em> field of the request you want to cancel.</td>
  558. </tr>
  559. </tbody>
  560. </table>
  561. </div>
  562. <p>Cancel messages can be used if you preemptively requested a chunk from multiple peers at the same time. Upon receiving the chunk from the fastest peer, send cancel messages to the others.</p>
  563. <p id="data-message">When a peer has requested a chunk from you, send it to them with a <strong>data</strong> message:</p>
  564. <div class="pagewidth msgfields">
  565. <table>
  566. <thead>
  567. <tr>
  568. <th>No.</th>
  569. <th>Name</th>
  570. <th>Type</th>
  571. <th>Description</th>
  572. </tr>
  573. </thead>
  574. <tbody>
  575. <tr>
  576. <td>1</td>
  577. <td><strong>Index</strong></td>
  578. <td>Varint</td>
  579. <td>Chunk number.</td>
  580. </tr>
  581. <tr>
  582. <td>2</td>
  583. <td><strong>Value</strong></td>
  584. <td>Length-prefixed</td>
  585. <td>Contents of the chunk. Do not set this field if the request had <em>hash</em> = 1.</td>
  586. </tr>
  587. <tr>
  588. <td>3</td>
  589. <td><strong>Nodes</strong></td>
  590. <td>Length-prefixed</td>
  591. <td>
  592. <p>This field is repeated for each hash that the requester needs to verify the chunk’s integrity.</p>
  593. <table>
  594. <thead>
  595. <tr>
  596. <th>No.</th>
  597. <th>Name</th>
  598. <th>Type</th>
  599. <th>Description</th>
  600. </tr>
  601. </thead>
  602. <tbody>
  603. <tr>
  604. <td>1</td>
  605. <td><strong>Index</strong></td>
  606. <td>Varint</td>
  607. <td>Hash number.</td>
  608. </tr>
  609. <tr>
  610. <td>2</td>
  611. <td><strong>Hash</strong></td>
  612. <td>Length-prefixed</td>
  613. <td>32-byte <a href="#chunk-hash">chunk hash</a> or <a href="#parent-hash">parent hash</a>.</td>
  614. </tr>
  615. <tr>
  616. <td>3</td>
  617. <td><strong>Size</strong></td>
  618. <td>Varint</td>
  619. <td>Total length of data in chunks covered by this hash.</td>
  620. </tr>
  621. </tbody>
  622. </table>
  623. </td>
  624. </tr>
  625. <tr>
  626. <td>4</td>
  627. <td><strong>Signature</strong></td>
  628. <td>Length-prefixed</td>
  629. <td>64-byte ed25519 signature of the root hash corresponding to this chunk.</td>
  630. </tr>
  631. </tbody>
  632. </table>
  633. </div>
  634. <h1 id="files-and-folders" class="section"><span>Files and folders</span></h1>
  635. <p>Dat uses two coupled feeds to represent files and folders. The <strong>metadata</strong> feed contains the names, sizes and other metadata for each file, and its typically quite small even when the Dat contains a lot of data. The <strong>content</strong> feed contains the actual file contents. The metadata feed points to where in the content feed each file is located, so you only need to fetch the contents of files you are interested in.</p>
  636. <aside>Folders aren’t created explicitly. Instead, files have slash-separated names and all but the last path segment represents the folders that file is inside. Dat can’t represent an empty folder or remember UIDs, permission modes or modification dates on folders.</aside>
  637. <img class="pagewidth" src="png/files_folders_overview.png"/>
  638. <p>The first chunk of the metadata feed is always an <strong>index</strong> chunk. Check that the <em>type</em> field contains the word “hyperdrive”. If so, the <em>content</em> field is the public key of the content feed.</p>
  639. <div class="pagewidth msgfields">
  640. <table>
  641. <thead>
  642. <tr>
  643. <th>No.</th>
  644. <th>Name</th>
  645. <th>Type</th>
  646. <th>Description</th>
  647. </tr>
  648. </thead>
  649. <tbody>
  650. <tr>
  651. <td>1</td>
  652. <td><strong>Type</strong></td>
  653. <td>Length-prefixed</td>
  654. <td>What sort of data is contained in this Dat. For Dats using the concept of files and folders this is “hyperdrive”.</td>
  655. </tr>
  656. <tr>
  657. <td>2</td>
  658. <td><strong>Content</strong></td>
  659. <td>Length-prefixed</td>
  660. <td>32-byte public key of the content feed.</td>
  661. </tr>
  662. </tbody>
  663. </table>
  664. </div>
  665. <p>After the index all following chunks in the metadata feed are <strong>nodes</strong>, which store file metadata. Nodes have these fields:</p>
  666. <div id="node-fields" class="pagewidth msgfields">
  667. <table>
  668. <thead>
  669. <tr>
  670. <th>No.</th>
  671. <th>Name</th>
  672. <th>Type</th>
  673. <th>Description</th>
  674. </tr>
  675. </thead>
  676. <tbody>
  677. <tr>
  678. <td>1</td>
  679. <td><strong>Name</strong></td>
  680. <td>Length-prefixed</td>
  681. <td>Slash-separated path and filename. Always begins with a slash. For example: “/src/main.c”</td>
  682. </tr>
  683. <tr>
  684. <td>2</td>
  685. <td><strong>Value</strong></td>
  686. <td>Length-prefixed</td>
  687. <td>
  688. <p>If this field is present the file is being created or updated. These sub-fields give the details of the new or updated file:</p>
  689. <table>
  690. <thead>
  691. <tr>
  692. <th>No.</th>
  693. <th>Name</th>
  694. <th>Type</th>
  695. <th>Description</th>
  696. </tr>
  697. </thead>
  698. <tbody>
  699. <tr>
  700. <td>1</td>
  701. <td><strong>Mode</strong></td>
  702. <td>Varint</td>
  703. <td>
  704. <p>Unix permissions. In practice one of these two common values depending on whether the file is executable or not:</p>
  705. <img src="png/files_folders_mode_flags.png"/>
  706. <p>Security-sensitive bits such as setuid and setgid might also be set. When extracting files from a Dat to the filesystem you might consider not honoring these bits.</p>
  707. </td>
  708. </tr>
  709. <tr>
  710. <td>2</td>
  711. <td><strong>UID</strong></td>
  712. <td>Varint</td>
  713. <td>Unix user ID. Alternatively, set to 0 to not expose the user’s ID.</td>
  714. </tr>
  715. <tr>
  716. <td>3</td>
  717. <td><strong>GID</strong></td>
  718. <td>Varint</td>
  719. <td>Unix group ID. Alternatively, set to 0 to not expose the user’s group ID.</td>
  720. </tr>
  721. <tr>
  722. <td>4</td>
  723. <td><strong>Size</strong></td>
  724. <td>Varint</td>
  725. <td>Size of the file in bytes.</td>
  726. </tr>
  727. <tr>
  728. <td>5</td>
  729. <td><strong>Blocks</strong></td>
  730. <td>Varint</td>
  731. <td>Number of chunks the file occupies in the content feed.</td>
  732. </tr>
  733. <tr>
  734. <td>6</td>
  735. <td><strong>Offset</strong></td>
  736. <td>Varint</td>
  737. <td>Chunk number of the first chunk in the content feed.</td>
  738. </tr>
  739. <tr>
  740. <td>7</td>
  741. <td><strong>Byte offset</strong></td>
  742. <td>Varint</td>
  743. <td>Size in bytes of all chunks in the content feed before this file. 0 for the first file.</td>
  744. </tr>
  745. <tr>
  746. <td>8</td>
  747. <td><strong>Mtime</strong></td>
  748. <td>Varint</td>
  749. <td>Time the file was last modified. Number of milliseconds since 1 January 1970 00:00:00 UTC.</td>
  750. </tr>
  751. <tr>
  752. <td>9</td>
  753. <td><strong>Ctime</strong></td>
  754. <td>Varint</td>
  755. <td>Time the file was created. Number of milliseconds since 1 January 1970 00:00:00 UTC.</td>
  756. </tr>
  757. </tbody>
  758. </table>
  759. <p>If the <em>value</em> field is absent (and therefore none of the sub-fields above are set) the file previously existing with this <em>name</em> is now deleted.</p>
  760. </td>
  761. </tr>
  762. <tr>
  763. <td>3</td>
  764. <td><strong>Paths</strong></td>
  765. <td>Length-prefixed</td>
  766. <td>Index that helps to traverse folders more efficiently. <a href="#paths-index">See below</a>.</td>
  767. </tr>
  768. </tbody>
  769. </table>
  770. </div>
  771. <p>To find the latest version of a file, start from the end of the metadata feed and work backwards until you find a node with that file’s name. Even though files can be modified and deleted, previous versions can still be retrieved by searching back in the metadata feed.</p>
  772. <p>Here is an example showing how the <em>offset</em> and <em>blocks</em> fields refer to chunks in the content feed:</p>
  773. <img id="files-folders-feeds" class="pagewidth" src="png/files_folders_feeds.png"/>
  774. <h2 id="paths-index">Paths index</h2>
  775. <p>Scanning through the list of all files added, modified or deleted would be slow for Dats that contain lots of files or a long history. To make this faster, every node in the metadata feed contains extra information in the <strong>paths</strong> field to help traverse folders.</p>
  776. <aside class="impl">
  777. <img class="icon" src="png/spanner_icon.png"/>
  778. <h3>Implementations</h3>
  779. <p class="lang">JS</p>
  780. </aside>
  781. <img class="pagewidth" src="png/paths_index_storage.png"/>
  782. <p>To calculate a <em>paths</em> field, start by constructing a file hierarchy from the metadata feed:</p>
  783. <img id="paths-index-tree" src="png/paths_index_tree.png"/>
  784. <aside>
  785. <p>The first node is called node 0, which is stored in chunk 1 of the metadata feed.</p>
  786. <p>Node number = chunk number - 1</p>
  787. </aside>
  788. <p>For each file in the hierarchy, find the most recent entry for it in the metadata feed and remember the node number. For each folder, remember the highest node number among its children:</p>
  789. <img id="paths-index-versions" src="png/paths_index_versions.png"/>
  790. <p>Locate the file that was just added. Select that file and all its parent folders up to the root folder. Also select files and folders within those folders, but not their descendants. Ignore everything else.</p>
  791. <img id="paths-index-select" src="png/paths_index_select.png"/>
  792. <aside>In this example we are calculating the <em>paths</em> field for <strong>node 8</strong>, however the same calculation will have already been done for all the previous nodes as they were added.</aside>
  793. <p>Next, follow these steps to process the node numbers into bytes:</p>
  794. <img id="paths-index-encode" class="pagewidth" src="png/paths_index_encode.png"/>
  795. <p>So node 8 would appear in the metadata feed as:</p>
  796. <img src="png/paths_index_result.png"/>
  797. <p>The process for calculating the <em>paths</em> field after deleting a file is mostly the same as when adding a file:</p>
  798. <img id="paths-index-delete" class="pagewidth" src="png/paths_index_delete.png"/>
  799. <h1 id="future-of-dat" class="section"><span>Future of Dat</span></h1>
  800. <p>Dat was first released in 2013, which in terms of internet infrastructure is very recent. Parts of the protocol are still changing today to enable Dat to handle bigger datasets, more hostile network conditions and support new types of applications.</p>
  801. <p>This guide has described the Dat protocol as of January 2019. Here’s a brief summary of upcoming proposals to modify the Dat protocol in the near future:</p>
  802. <ul>
  803. <li>
  804. <p><strong><a href="https://github.com/datproject/planning#protocol-performance-and-features">Hyperdrive</a></strong> is the technical name of the files and folders system. Hyperdrive is going to be completely overhauled to make it faster for datasets containing millions of files. The new version will use a data structure called a prefix tree. There will also be refactoring changes so that files/folders and key/value databases use the same underlying storage system.</p>
  805. </li>
  806. <li>
  807. <p><strong><a href="https://pfrazee.hashbase.io/blog/hyperswarm">Hyperswarm</a></strong> is a new set of discovery mechanisms for finding other peers. It will replace the local network discovery and centralized DNS discovery mechanisms. It will also replace the BitTorrent distributed hash table mechanism that is in use today (but not documented in this guide).</p>
  808. <p>Hyperswarm is able to hole-punch through NAT devices on networks. This helps users on residential or mobile internet connections directly connect to each other despite not having dedicated IP addresses or being able to accept incoming TCP connections.</p>
  809. </li>
  810. <li>
  811. <p><strong><a href="https://www.datprotocol.com/deps/0008-multiwriter/">Multi-writer</a></strong> will allow Dats to be modified by multiple devices and multiple authors at the same time. Each author will have their own secret key and publish a Dat with their data in it. Multi-writer fuses all of these separate Dats into one “meta-Dat” that is a view of everyone’s data combined.</p>
  812. </li>
  813. <li>
  814. <p><strong><a href="https://noiseprotocol.org/">NOISE protocol</a></strong> is a cryptographic framework for setting up secure connections between computers on the internet. This will replace how handshakes and encryption currently work in the wire protocol.</p>
  815. <p>NOISE will fix weaknesses such as connections being readable by any eavesdropper who knows the Dat’s public key. It will allow connections to be authenticated to prevent tampering and also support forward secrecy so that past connections cannot be decrypted if the key is later stolen.</p>
  816. </li>
  817. </ul>
  818. <hr/>
  819. <p id="conclusion">This is the end of <em>How Dat Works</em>. We’ve seen all the steps necessary to download and share files using Dat. If you’d like to write an implementation then check out the <em><a href="https://datprotocol.github.io/book/">Dat Protocol Book</a></em> which offers guidance about implementation details.</p>
  820. <p>The focus of this guide has been on storing files, but this is just one use of Dat. The protocol is flexible enough to store arbitrary data that does not use the concept of files or folders. One example is <a href="https://www.datprotocol.com/deps/0004-hyperdb/">Hyperdb</a> which is a key/value database, but Dat can be extended to support completely different use cases too. Take a look at the formal <a href="https://www.datprotocol.com/deps/">protocol specifications</a> for more information.</p>