ecosistema-social-decentral.../protocols/gun.md

77 lines
4.6 KiB
Markdown
Raw Normal View History

2020-06-09 23:30:21 +02:00
# Gun
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Gun is a distributed database with a graph structure. Related libraries include a constellation of tools for merging conflicting data and handling routing and security.
2020-04-26 19:10:06 +02:00
2020-06-10 06:58:27 +02:00
In GunDB's graph store, entries are [JSON objects under UUID keys](https://gun.eco/docs/Porting-GUN). Data is stored in browser localStorage by default, with backup "supernode" servers to ensure persistence. Peers connect to other peers, and choose what data to synchronize and persist.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
### Identity
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Gun's SEA module provides the capability to create a [public/private keypair](https://github.com/amark/gun/wiki/Auth) for a user.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
### Network structure
2020-04-26 19:10:06 +02:00
2020-06-10 06:58:27 +02:00
Gun transfers data between peers. When a client puts something in a graph, a message is sent to the network and other clients that have subscribed to that data pick it up and update their state. Those who are offline will eventually receive those updates.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Gun uses a flooding algorithm for message propagation, called [DAM](https://gun.eco/docs/DAM) (Daisy-chain ad-hoc mesh-network). DAM's API allows for the swapping out of transport layers (websockets, WebRTC, etc). A proposed future [routing](https://gun.eco/docs/Routing) protocol, the [AXE protocol](https://web.stanford.edu/~nadal/A-Decentralized-Data-Synchronization-Protocol.pdf), includes a mechanism for monetization through bandwidth-based payments.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
### Data
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Gun saves data two ways, in a client browser's localStorage, and through [RAD](https://gun.eco/docs/RAD), a storage adaptor that stores data on disk using a radix tree. Clients subscribe to the data they need from the "superpeer", a persistent node storing data on disk that should be run with most applications to ensure availability of data when other browser-based peers are offline. Superpeers are servers running node.js and persisting data on disk. Clients may serve the data they have to other clients as well.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Peers connect to graphs relevant to their application's logic. There is no universally shared graph across the network.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
GunDB uses CRDTs (Conflict-free Replicated Data Types). Conflicts are handled by a [conflict resolution algorithm](https://gun.eco/docs/Conflict-Resolution-with-Guns) that uses lexical sort. Gun is eventually consistent, not strongly consistent, meaning that peers will eventually converge upon the last updated value.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Gun focuses on mutability by not using an append-only CRDT, instead allowing insertion and deletion into the graph. [Deletion](https://stackoverflow.com/questions/37758618/how-to-delete-data-in-gun-db) works by inserting `null` at the deleted node, de-referencing it.
2020-04-26 19:10:06 +02:00
#### Filtering
2020-06-09 23:30:21 +02:00
There is a [GraphQL](https://github.com/brysgo/graphql-gun) API for the gun p2p graph database.
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
### Privacy and Access Control
2020-04-26 19:10:06 +02:00
2020-06-09 23:30:21 +02:00
Privacy and access control can be built on top of GunDB's graph by encrypting data for the intended user. Gun's encryption utilities, [SEA](https://gun.eco/docs/SEA) (Security, Encryption, and Authorization), intend to make it easier to add private space to applications.
2020-05-18 02:40:45 +02:00
2020-06-09 23:30:21 +02:00
For access control, cryptographic keys are assigned to roles, groups, or data points. This information is either used to derive a shared ECDH secret to decrypt (read), or to load collaborative multi-writer edits (signed).
2020-05-18 02:40:45 +02:00
2020-06-09 23:30:21 +02:00
Iris, a decentralized social network building on Gun, has a [library](https://github.com/irislib/iris-lib) for encrypted GUN channels and contact list management.
2020-06-01 00:30:15 +02:00
2020-06-08 20:40:05 +02:00
### Interoperablity
2020-06-01 00:30:15 +02:00
2020-06-08 20:40:05 +02:00
Plugins, such as backup storage on centralized databases or file systems, can be used to extend GUN.
2020-06-01 00:30:15 +02:00
2020-05-18 02:40:45 +02:00
### Scalability
### Metrics
2020-06-08 20:40:05 +02:00
- 11K+ [github](https://github.com/amark/gun) stars
- 10M ~ 30M monthly [downloads](https://www.jsdelivr.com/package/npm/gun)
2020-06-01 00:30:15 +02:00
2020-06-09 23:30:21 +02:00
### Monetization
The GUN protocol is developed by a VC-funded company.
2020-06-06 01:44:46 +02:00
### Implementations
2020-06-01 00:30:15 +02:00
2020-06-09 23:30:21 +02:00
- [HackerNoon](https://hackernoon.com/state-of-hacker-noon-2019-2020-8w1ls3axx) integrated Gun for annotations
- [Meething](https://meething.space/) is a Mozilla backed secure & decentralized video conferencing that uses GUN
- [Party](https://party.lol/), an encrypted messaging browser extension, uses Gun
- [Notabug](https://notabug.io/t/notabug/comments/59382d2a08b7d7073415b5b6ae29dfe617690d74/welcome-to-notabug), a decentralized Reddit clone, uses Gun
- [DTube](https://d.tube/) uses GunDB for messaging
- [Iris](https://irislib.github.io/), a web-of-trust based social network, is built on Gun
### Related
Comparisons can be made to other databases designed for p2p use cases:
[OrbitDB](https://github.com/orbitdb/orbit-db) - see under [IPFS.md](IPFS.md)
[HyperDB](https://github.com/mafintosh/hyperdb) - see under [hypercore.md](hypercore.md)
[KappaDB](https://github.com/kappa-db)
2020-06-08 20:40:05 +02:00
### Links
2020-06-09 23:30:21 +02:00
[Site](gun.eco)
[Documentation Clarification](https://github.com/amark/gun/issues/597)