Skip to content

Instantly share code, notes, and snippets.

View hackergrrl's full-sized avatar
🌱

Kira hackergrrl

🌱
View GitHub Profile
// ------------------ KV ------------------
// API:
// - put
// - get
// EVENTS:
// - new value for key listened to
// id view
// requires 'msg.links' being populated to point to old version
@hackergrrl
hackergrrl / integration.md
Created September 13, 2018 17:15
osm-p2p-syncfile integration

syncfile integration

The new syncfile module is called osm-p2p-syncfile. It manages a specially formatted tarball that stores media blobs as well as a P2P database (currently [osm-p2p-db][]).

basic usage

Desktop and mobile will both need to open a syncfile (new or existing) and sync the locally running database with it. This'll probably look something like

var Syncfile = require('osm-p2p-syncfile')

I'm not well versed with Matrix, so please let me know where I've erred.

My understanding is that Matrix is a federated chat protocol, using both server-to-server and server-to-client connections for moving messages around. As I understand it, chat data can be cached on clients, but fundamentally lives on the servers, which host anywhere between 1 and maybe 1000s of users.

Cabal is peer-to-peer, in the sense that there is no server/client distinction. Any peer currently has a full copy of chat history, and seeks out other peers in the cabal to send and receive new messages to. This means that nobody has to choose a server to join / entrust their identity to: it lives on your computer as your private/public keypair. Cabal is really just a database that anybody with the shared key can append new data to. Peers sync any new data around until everyone has the same eventual state. The clients (cabal-desktop, etc) scan everyone's append-only feed of messages to build a view of chat history for each channel.

Ther

var batch = [
{type: 'put', key: `metadata/${channel}`, value: metadata},
{type: 'put', key: key, value: m}
]

osm-p2p-db vs kappa-osm

NOTE: time for spatial indexing was not included in the benchmark, since kappa-osm doesn't implement it yet.

5000 random documents

DB Insert Index Replicate
osm-p2p-db 6018 ms 7956 ms 29414 ms
var hyperdb = require('hyperdb')
var hindex = require('hyperdb-index-level')
var level = require('level')
var ram = require('random-access-memory')
var db = hyperdb(ram, { valueEncoding: 'json' })
var lvl = level('./index')
var idx = hindex(db, lvl, processor)
var alice = hyperdb(ram, { valueEncoding: 'json' })
var ram = require('random-access-memory')
var hyperdb = require('hyperdb')
var alice = hyperdb(ram, { valueEncoding: 'json' })
alice.put('foo/bar', 'baz', function () {
alice.put('foo/2', { some: 'json' }, function () {
var bob = hyperdb(ram, alice.key, { valueEncoding: 'json' })
bob.ready(function () {
alice.authorize(bob.local.key, function () {
tape('unauthorized writer doing a put after replication', function (t) {
t.plan(1)
var a = create.one()
a.ready(function () {
var b = create.one(a.key)
b.ready(function () {
replicate(a, b, function () {
b.put('foo', 'bar', function (err) {
t.error(err)
})