p2p anarchist real-time communication protocol using append-only logs
p2p anarchist real-time communication protocol using append-only logs
If you know what scuttlebutt is, this is like a cheap fast real-time version for exchanging data.
var chatdb = require('kappa-chat')
var db = chatdb('./db')
/*
var msg = {
key: 'hexkeyofauthor',
seq: 14,
value: {
type: 'chat/text',
nick: 'noffle',
text: 'hello p2p world'
}
}
*/
db.on('message', function (msg) {
var content = msg.value
if (content.type !== 'chat/text') return
var nick = content.nick || 'anomymous'
console.log(nick + '> ' + content.text)
})
db.publish({
type: 'chat/text',
nick: 'foobar',
channel: '#testing',
text: 'hack the planet'
})
outputs
foobar> hack the planet
var chatdb = require('kappa-chat')
Create a new chat database. storage
is either a string (location on local disk
to store the db) or an instance of
random-access-storage.
Publish a message. Messages can be structured any way you want. You and your community can decide what works best for you, or you can discuss between multiple collectives to agree upon common formats that serve you well.
A common type
field can be useful for readily identifying the data. Here's an
example for an IRC-like textual chat message:
{
type: 'chat/text',
nick: 'noffle',
text: 'hello p2p world',
timestamp: 1526236798000
}
When a new p2p log entry is received, this event is emitted. An entry has the format
{
key: 'hexkeyofauthor',
seq: 14,
value: { // message
type: 'chat/text',
nick: 'noffle',
channel: '#testing',
text: 'hello p2p world'
}
}
key
is the message author's public cryto key as a hexidecimal string, and
seq
is the sequence number of the entry in their append-only log.
todo
A common type
field can be useful for readily identifying the data. Here's an
example for an IRC-like textual chat message:
{
type: 'chat/text',
nick: 'noffle',
text: 'hello p2p world',
timestamp: 1526236798000
}
With npm installed, run
$ npm install kappa-chat
ISC