# munro

> p2p live streaming protocol

Latest version **0.1.1** (published 2016-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install munro
pnpm add munro
yarn add munro
bun add munro
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2016-01-19 |
| First published | 2016-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | piedshag |
| Maintainers | piedshag |

## Links

- npm: https://www.npmjs.com/package/munro
- Repository: https://github.com/piedshag/munro
- Issues: https://github.com/piedshag/munro/issues
- npm.io page: https://npm.io/package/munro

## Dependencies (10)

- [debug](https://npm.io/package/debug.md) ^2.2.0
- [bencode](https://npm.io/package/bencode.md) ^0.7.0
- [bitfield](https://npm.io/package/bitfield.md) ^1.1.2
- [duplexify](https://npm.io/package/duplexify.md) ^3.4.2
- [flat-tree](https://npm.io/package/flat-tree.md) ^1.3.0
- [buffer-equals](https://npm.io/package/buffer-equals.md) ^1.0.3
- [end-of-stream](https://npm.io/package/end-of-stream.md) ^1.1.0
- [protocol-buffers](https://npm.io/package/protocol-buffers.md) ^3.1.4
- [sodium-signatures](https://npm.io/package/sodium-signatures.md) ^1.1.0
- [length-prefixed-stream](https://npm.io/package/length-prefixed-stream.md) ^1.4.0

## Recent versions

- 0.1.1 (latest) — 2016-01-19
- 0.1.0 — 2016-01-19
- 0.0.1 — 2016-01-18

## README

# munro
a p2p live streaming protocol inspired by [ppspp](https://tools.ietf.org/html/rfc7574) and named after [munro](https://tools.ietf.org/html/rfc7574#section-6.1.2.1). The protocol is completely transport agnostic so it will work wherever you put it.

[![travis](https://travis-ci.org/piedshag/munro.svg?branch=master)](https://travis-ci.org/piedshag/munro)

```
npm install munro
```

## Usage

First someone must create some data

``` js
var munro = require('munro')
var disc = require('discovery-channel')()
var net = require('net')

var mro = munro()
mro.append('hello')
mro.append('world')

var server = net.createServer(function (socket) {
  socket.pipe(mro.peerStream()).pipe(socket)
})

disc.add(mro.id.slice(0, 20), server.address().port)
disc.on('peer', function (hash, peer) {
  var socket = net.connect(peer.port, peer.host)
  socket.pipe(mro.peerStream()).pipe(socket)
})

```

And then someone will consume it

``` js
var munro = require('munro')
var disc = require('discovery-channel')()
var net = require('net')

var mro = munro(id-from-example-above)

var server = net.createServer(function (socket) {
  socket.pipe(mro.peerStream()).pipe(socket)
})

disc.add(mro.id.slice(0, 20), server.address().port)
disc.on('peer', function (hash, peer) {
  var socket = net.connect(peer.port, peer.host)
  socket.pipe(mro.peerStream()).pipe(socket)
})

mro.get(0, function (err, block) {
  console.log(block.toString()) // 'hello'
})
```

## API

#### `var munro = munro(id)`

create a new munro instance. If id is specified munro will not be able to broadcast pieces and all pieces recieved will be verified using the id.

#### `var stream = munro.peerStream()`

stream is a duplex stream which can be piped to peers in order to replicate data.

#### `munro.broadcast(data)`

munro will sign and broadcast the data to connected peers.

#### `munro.get(index, cb)`

if connected peers have index munro will attempt to download the data.

#### `munro.destroy()`

will destroy all peers and callback error to pending callbacks.

#### `var ws = munro.writeStream()`

instead of broadcasting every block. just write it to the stream.

#### `var rs = munro.readStream()`

read all the blocks when they become available and pipe them onwards

## How does this even work?

Good question. When content is `broadcast` to the network it is only done so in peers look at the example below.
```
   1* // munro hash
 /   \
0     2
```
Two blocks of data are needed to generate a munro hash. Once the hash is generated it is signed off and the peer floods the network with `have` messages. If a peer is interested in the block it sends back a `request` message. The broadcaster then sends back the piece and other pieces that are needed to verify the authenticity so in this case it would send back block `2`. Once the blocks have been recieved the peer is able to verify the authenticity of the content by calculating the munro hash. If all is well that peer then boadcasts `have` messages to all of its peers and the process is repeated. This was inspired by [ppspp](https://tools.ietf.org/html/rfc7574)

-piedshag

---
_Source: https://npm.io/package/munro · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
