cosmicrocks / gun-rs

non-wasm rust port of gun

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gun-rs

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

Deployed at https://gun-rs.iris.to (serves iris-messenger at the root)

Live stats: https://gun-rs.iris.to/stats

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

3/12/2021:

  • Gun basic API
  • CLI for running the server
  • Incoming websockets
  • Outgoing websockets (env PEERS=wss://some-server-url.herokuapp.com/gun)
  • Multicast (Iris messages seem not to propagate — size limit?)
  • In-memory storage
  • TLS support (env CERT_PATH and KEY_PATH)
  • Advanced deduplication of sync messages
  • Publish & subscribe
  • Disk storage
  • SEA (verification of signed data)

Issues

  • When multiple adapters are enabled, it sometimes gets stuck
  • User-space nodes (js: gun.user().get('something')) are relayed, but not properly retrieved and sent from memory (wrong format somehow)
  • Multicast doesn't relay large messages like Iris posts

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

About

non-wasm rust port of gun


Languages

Language:CSS 69.5%Language:JavaScript 17.6%Language:Rust 10.2%Language:HTML 2.7%Language:Dockerfile 0.0%Language:Procfile 0.0%