Skip to content

Commit

Permalink
Clean up some todos & some refactoring (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire authored and daviddias committed Dec 18, 2016
1 parent f8b2ac1 commit c687899
Show file tree
Hide file tree
Showing 14 changed files with 855 additions and 539 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ build
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

lib
dist

docs
13 changes: 1 addition & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ js-libp2p-floodsub

## Install

```
```sh
> npm install libp2p-floodsub
```
Expand All @@ -46,17 +45,7 @@ fsub.publish('fruit', new Buffer('banana'))

## API

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

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

### `ps.publish(<topic>, <msg>)`

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

### `ps.getPeerSet()`

### `ps.getSubscriptions()`
See https://libp2p.github.io/js-libp2p-floodsub

## Contribute

Expand Down
69 changes: 69 additions & 0 deletions benchmarks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict'

const Benchmark = require('benchmark')
const crypto = require('crypto')
const map = require('async/map')
const parallel = require('async/parallel')

const PSG = require('../src')
const utils = require('../test/utils')

const suite = new Benchmark.Suite('pubsub')

// Simple benchmark, how many messages can we send from
// one node to another.

map([0, 1], (i, cb) => {
utils.createNode('/ip4/127.0.0.1/tcp/0', (err, node) => {
if (err) {
return cb(err)
}

cb(null, {
libp2p: node,
ps: new PSG(node)
})
})
}, (err, peers) => {
if (err) {
throw err
}

parallel([
(cb) => peers[0].libp2p.dialByPeerInfo(peers[1].libp2p.peerInfo, cb),
(cb) => setTimeout(() => {
peers[0].ps.subscribe('Z')
peers[1].ps.subscribe('Z')
cb(null, peers)
}, 200)
], (err, res) => {
if (err) {
throw err
}
const peers = res[1]

suite.add('publish and receive', (deferred) => {
const onMsg = (msg) => {
deferred.resolve()
peers[1].ps.removeListener('Z', onMsg)
}

peers[1].ps.on('Z', onMsg)

peers[0].ps.publish('Z', crypto.randomBytes(1024))
}, {
defer: true
})

suite
.on('cycle', (event) => {
console.log(String(event.target))
})
.on('complete', () => {
process.exit()
})
.run({
async: true
})
})
})
26 changes: 26 additions & 0 deletions benchmarks/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const Benchmark = require('benchmark')

if (typeof window !== 'undefined') {
window.Benchmark = Benchmark
}

const utils = require('../src/utils')

const suite = new Benchmark.Suite('utils')

let res = []

suite.add('randomSeqno', () => {
res.push(utils.randomSeqno())
})

suite
.on('cycle', (event) => {
console.log(String(event.target))
res = []
})
.run({
async: true
})
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
"test:node:cli": "TEST=cli npm run test:node",
"test:browser": "gulp test:browser",
"build": "gulp build",
"release": "gulp release",
"release-minor": "gulp release --type minor",
"release-major": "gulp release --type major",
"docs": "aegir-docs",
"release": "gulp release --docs",
"release-minor": "gulp release --type minor --docs",
"release-major": "gulp release --type major --docs",
"coverage-publish": "aegir-coverage publish"
},
"pre-commit": [
Expand All @@ -41,28 +42,28 @@
},
"homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme",
"devDependencies": {
"aegir": "^9.1.2",
"aegir": "^9.3.0",
"async": "^2.1.4",
"benchmark": "^2.1.2",
"chai": "^3.5.0",
"libp2p-ipfs-nodejs": "^0.16.0",
"libp2p-ipfs-nodejs": "^0.17.0",
"lodash.times": "^4.3.2",
"multiaddr": "^2.1.1",
"peer-id": "^0.8.0",
"peer-id": "^0.8.1",
"peer-info": "^0.8.1",
"pre-commit": "^1.1.3"
"pre-commit": "^1.2.2"
},
"dependencies": {
"debug": "^2.3.3",
"git-sha1": "^0.1.2",
"debug": "^2.4.5",
"length-prefixed-stream": "^1.5.1",
"lodash.intersection": "^4.4.0",
"lodash.uniq": "^4.5.0",
"libp2p-crypto": "^0.7.5",
"lodash.values": "^4.3.0",
"time-cache": "^0.2.3"
"pull-pushable": "^2.0.1",
"time-cache": "^0.3.0"
},
"contributors": [
"David Dias <[email protected]>",
"Gavin McDermott <[email protected]>",
"Haad <[email protected]>"
]
}
}
70 changes: 0 additions & 70 deletions src/dial-floodsub.js

This file was deleted.

Loading

0 comments on commit c687899

Please sign in to comment.