-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up some todos & some refactoring (#12)
- Loading branch information
1 parent
f8b2ac1
commit c687899
Showing
14 changed files
with
855 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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": [ | ||
|
@@ -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]>" | ||
] | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.