Skip to content

Commit 937000c

Browse files
authored
Merge pull request #2 from libp2p/feat/0.1
v0.1
2 parents cbb3036 + 1f3afc5 commit 937000c

22 files changed

+1107
-25
lines changed

.gitignore

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
**/node_modules/
2+
**/*.log
3+
test/repo-tests*
4+
15
# Logs
26
logs
37
*.log
4-
npm-debug.log*
8+
9+
coverage
510

611
# Runtime data
712
pids
@@ -14,24 +19,17 @@ lib-cov
1419
# Coverage directory used by tools like istanbul
1520
coverage
1621

17-
# nyc test coverage
18-
.nyc_output
19-
2022
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
2123
.grunt
2224

2325
# node-waf configuration
2426
.lock-wscript
2527

26-
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
28+
build
2829

29-
# Dependency directories
30+
# Dependency directory
31+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3032
node_modules
31-
jspm_packages
32-
33-
# Optional npm cache directory
34-
.npm
3533

36-
# Optional REPL history
37-
.node_repl_history
34+
lib
35+
dist

.npmignore

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
**/node_modules/
2+
**/*.log
3+
test/repo-tests*
4+
5+
# Logs
6+
logs
7+
*.log
8+
9+
coverage
10+
11+
# Runtime data
12+
pids
13+
*.pid
14+
*.seed
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
23+
.grunt
24+
25+
# node-waf configuration
26+
.lock-wscript
27+
28+
build
29+
30+
# Dependency directory
31+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
32+
node_modules
33+
34+
test

.travis.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
sudo: false
2+
language: node_js
3+
node_js:
4+
- 4
5+
- 5
6+
- stable
7+
8+
# Make sure we have new NPM.
9+
before_install:
10+
- npm install -g npm
11+
12+
script:
13+
- npm run lint
14+
- npm test
15+
- npm run coverage
16+
17+
18+
before_script:
19+
- export DISPLAY=:99.0
20+
- sh -e /etc/init.d/xvfb start
21+
22+
after_success:
23+
- npm run coverage-publish
24+
25+
env:
26+
- CXX=g++-4.8
27+
28+
addons:
29+
firefox: 'latest'
30+
apt:
31+
sources:
32+
- ubuntu-toolchain-r-test
33+
packages:
34+
- g++-4.8

README.md

+35-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
# js-libp2p-pubsub-gossip
1+
js-libp2p-floodsub
2+
==================
23

34
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
45
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://libp2p.io/)
56
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
6-
[![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)
7-
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-pubsub-gossip.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-pubsub-gossip)
8-
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-pubsub-gossip.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-pubsub-gossip)
9-
[![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)
7+
[![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)
8+
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-floodsub.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-floodsub)
9+
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-floodsub.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-floodsub)
10+
[![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)
1011
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
11-
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-pubsub-gossip)
12+
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-floodsub)
1213

13-
> 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).
14+
> 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).
1415
1516

1617
## Table of Contents
@@ -24,20 +25,42 @@
2425
## Install
2526

2627
```
28+
```sh
29+
> npm install libp2p-floodsub
2730
```
2831

29-
## Usage
32+
## Examples
3033

31-
```
34+
```JavaScript
35+
const FloodSub = require('libp2p-floodsub')
36+
37+
const fsub = new FloodSub(libp2pNodeInstance)
38+
39+
fsub.on('fruit', (data) => {
40+
console.log(data)
41+
})
42+
fsub.subscribe('fruit')
43+
44+
fsub.publish('fruit', new Buffer('banana'))
3245
```
3346

3447
## API
3548

36-
## Contribute
49+
### `ps.subscribe(<topic>)`
50+
51+
### `ps.unsubscribe(<topic>)`
3752

38-
See [the contribute file](contribute.md)!
53+
### `ps.publish(<topic>, <msg>)`
54+
55+
### `ps.on(<topic>, callback)`
56+
57+
### `ps.getPeerSet()`
58+
59+
### `ps.getSubscriptions()`
60+
61+
## Contribute
3962

40-
PRs accepted.
63+
PRs are welcome!
4164

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

circle.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
machine:
2+
node:
3+
version: stable
4+
5+
dependencies:
6+
pre:
7+
- google-chrome --version
8+
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
9+
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
10+
- sudo apt-get update
11+
- sudo apt-get --only-upgrade install google-chrome-stable
12+
- google-chrome --version

examples/pub-sub-1-topic/publisher.js

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict'
2+
3+
const PeerId = require('peer-id')
4+
const PeerInfo = require('peer-info')
5+
const multiaddr = require('multiaddr')
6+
const libp2pIPFS = require('libp2p-ipfs')
7+
const PSG = require('../../src')
8+
const series = require('run-series')
9+
10+
const privateKey = 'CAASpgkwggSiAgEAAoIBAQC2SKo/HMFZeBml1AF3XijzrxrfQXdJzjePBZAbdxqKR1Mc6juRHXij6HXYPjlAk01BhF1S3Ll4Lwi0cAHhggf457sMg55UWyeGKeUv0ucgvCpBwlR5cQ020i0MgzjPWOLWq1rtvSbNcAi2ZEVn6+Q2EcHo3wUvWRtLeKz+DZSZfw2PEDC+DGPJPl7f8g7zl56YymmmzH9liZLNrzg/qidokUv5u1pdGrcpLuPNeTODk0cqKB+OUbuKj9GShYECCEjaybJDl9276oalL9ghBtSeEv20kugatTvYy590wFlJkkvyl+nPxIH0EEYMKK9XRWlu9XYnoSfboiwcv8M3SlsjAgMBAAECggEAZtju/bcKvKFPz0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xby22DFOKXZEpiyI9XYP1C8wPiJsShGm2yEwBPWXnrrZNWczaVuCbXHrZkWQogBDG3HGXNdU4MAWCyiYlyinIBpPpoAJZSzpGLmWbMWh28+RJS6AQX6KHrK1o2uw=='
11+
12+
let nodePublisher
13+
let psPublisher
14+
15+
function bootNode (next) {
16+
const idPublisher = PeerId.createFromPrivKey(privateKey)
17+
const peerPublisher = new PeerInfo(idPublisher)
18+
peerPublisher.multiaddr.add(multiaddr('/ip4/0.0.0.0/tcp/12345'))
19+
nodePublisher = new libp2pIPFS.Node(peerPublisher)
20+
nodePublisher.start((err) => {
21+
console.log('Publisher listening on:')
22+
23+
peerPublisher.multiaddrs.forEach((ma) => {
24+
console.log(ma.toString() + '/ipfs/' + idPublisher.toB58String())
25+
})
26+
next(err)
27+
})
28+
}
29+
30+
function setUpPS (next) {
31+
console.log('attaching pubsub')
32+
psPublisher = new PSG(nodePublisher)
33+
next()
34+
}
35+
36+
function publishMsg (err) {
37+
if (err) {
38+
throw err
39+
}
40+
41+
setInterval(() => {
42+
process.stdout.write('.')
43+
psPublisher.publish('interop', new Buffer('hey, how is it going?'))
44+
}, 300)
45+
}
46+
47+
series([
48+
bootNode,
49+
setUpPS
50+
], publishMsg)
51+
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'use strict'

gulpfile.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict'
2+
3+
const gulp = require('gulp')
4+
5+
require('aegir/gulp')(gulp)

img/test-cases.monopic

5.4 KB
Binary file not shown.

img/test-cases.txt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
All subscribe to Partial
3+
the same topic subscriptions
4+
5+
line line
6+
◉────◉────◉ ◉────◎────◉
7+
a b c a b c
8+
9+
10+
1 level tree 1 level tree
11+
┌◉┐ ┌◉┐
12+
│b│ │b│
13+
◉─┘ └─◉ ◎─┘ └─◉
14+
a c a c
15+
16+
2 levels tree 2 levels tree
17+
┌◉┐ ┌◉┐
18+
│c│ │c│
19+
┌◉─┘ └─◉┐ ┌◎─┘ └─◉┐
20+
│b d│ │b d│
21+
◉─┘ └─◉ ◉─┘ └─◎
22+
a e a e

package.json

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "libp2p-floodsub",
3+
"version": "0.0.0",
4+
"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).",
5+
"main": "lib/core/index.js",
6+
"jsnext:main": "src/core/index.js",
7+
"scripts": {
8+
"lint": "aegir-lint",
9+
"coverage": "gulp coverage",
10+
"test": "PHANTOM=off gulp test",
11+
"test:node": "gulp test:node",
12+
"test:node:core": "TEST=core npm run test:node",
13+
"test:node:http": "TEST=http npm run test:node",
14+
"test:node:cli": "TEST=cli npm run test:node",
15+
"test:browser": "PHANTOM=off gulp test:browser",
16+
"build": "gulp build",
17+
"release": "PHANTOM=off gulp release",
18+
"release-minor": "PHANTOM=off gulp release --type minor",
19+
"release-major": "PHANTOM=off gulp release --type major",
20+
"coverage-publish": "aegir-coverage publish"
21+
},
22+
"pre-commit": [
23+
"lint",
24+
"test"
25+
],
26+
"repository": {
27+
"type": "git",
28+
"url": "git+https://github.com/libp2p/js-libp2p-floodsub.git"
29+
},
30+
"keywords": [
31+
"IPFS",
32+
"libp2p",
33+
"pubsub",
34+
"gossip",
35+
"flood",
36+
"flooding"
37+
],
38+
"author": "David Dias <[email protected]>",
39+
"license": "MIT",
40+
"bugs": {
41+
"url": "https://github.com/libp2p/js-libp2p-floodsub/issues"
42+
},
43+
"homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme",
44+
"devDependencies": {
45+
"aegir": "^8.0.1",
46+
"chai": "^3.5.0",
47+
"libp2p-ipfs": "^0.14.1",
48+
"lodash.times": "^4.3.2",
49+
"multiaddr": "^2.0.3",
50+
"peer-id": "^0.7.0",
51+
"peer-info": "^0.7.1",
52+
"pre-commit": "^1.1.3",
53+
"run-parallel": "^1.1.6",
54+
"run-series": "^1.1.4"
55+
},
56+
"dependencies": {
57+
"debug": "^2.2.0",
58+
"git-sha1": "^0.1.2",
59+
"length-prefixed-stream": "^1.5.0",
60+
"lodash.intersection": "^4.4.0",
61+
"lodash.uniq": "^4.5.0",
62+
"lodash.values": "^4.3.0",
63+
"time-cache": "^0.2.3"
64+
}
65+
}

src/config.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
3+
const debug = require('debug')
4+
5+
const log = debug('libp2p:floodsub')
6+
log.err = debug('libp2p:floodsub:error')
7+
8+
module.exports = {
9+
log: log,
10+
multicodec: '/floodsub/1.0.0'
11+
}

0 commit comments

Comments
 (0)