#graph #multicast #websockets #distributed #port #pure

bin+lib gundb

Distributed graph database that syncs over websockets and multicast

2 releases

0.2.1 May 16, 2022
0.2.0 May 15, 2022
0.1.1 Jan 21, 2022
0.1.0 Jan 21, 2022

#47 in WebSocket

47 downloads per month

MIT license

8.5MB
6K SLoC

JavaScript 4.5K SLoC // 0.1% comments Rust 1.5K SLoC // 0.1% comments

Gun-rs

Pure Rust implementation of Gun.js. For a wasm version, check out gun-rs-wasm.

Iris-messenger uses the gun-rs node at wss://gun-rs.iris.to/gun

Why?

  • Rust can be compiled into high-performing native binaries on many platforms, including embedded systems.
  • Maintaining and contributing to the codebase is easier than in Gun.js. Gun.js doesn't have compilation or minification steps, and the code is kind of manually minified 😄

Use

Install Rust first.

Gun relay

cargo install gundb
gundb start

Gun library

use gundb::{Node, NodeConfig};
use gundb::types::GunValue;
let mut db = Node::new_with_config(NodeConfig {
    outgoing_websocket_peers: vec!["wss://some-server-to-sync.with/gun".to_string()],
    ..NodeConfig::default()
});
let mut sub = db.get("greeting").on();
db.get("greeting").put("Hello World!".into());
if let GunValue::Text(str) = sub.recv().await.unwrap() {
    assert_eq!(&str, "Hello World!");
}

Status

15/5/2022:

  • Gun basic API
  • CLI for running the server
  • Incoming websockets
  • Outgoing websockets (env PEERS=wss://some-server-url.herokuapp.com/gun)
  • Multicast (currently size limited to 65KB — large photos in messages will not sync over it)
  • In-memory storage
  • TLS support (env CERT_PATH and KEY_PATH)
  • Advanced deduplication of network messages
  • Publish & subscribe (network messages only relayed to relevant peers)
  • Disk storage (sled.rs)
  • Hash verification for content-addressed data (db.get('#').get(data_hash).put(data))
  • Signature verification of user data (db.get('~' + pubkey).get('profile') ...)
  • Encryption & decryption (usually done on the client side in js, like iris private messaging)

Issues

  • Multicast doesn't relay large messages like Iris posts with photos

Develop

cargo install cargo-watch
RUST_LOG=debug cargo watch -x 'run -- start'

Run on Heroku

heroku create --buildpack emk/rust
git push heroku master

or:

Deploy

Dependencies

~16–26MB
~573K SLoC