straggler
aggregate text streams
because text is a universal interface
All nodes are authenticated with public key pairs.
example
First generate a quick auth file with keypairs for a reader and a writer:
$ straggler -g > hub.json
$ straggler -g > viewer.json
$ straggler -g > writer.json
$ echo "[`straggler -e viewer.json -r beep`,\
`straggler -e writer.json -w beep`]" > auth.json
then start up a straggler hub:
$ straggler -k hub.json -a auth.json -l 9600
Now read data from the writer:
$ straggler -k viewer.json -r http://localhost:9600/beep
and write data from the writer:
$ echo beep boop | straggler -k writer.json -w http://localhost:9600/beep
Now you should see "beep boop" appear on the viewer command.
api example
First generate keypairs for your hub, viewer, and writer rsa-json:
$ rsa-json > hub.json
$ rsa-json > viewer.json
$ rsa-json > writer.json
Create a hub and bind it to an http server:
var straggler = ;var st = ;var hub = st;var http = ;var server = http;server;
Write a viewer.js
program to read messages from the writer:
var straggler = ;var st = ;var rs = st;rs;
Write a writer.js
program to write messages to the hub:
var straggler = ;var st = ;var ws = st;ws;
Run the hub, the viewer, and the writer programs:
$ node hub.js &
[1] 18835
$ node viewer.js &
[2] 18840
$ node writer.js
beep boop
$
usage
usage:
straggler -k keys.json -r URI
Pipe URI to stdout.
straggler -k keys.json -w URI
Pipe stdin to URI.
straggler -k keys.json -l PORT -a authorized.json
Create an http server listening on PORT given an authorized key list from
`authorized.json`.
straggler -g > keys.json
Generate a keypair for use with `-k`.
straggler -e keys.json [{-r,-w,--rw} NAME, ...]
Generate an entry for the authorized.json file with permissions
(`-r`, `-w`, or `--rw`) for each NAME.
methods
var straggler =
var st = straggler(keys)
Create a new stragger instance st
from keys
, a public/private keypair
generated by rsa-json.
var rw = st.createStream(uri, cb)
Create a duplex stream rw
at uri
.
cb(err, rw)
fires when the stream is ready or an error occurs.
rw
emits an 'open'
event when the stream is ready and buffers writes until
the stream is fully opened.
var ws = st.createWriteStream(uri, cb)
Create a writable stream ws
at uri
.
cb(err, ws)
fires when the stream is ready or an error occurs.
ws
emits an 'open'
event when the stream is ready and buffers writes until
the stream is fully opened.
var rs = st.createReadStream(uri, cb)
Create a readable stream rs
at uri
.
cb(err, ws)
fires when the stream is ready or an error occurs.
rs
emits an 'open'
event when the stream is fully opened.
var hub = st.createHub(authorized)
Create a straggler hub
instance to hook into an http server given
authorized
, an array of public key and permissions data.
Hubs are always authorized to read and write from themselves.
In this example authorized
data, the first key can write to the '/beep'
uri
and the second key can read from the '/beep'
uri. "write"
and "read"
entries are arrays of paths that may be written to or read from respectively
according to each public key.
Records can have both "read"
and "write"
entries.
When "read"
or "write"
is true
instead of an array, keys can read or write
respectively to all streams.
hub.handle(req, res)
Handle a request from a (req, res)
pair from an http server.
hub.test(url)
Test a req.url
string, returning the handler that should fire or undefined
if the route doesn't match anything.
install
With npm do:
npm install straggler
license
MIT