Skip to content

Commit

Permalink
Merge pull request #2 from libp2p/feat/0.1
Browse files Browse the repository at this point in the history
v0.1
  • Loading branch information
daviddias authored Sep 14, 2016
2 parents cbb3036 + 1f3afc5 commit 937000c
Show file tree
Hide file tree
Showing 22 changed files with 1,107 additions and 25 deletions.
24 changes: 11 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
**/node_modules/
**/*.log
test/repo-tests*

# Logs
logs
*.log
npm-debug.log*

coverage

# Runtime data
pids
Expand All @@ -14,24 +19,17 @@ lib-cov
# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
build

# Dependency directories
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
lib
dist
34 changes: 34 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
**/node_modules/
**/*.log
test/repo-tests*

# Logs
logs
*.log

coverage

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

build

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

test
34 changes: 34 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
sudo: false
language: node_js
node_js:
- 4
- 5
- stable

# Make sure we have new NPM.
before_install:
- npm install -g npm

script:
- npm run lint
- npm test
- npm run coverage


before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

env:
- CXX=g++-4.8

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# js-libp2p-pubsub-gossip
js-libp2p-floodsub
==================

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://libp2p.io/)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-pubsub-gossip/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-pubsub-gossip?branch=master)
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-pubsub-gossip.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-pubsub-gossip)
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-pubsub-gossip.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-pubsub-gossip)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-pubsub-gossip.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-pubsub-gossip) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-floodsub/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-floodsub?branch=master)
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-floodsub.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-floodsub)
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-floodsub.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-floodsub)
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-floodsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-floodsub) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-pubsub-gossip)
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-floodsub)

> libp2p-pubsub-gossip, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).
> libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).

## Table of Contents
Expand All @@ -24,20 +25,42 @@
## Install

```
```sh
> npm install libp2p-floodsub
```

## Usage
## Examples

```
```JavaScript
const FloodSub = require('libp2p-floodsub')

const fsub = new FloodSub(libp2pNodeInstance)

fsub.on('fruit', (data) => {
console.log(data)
})
fsub.subscribe('fruit')

fsub.publish('fruit', new Buffer('banana'))
```

## API

## Contribute
### `ps.subscribe(<topic>)`

### `ps.unsubscribe(<topic>)`

See [the contribute file](contribute.md)!
### `ps.publish(<topic>, <msg>)`

### `ps.on(<topic>, callback)`

### `ps.getPeerSet()`

### `ps.getSubscriptions()`

## Contribute

PRs accepted.
PRs are welcome!

Small note: If editing the Readme, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

Expand Down
12 changes: 12 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
machine:
node:
version: stable

dependencies:
pre:
- google-chrome --version
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
- sudo apt-get update
- sudo apt-get --only-upgrade install google-chrome-stable
- google-chrome --version
51 changes: 51 additions & 0 deletions examples/pub-sub-1-topic/publisher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict'

const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const multiaddr = require('multiaddr')
const libp2pIPFS = require('libp2p-ipfs')
const PSG = require('../../src')
const series = require('run-series')

const privateKey = 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0mkHiaJcpycy9STKphorpCT83srBVQi59CdFU6Mj+aL/xt0kCPMVigJw8P3/YCEJ9J+rS8BsoWE+xWUEsJvtXoT7vzPHaAtM3ci1HZd302Mz1+GgS8Epdx+7F5p80XAFLDUnELzOzKftvWGZmWfSeDnslwVONkL/1VAzwKy7Ce6hk4SxRE7l2NE2OklSHOzCGU1f78ZzVYKSnS5Ag9YrGjOAmTOXDbKNKN/qIorAQ1bovzGoCwx3iGIatQKFOxyVCyO1PsJYT7JO+kZbhBWRRE+L7l+ppPER9bdLFxs1t5CrKc078h+wuUr05S1P1JjXk68pk3+kQKBgQDeK8AR11373Mzib6uzpjGzgNRMzdYNuExWjxyxAzz53NAR7zrPHvXvfIqjDScLJ4NcRO2TddhXAfZoOPVH5k4PJHKLBPKuXZpWlookCAyENY7+Pd55S8r+a+MusrMagYNljb5WbVTgN8cgdpim9lbbIFlpN6SZaVjLQL3J8TWH6wKBgQDSChzItkqWX11CNstJ9zJyUE20I7LrpyBJNgG1gtvz3ZMUQCn3PxxHtQzN9n1P0mSSYs+jBKPuoSyYLt1wwe10/lpgL4rkKWU3/m1Myt0tveJ9WcqHh6tzcAbb/fXpUFT/o4SWDimWkPkuCb+8j//2yiXk0a/T2f36zKMuZvujqQKBgC6B7BAQDG2H2B/ijofp12ejJU36nL98gAZyqOfpLJ+FeMz4TlBDQ+phIMhnHXA5UkdDapQ+zA3SrFk+6yGk9Vw4Hf46B+82SvOrSbmnMa+PYqKYIvUzR4gg34rL/7AhwnbEyD5hXq4dHwMNsIDq+l2elPjwm/U9V0gdAl2+r50HAoGALtsKqMvhv8HucAMBPrLikhXP/8um8mMKFMrzfqZ+otxfHzlhI0L08Bo3jQrb0Z7ByNY6M8epOmbCKADsbWcVre/AAY0ZkuSZK/CaOXNX/AhMKmKJh8qAOPRY02LIJRBCpfS4czEdnfUhYV/TYiFNnKRj57PPYZdTzUsxa/yVTmECgYBr7slQEjb5Onn5mZnGDh+72BxLNdgwBkhO0OCdpdISqk0F0Pxby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=='

let nodePublisher
let psPublisher

function bootNode (next) {
const idPublisher = PeerId.createFromPrivKey(privateKey)
const peerPublisher = new PeerInfo(idPublisher)
peerPublisher.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/12345'))
nodePublisher = new libp2pIPFS.Node(peerPublisher)
nodePublisher.start((err) => {
console.log('Publisher listening on:')

peerPublisher.multiaddrs.forEach((ma) => {
console.log(ma.toString() + '/ipfs/' + idPublisher.toB58String())
})
next(err)
})
}

function setUpPS (next) {
console.log('attaching pubsub')
psPublisher = new PSG(nodePublisher)
next()
}

function publishMsg (err) {
if (err) {
throw err
}

setInterval(() => {
process.stdout.write('.')
psPublisher.publish('interop', new Buffer('hey, how is it going?'))
}, 300)
}

series([
bootNode,
setUpPS
], publishMsg)

1 change: 1 addition & 0 deletions examples/pub-sub-1-topic/subscriber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict'
5 changes: 5 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

const gulp = require('gulp')

require('aegir/gulp')(gulp)
Binary file added img/test-cases.monopic
Binary file not shown.
22 changes: 22 additions & 0 deletions img/test-cases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

All subscribe to Partial
the same topic subscriptions

line line
◉────◉────◉ ◉────◎────◉
a b c a b c


1 level tree 1 level tree
┌◉┐ ┌◉┐
│b│ │b│
◉─┘ └─◉ ◎─┘ └─◉
a c a c

2 levels tree 2 levels tree
┌◉┐ ┌◉┐
│c│ │c│
┌◉─┘ └─◉┐ ┌◎─┘ └─◉┐
│b d│ │b d│
◉─┘ └─◉ ◉─┘ └─◎
a e a e
65 changes: 65 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "libp2p-floodsub",
"version": "0.0.0",
"description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).",
"main": "lib/core/index.js",
"jsnext:main": "src/core/index.js",
"scripts": {
"lint": "aegir-lint",
"coverage": "gulp coverage",
"test": "PHANTOM=off gulp test",
"test:node": "gulp test:node",
"test:node:core": "TEST=core npm run test:node",
"test:node:http": "TEST=http npm run test:node",
"test:node:cli": "TEST=cli npm run test:node",
"test:browser": "PHANTOM=off gulp test:browser",
"build": "gulp build",
"release": "PHANTOM=off gulp release",
"release-minor": "PHANTOM=off gulp release --type minor",
"release-major": "PHANTOM=off gulp release --type major",
"coverage-publish": "aegir-coverage publish"
},
"pre-commit": [
"lint",
"test"
],
"repository": {
"type": "git",
"url": "git+https://github.com/libp2p/js-libp2p-floodsub.git"
},
"keywords": [
"IPFS",
"libp2p",
"pubsub",
"gossip",
"flood",
"flooding"
],
"author": "David Dias <daviddias@ipfs.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/libp2p/js-libp2p-floodsub/issues"
},
"homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme",
"devDependencies": {
"aegir": "^8.0.1",
"chai": "^3.5.0",
"libp2p-ipfs": "^0.14.1",
"lodash.times": "^4.3.2",
"multiaddr": "^2.0.3",
"peer-id": "^0.7.0",
"peer-info": "^0.7.1",
"pre-commit": "^1.1.3",
"run-parallel": "^1.1.6",
"run-series": "^1.1.4"
},
"dependencies": {
"debug": "^2.2.0",
"git-sha1": "^0.1.2",
"length-prefixed-stream": "^1.5.0",
"lodash.intersection": "^4.4.0",
"lodash.uniq": "^4.5.0",
"lodash.values": "^4.3.0",
"time-cache": "^0.2.3"
}
}
11 changes: 11 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'

const debug = require('debug')

const log = debug('libp2p:floodsub')
log.err = debug('libp2p:floodsub:error')

module.exports = {
log: log,
multicodec: '/floodsub/1.0.0'
}
Loading

0 comments on commit 937000c

Please sign in to comment.