Skip to content

Instantly share code, notes, and snippets.

View AljoschaMeyer's full-sized avatar

Aljoscha Meyer AljoschaMeyer

View GitHub Profile
// A sketch for building up mergeable monoids (mms) from component mms.
// Status: A quick sketch of low quality in terminology, code and presentation...
// A *mergeable monoid* (*mm*) is a regular monoid (a carrier set S, an associative
// concatenation function + (S, S) -> S, and a neutral element e:S) together with
// a *conflict detection function* cdf (S, S) -> bool that returns true if
// s1 + s2 == s2 + s1 (i.e. if there is no merge conflict), false otherwise.
const canonic_cdf = (concat) => (s1, s2) => (concat(s1, s2) === concat(s2, s1));
// The cdf can be more efficient than actually performing that test, e.g. for a
@AljoschaMeyer
AljoschaMeyer / leyline-replication-design-notes.md
Last active January 22, 2019 09:54
Design notes for a replication mechanism on top of https://github.com/AljoschaMeyer/leyline-core

Design notes on leyline's default replication mechanism

First things first, this replication mechanism is not mandatory for interoperability of leyline-based applications. How a certain program got its data is fairly irrelevant, it only matters that the data is in the correct format. So this design is just one of many possible replication mechanisms. But realistically speaking, the default mechanism will be used by a vast majority of peers, and may end up as a de-facto standard for interoperable data replication. Few people will build their own carried-pidgeon based system.

The replication mechanism is fully decentralized and conceptually divided into five distinct layers:

  • creation of bidirectional, encrypted communication channels between two peers
  • a peer sampling service building a random-ish overlay among all leyline peers
  • a topology layer to prioritize connections between peers that want to exchange data
  • efficient exchange of leyline-core logs
#[cfg(test)]
extern crate quickcheck;
#[cfg(test)]
extern crate rand;
use std::collections::BTreeSet;
/// Find the power of two <= the given number (`None` for 0).
fn prev_power_of_two(n: u64) -> Option<u64> {
if n == 0 {
@AljoschaMeyer
AljoschaMeyer / 001.dot
Created October 22, 2018 21:02
A few graphs for the merkle tree discussion on ssb
digraph G {
rankdir = TB;
node [shape=box];
m0[shape=oval];
m2[shape=oval];
m4[shape=oval];
m6[shape=oval];
subgraph _1 {
extern crate ssb_legacy_msg_data;
extern crate ssb_multiformats;
use ssb_legacy_msg_data::{
StringlyTypedError,
LegacyF64,
Serialize,
Deserialize,
Deserializer,
de::{
@AljoschaMeyer
AljoschaMeyer / cargo.toml
Created March 12, 2018 16:51
Example of statically typed messages.
[package]
name = "demo-ssb-client"
version = "0.1.0"
authors = ["AljoschaMeyer <mail@aljoscha-meyer.de>"]
[dependencies]
tokio = "0.1.3"
futures = "0.1.18"
sodiumoxide = "0.0.16"
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate tokio;
extern crate futures;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_keyfile;
extern crate ssb_common;
extern crate ssb_client;
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate tokio;
extern crate futures;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_keyfile;
extern crate ssb_common;
extern crate ssb_client;
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate tokio;
extern crate futures;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_keyfile;
extern crate ssb_common;
extern crate ssb_client;
#![feature(try_from)]
#![feature(ip_constructors)]
extern crate tokio;
extern crate futures;
extern crate sodiumoxide;
extern crate secret_stream;
extern crate ssb_keyfile;
extern crate ssb_common;
extern crate ssb_client;