straggler

1.1.0 • Public • Published

straggler

aggregate text streams

because text is a universal interface

All nodes are authenticated with public key pairs.

build status

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 = require('straggler');
var st = straggler(require('./hub.json'));
var hub = st.createHub(require('./authorized.json'));
 
var http = require('http');
var server = http.createServer(function (req, res) {
    hub.handle(req, res);
});
server.listen(5000);

Write a viewer.js program to read messages from the writer:

var straggler = require('straggler');
var st = straggler(require('./viewer.json'));
var rs = st.createReadStream('http://localhost:5000');
rs.pipe(process.stdout);

Write a writer.js program to write messages to the hub:

var straggler = require('straggler');
var st = straggler(require('./writer.json'));
var ws = st.createWriteStream('http://localhost:5000');
ws.end('beep boop\n');

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 = require('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.

[
  {
    "key": "MIGRAoGJAbOh2SZ1XYOLjMqh0cKyy9TENl+eWXrTQEdhjIpLe3toSG0Fhzlxtvg/jDz7I1MKrloqIxyfmLVhNs5CXEmiYWhvNcrXQG6FPNeUlGd5yp0JHF75LJkN2Ai4sG98EJvdaFrGFp5MPPycSdWtv2dX/mtaHWWmoAi2w+vPENE7T5SH4+XkWywY6xkCAwEAAQ==",
    "write": [ "beep" ]
  },
  {
    "key": "MIGQAoGIcDhdhdKVbmskZzGrhshqB2J5uq02DU18+OMlp4XN5cor0K98RTnc0TB6pvKinrtwx7/UMY4Zs+u/GZUcukoDmCgRkSnLV0pQO0EJMgx9Yok4ghTcM0smQgtWWe6H38ExKvOFqNcWJeKV3CwqSU/BJF/EeU1iH+p6MeF5mPGuMtmXmNfqqFgQ5wIDAQAB",
    "read": [ "beep" ]
  }
]

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

Readme

Keywords

none

Package Sidebar

Install

npm i straggler

Weekly Downloads

2

Version

1.1.0

License

MIT

Last publish

Collaborators

  • nopersonsmodules