Skip to content

Commit c687899

Browse files
dignifiedquiredaviddias
authored andcommitted
Clean up some todos & some refactoring (#12)
1 parent f8b2ac1 commit c687899

14 files changed

+855
-539
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ build
3131
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3232
node_modules
3333

34-
lib
3534
dist
35+
36+
docs

README.md

+1-12
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ js-libp2p-floodsub
2424

2525
## Install
2626

27-
```
2827
```sh
2928
> npm install libp2p-floodsub
3029
```
@@ -46,17 +45,7 @@ fsub.publish('fruit', new Buffer('banana'))
4645

4746
## API
4847

49-
### `ps.subscribe(<topic>)`
50-
51-
### `ps.unsubscribe(<topic>)`
52-
53-
### `ps.publish(<topic>, <msg>)`
54-
55-
### `ps.on(<topic>, callback)`
56-
57-
### `ps.getPeerSet()`
58-
59-
### `ps.getSubscriptions()`
48+
See https://libp2p.github.io/js-libp2p-floodsub
6049

6150
## Contribute
6251

benchmarks/index.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict'
2+
3+
const Benchmark = require('benchmark')
4+
const crypto = require('crypto')
5+
const map = require('async/map')
6+
const parallel = require('async/parallel')
7+
8+
const PSG = require('../src')
9+
const utils = require('../test/utils')
10+
11+
const suite = new Benchmark.Suite('pubsub')
12+
13+
// Simple benchmark, how many messages can we send from
14+
// one node to another.
15+
16+
map([0, 1], (i, cb) => {
17+
utils.createNode('/ip4/127.0.0.1/tcp/0', (err, node) => {
18+
if (err) {
19+
return cb(err)
20+
}
21+
22+
cb(null, {
23+
libp2p: node,
24+
ps: new PSG(node)
25+
})
26+
})
27+
}, (err, peers) => {
28+
if (err) {
29+
throw err
30+
}
31+
32+
parallel([
33+
(cb) => peers[0].libp2p.dialByPeerInfo(peers[1].libp2p.peerInfo, cb),
34+
(cb) => setTimeout(() => {
35+
peers[0].ps.subscribe('Z')
36+
peers[1].ps.subscribe('Z')
37+
cb(null, peers)
38+
}, 200)
39+
], (err, res) => {
40+
if (err) {
41+
throw err
42+
}
43+
const peers = res[1]
44+
45+
suite.add('publish and receive', (deferred) => {
46+
const onMsg = (msg) => {
47+
deferred.resolve()
48+
peers[1].ps.removeListener('Z', onMsg)
49+
}
50+
51+
peers[1].ps.on('Z', onMsg)
52+
53+
peers[0].ps.publish('Z', crypto.randomBytes(1024))
54+
}, {
55+
defer: true
56+
})
57+
58+
suite
59+
.on('cycle', (event) => {
60+
console.log(String(event.target))
61+
})
62+
.on('complete', () => {
63+
process.exit()
64+
})
65+
.run({
66+
async: true
67+
})
68+
})
69+
})

benchmarks/utils.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
3+
const Benchmark = require('benchmark')
4+
5+
if (typeof window !== 'undefined') {
6+
window.Benchmark = Benchmark
7+
}
8+
9+
const utils = require('../src/utils')
10+
11+
const suite = new Benchmark.Suite('utils')
12+
13+
let res = []
14+
15+
suite.add('randomSeqno', () => {
16+
res.push(utils.randomSeqno())
17+
})
18+
19+
suite
20+
.on('cycle', (event) => {
21+
console.log(String(event.target))
22+
res = []
23+
})
24+
.run({
25+
async: true
26+
})

package.json

+14-13
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
"test:node:cli": "TEST=cli npm run test:node",
1414
"test:browser": "gulp test:browser",
1515
"build": "gulp build",
16-
"release": "gulp release",
17-
"release-minor": "gulp release --type minor",
18-
"release-major": "gulp release --type major",
16+
"docs": "aegir-docs",
17+
"release": "gulp release --docs",
18+
"release-minor": "gulp release --type minor --docs",
19+
"release-major": "gulp release --type major --docs",
1920
"coverage-publish": "aegir-coverage publish"
2021
},
2122
"pre-commit": [
@@ -41,28 +42,28 @@
4142
},
4243
"homepage": "https://github.com/libp2p/js-libp2p-floodsub#readme",
4344
"devDependencies": {
44-
"aegir": "^9.1.2",
45+
"aegir": "^9.3.0",
4546
"async": "^2.1.4",
47+
"benchmark": "^2.1.2",
4648
"chai": "^3.5.0",
47-
"libp2p-ipfs-nodejs": "^0.16.0",
49+
"libp2p-ipfs-nodejs": "^0.17.0",
4850
"lodash.times": "^4.3.2",
4951
"multiaddr": "^2.1.1",
50-
"peer-id": "^0.8.0",
52+
"peer-id": "^0.8.1",
5153
"peer-info": "^0.8.1",
52-
"pre-commit": "^1.1.3"
54+
"pre-commit": "^1.2.2"
5355
},
5456
"dependencies": {
55-
"debug": "^2.3.3",
56-
"git-sha1": "^0.1.2",
57+
"debug": "^2.4.5",
5758
"length-prefixed-stream": "^1.5.1",
58-
"lodash.intersection": "^4.4.0",
59-
"lodash.uniq": "^4.5.0",
59+
"libp2p-crypto": "^0.7.5",
6060
"lodash.values": "^4.3.0",
61-
"time-cache": "^0.2.3"
61+
"pull-pushable": "^2.0.1",
62+
"time-cache": "^0.3.0"
6263
},
6364
"contributors": [
6465
"David Dias <[email protected]>",
6566
"Gavin McDermott <[email protected]>",
6667
6768
]
68-
}
69+
}

src/dial-floodsub.js

-70
This file was deleted.

0 commit comments

Comments
 (0)