-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprotocol.ejs
More file actions
199 lines (155 loc) · 10.2 KB
/
Copy pathprotocol.ejs
File metadata and controls
199 lines (155 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
---
title: How the Hypercore Protocol Works
layout: layouts/base
css: css/pages/protocol.css
---
<main>
<div id="hypercore"><div id="hyperdrive"><div id="hyperswarm">
<h1>How the Hypercore Protocol Works</h1>
<nav>
<a id="core-link" href="#hypercore">Hypercore</a>
<a id="drive-link" href="#hyperdrive">Hyperdrive</a>
<a id="swarm-link" href="#hyperswarm">Hyperswarm</a>
</nav>
<section id="core">
<% include /bar-anim %>
<h2>Hypercore is a distributed append-only log</h2>
<p>
Hypercore comes with a secure transport protocol, making it easy to build fast and scalable peer-to-peer applications. Think lightweight blockchain crossed with BitTorrent.
</p>
<h3>Append-only logs?</h3>
<p>
If you are not familiar with append-only logs, they are basically just lists you can only append to. If you think about it in terms of normal array operations, it is a log where you can only call get(index), push(data) and retrieve the log length, but where you can never overwrite old entries.
</p>
<div class="videogif">
<video src="<%= rootPath %>videos/aol.mp4" autoplay loop muted playsinline></video>
</div>
<p>
Hypercore allows you to quickly distribute these kind of logs in a peer-to-peer fashion. Each peer can choose to download only the section of the log they are interested in, without having to download everything from the beginning.
</p>
<p>
Using append-only logs, Hypercore can easily generate compressed bitfields describing which portions of a log a peer has. This, among other things, helps make the replication protocol light and efficient.
</p>
<h3>Secured by Merkle trees and cryptography</h3>
<p>
Hypercore verifies log contents by building a Merkle tree using the BLAKE2b-256 hash function. Peers can also use this Merkle tree to only download the parts of the log they are interested in, and redistribute these parts to others.
</p>
<div class="videogif" style="height: 300px;">
<video src="<%= rootPath %>videos/merkle-trees.mp4" autoplay loop muted playsinline style="margin-top: -150px;"></video>
</div>
<p>
Merkle trees are widely used in many distributed systems. They are normally only used to verify static content, because when content changes the root of the tree changes as well. To support mutable datasets, Hypercore uses asymmetric cryptography to sign the root of the Merkle tree as data is appended to it.
</p>
<div class="videogif" style="height: 380px;">
<video src="<%= rootPath %>videos/growing-merkle-trees.mp4" autoplay loop muted playsinline style="margin-top: -100px;"></video>
</div>
<p>
Only the owner of the private key can append to the log. But one Hypercore is rarely used on its own -- more powerful, multi-user data structures can be created by combining multiple cores. Hypercore's main purpose is to be a building block in other things.
</p>
</section>
<section id="drive">
<% include /bar-anim %>
<h2>Hyperdrive is a P2P filesystem</h2>
<p>
Hyperdrive is designed to help you share files quickly and safely, directly from your computer.
</p>
<p>
Hyperdrive is built using Hypercores. Using an append-only index you can find only the files you are interested from a large drive in milliseconds -- all P2P.
</p>
<p>
By default, readers only download the portions of files they need, on demand. You can stream media from friends without jumping through hoops! Seeking is snappy and there's no buffering.
</p>
<p>
If you want to learn more about the code you can see the Node.js implementation in the <a href="https://github.com/mafintosh/hyperdrive">GitHub repository</a>
</p>
<p>
If you want to download or share filesystems, we suggest you read on and try out the daemon.
</p>
<h3>How does Hyperdrive work?</h3>
<p>
Hyperdrive indexes filenames into a Hypercore. To avoid having to scan through this entire Hypercore when you want to find a specific file or folder, filenames are indexed using an append-only hash trie, which we call Hypertrie. The hash trie basically functions as a fast append-only key value store with listable folders.
</p>
<div class="videogif">
<video src="<%= rootPath %>videos/trie.mp4" autoplay loop muted playsinline style="margin-top: -100px;"></video>
</div>
<p>
If you are looking for a simple database abstraction on top of Hypercore you can also use Hypertrie standalone, outside of Hyperdrive. In you want to learn more about how to use it, we suggest you look at the <a href="https://github.com/mafintosh/hypertrie">Hypertrie repository</a>
</p>
<p>
Since it builds on top of the append-only log, it inherits the same guarantees of every change being versioned by default, making it easy to see historical changes and prevent accidental data loss.
</p>
<p>
In addition to the Hypertrie, which we refer to as the metadata log, Hyperdrive uses another Hypercore to store the binary file content of each file you insert. This dual-log design makes it easy to replicate or watch only the metadata log, without content, if that is what you are interested in.
</p>
<p>
Each entry in the Hypertrie links to the content log to signal where a file's binary data starts and ends. Additionally, the entry contains all the normal POSIX data you'd be interested in, such as modification time, creation time, file modes, etc.
</p>
<h3>Mounts</h3>
<p>
For better composability and collaboration, an entry can also link to a completely different Hyperdrive or Hypercore. We call this feature mounts. Even though it's ostensibly simple, it can be used to build powerful collaborative features.
</p>
<div class="videogif">
<video src="<%= rootPath %>videos/metadata-and-content-and-mounts.mp4" autoplay loop muted playsinline style="margin-top: -100px;"></video>
</div>
<p>
Internally we have been using Hyperdrive mounts for a concept we call "groupware", where each user mounts their own drive inside a single shared one, then applications render multi-user views over the group drive. The groupware pattern can be used to build lightweight, Dropbox-like applications, among others.
</p>
<p>
We are always exploring new ways to enhance Hyperdrive! If you are interested in collobarating with us always feel free to to open an issue on <a href="https://github.com/mafintosh/hyperdrive">Github</a>, reach out at <a href="https://twitter.com/hypercoreproto">@hypercoreproto</a> or join our <a href="https://discord.com/invite/ga5hxGf">Discord</a>.
</p>
</section>
<section id="swarm">
<% include /bar-anim %>
<h2>Hyperswarm is a DHT for the home</h2>
<p>
Hyperswarm combines a <a href="https://github.com/hyperswarm/dht">Kademlia-based distributed hash table (DHT)</a> for global discovery with MDNS to discover peers on local networks.
</p>
<p>
Hyperswarm is part of the Hypercore protocol but can be used standalone as well. You can learn more on the <a href="https://github.com/hyperswarm">Hyperswarm Github organisation</a> and in the main <a href="https://github.com/hyperswarm/hyperswarm">Node.js implementation repository</a>
</p>
<h3>A Kademlia DHT</h3>
<p>
As with many P2P projects, Hyperswarm uses a DHT to discover peers on the internet. Hypercore maintains a hash of its public key, called a "discovery key", that is used as the topic with which peers share their IPs and ports to discover each other.
</p>
<p>
Hypercore comes with a capability system wherein each peer has to verify they know the correct public key before they start sharing data. Even if you know a Hypercore's discovery key, you must also know the public key in order to download data from peers.
</p>
<div class="videogif">
<video src="<%= rootPath %>videos/dht.mp4" autoplay loop muted playsinline style="margin-top: -90px;">
</div>
<p>
The DHT used in Hyperswarm is based on Kademlia, a UDP-based DHT which is used by many projects, including BitTorrent. You can learn a lot more about Kademlia in <a href="https://pdos.csail.mit.edu/~petar/papers/maymounkov-kademlia-lncs.pdf">the Kademlia paper</a>.
</p>
<p>
DHTs scale well in general, but are notoriously hard to work with. Hyperswarm employs a series of heuristics to answer queries quickly and garbage collect stale data as fast as possible.
</p>
<p>
As a general note, most DHTs (Hyperswarm included) generally expose routing information such as your IP/port to help route requests. Privacy-preserving DHTs are an active research area by many participants in the P2P ecosystem.
</p>
<h3>Distributed Holepunching</h3>
<p>
Ideal P2P networks should be able to connect any two peers together, wherever they are. In practice, this is a challenge due to firewalls which reject incoming connections and NATs which mask your IP. To help “break through” firewalls, a technique called UDP holepunching is used.
</p>
<p>
Traditionally UDP holepunching requires the use of centralised servers that are preknown by each peer in a network.
</p>
<p>
Hyperswarm expands on holepunching by making it a first-class feature: any peer in the DHT can help you holepunch to any other peer that it knows about.
</p>
<div class="videogif" style="height: 390px;">
<video src="<%= rootPath %>videos/dht-holepunching.mp4" autoplay loop muted playsinline style="margin-top: -60px;">
</div>
<p>
After finding the relevant peers, Hyperswarm utilises the UTP transport protocol, to make reliable connection streams between peers. For non-holepunching cases, TCP is used as well.
</p>
<p>
Importantly, Hyperswarm connections are unencrypted -- encryption must be added separately. As an example, once Hyperswarm has established a connection, Hypercore wraps it in a <a href="https://noiseprotocol.org/">Noise protocol</a> stream to add end-to-end encryption.
</p>
</section>
<nav>
<a id="core-link" href="#hypercore">Hypercore</a>
<a id="drive-link" href="#hyperdrive">Hyperdrive</a>
<a id="swarm-link" href="#hyperswarm">Hyperswarm</a>
</nav>
</div></div></div>
</main>