Novices Performing Miracles

    mqemitter-p2p

    0.1.0 • Public • Published

    mqemitter-p2p

    A P2P implementation of MQEmitter, based on HyperEmitter and a Merkle DAG

    HyperEmitter-powered MQEmitter.

    See MQEmitter for the actual API. The listen and connect function are exposed from the internal HyperEmitter.

    Install

    $ npm install mqemitter-p2p --save

    Example

    var fs = require('fs')
    var path = require('path')
    var schema = fs.readFileSync(path.join(__dirname, 'test.proto'))
    var p2p = require('./')
    var memdb = require('memdb')
    var assert = require('assert')
     
    var a = p2p({
      db: memdb(),
      schema: schema
    })
     
    var b = p2p({
      db: memdb(),
      schema: schema
    })
     
    var msg = {
      topic: 'hello',
      payload: null
    }
     
    a.listen(9001, 'localhost', function (err) {
      assert(!err)
      b.connect(9001, 'localhost', function (err) {
        assert(!err)
      })
    })
     
    a.emit(msg)
    b.on('hello', function (received, cb) {
      console.log(received)
      cb()
      assert.deepEqual(received, msg, 'msg matches')
      a.close(function (err) {
        assert(!err)
        b.close(function (err) {
          assert(!err)
          console.log('closed successfully')
        })
      })
    })

    License

    ISC

    Install

    npm i mqemitter-p2p

    DownloadsWeekly Downloads

    2

    Version

    0.1.0

    License

    ISC

    Last publish

    Collaborators

    • matteo.collina