diff --git a/protocols/gun.md b/protocols/gun.md index 94d0a02..64f5841 100644 --- a/protocols/gun.md +++ b/protocols/gun.md @@ -1,40 +1,44 @@ -# Gun +# GUN -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. +GUN is a distributed database with a graph structure. It includes a library of tools for merging conflicting data and handling routing, security, and storage. -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. +In GUN's graph store, entries are [JSON objects under UUID keys](https://gun.eco/docs/Porting-GUN). + +Data is stored in the browser by default, with backup "superpeers" to ensure persistence. Peers connect to other peers, and choose what data to synchronize and persist. ### Identity -Gun's SEA module provides the capability to create a [public/private keypair](https://github.com/amark/gun/wiki/Auth) for a user. +GUN's SEA (Security, Encryption, Authorization) module provides the capability to create a [public/private keypair](https://github.com/amark/gun/wiki/Auth) for a user. ### Network structure -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. +[DAM](https://gun.eco/docs/DAM) (Daisy-chain ad-hoc mesh-network) is the message [routing](https://gun.eco/docs/Routing) algorithm used by GUN to sync data between peers. DAM's API allows for the swapping out of transport layers (websockets, WebRTC, multicast UDP etc). -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. +When a peer puts something in a graph, a message is sent to the network and other peers that have subscribed to that data pick it up and update their state. Those who are offline will eventually receive those updates. -### Data +A proposed future evolution of the routing protocol is called [AXE](https://web.stanford.edu/~nadal/A-Decentralized-Data-Synchronization-Protocol.pdf). It cuts off unnecessary connections, includes a DHT, and has a token for monetization through bandwidth-based payments. -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. +### Data Storage + +Peers subscribe to the data they need and the network retrieves it from any peer (including browsers, where GUN stores data in localStorage). Running always-online peers, such as a "superpeer", is recommended for most applications to ensure availability of data when most browser-based peers may be offline. A superpeer is an IP addressable machine running node.js that persists data to disk. [RAD](https://gun.eco/docs/RAD), GUN's storage adaptor, saves data to disk using a radix tree. Peers connect to graphs relevant to their application's logic. There is no universally shared graph across the network. -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. +GUN uses a CRDT (Conflict-free Replicated Data Type) to merge data. Conflicts are handled by a [conflict resolution algorithm](https://gun.eco/docs/Conflict-Resolution-with-Guns) that uses lexical sort. GUN is eventually consistent, meaning that peers will eventually converge upon the last updated value. -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. +GUN focuses on mutability by not using an append-only log, which implements updates, insertions, and deletion as a layer on top. [Deletion](https://stackoverflow.com/questions/37758618/how-to-delete-data-in-gun-db) in GUN works by overwriting bytes with `null`, or by de-referencing portions of a graph. #### Filtering -There is a [GraphQL](https://github.com/brysgo/graphql-gun) API for the gun p2p graph database. +There is a [GraphQL](https://github.com/brysgo/graphql-gun) API for the gun p2p graph database. SQL and Mango (MongoDB) queries were available in the past, but deprecated. ### Privacy and Access Control -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. +Privacy and access control can be built on top of the GUN database 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. -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). +Cryptographic keypairs 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). -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. +Iris, a decentralized social network building on GUN, has a [library](https://github.com/irislib/iris-lib) for end-to-end encrypted chat channels and private contact list management. ### Interoperablity @@ -49,16 +53,19 @@ Plugins, such as backup storage on centralized databases or file systems, can be ### Monetization -The GUN protocol is developed by a VC-funded company. +The GUN protocol is developed by a [VC-funded company](https://era.eco/#step1), which funds the development of Iris as well. Business models include consulting and integrations. Future business models include a proposed paid service on AXE, a blockchain-based tokenized bandwidth incentive network. ### Implementations -- [HackerNoon](https://hackernoon.com/state-of-hacker-noon-2019-2020-8w1ls3axx) integrated Gun for annotations +GUN is used for p2p chat/social apps, encrypted video conferencing, realtime GPS tracking, and AR/VR multiplayer games, among other applications. + +- [Internet Archive](https://news.ycombinator.com/item?id=17685682) uses GUN for their [dWeb library](https://github.com/internetarchive/dweb-transports) metadata +- [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 +- [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 GUN for messaging +- [Iris](https://irislib.github.io/), is a web-of-trust based social network built on GUN ### Related