-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Use pregenerated ids for testing #284
Conversation
4825281
to
5c6009c
Compare
c0a0675
to
d38014b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stunning work! 🚀
src/test-ids/index.js
Outdated
|
||
module.exports.privKey = () => pbm.PublicKey.encode({ | ||
Type: pbm.KeyType.RSA, | ||
Data: base.decode(Ids[rand(0, Ids.length)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we shuffle the array and then step through we'll not get any collisions until we use all of them up.
src/test-ids/index.js
Outdated
module.exports.privKey = () => pbm.PublicKey.encode({ | ||
Type: pbm.KeyType.RSA, | ||
Data: base.decode(Ids[rand(0, Ids.length)]) | ||
}).toString('base64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do all this work beforehand and have ids.json
just be a list of base64 encoded private keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd also not need "whatever part of ascii can be put into a JSON string without needing to get escaped"-base
if we did this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's bigger than. The comment starts with "compression"
for a reason ;)
(I wanted to just use a binary protobuf but there are browsers and we know they like to mess with binary stuff)
src/test-ids/index.js
Outdated
cb(null, new Id(digest, key, key.public)) | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in ipfs/js-ipfs#1485 shall we just have a private key option? Do we need both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The reason why this even exists is because I added it for the in-process daemon first, then added the private key as string for external daemons.
ping @mkg20001 :D |
bbc36ed
to
edaf163
Compare
@alanshaw Added requested changes |
src/ipfsd-daemon.js
Outdated
@@ -78,7 +79,7 @@ class Daemon { | |||
this._started = false | |||
this.api = null | |||
this.bits = this.opts.initOptions ? this.opts.initOptions.bits : null | |||
this._env = Object.assign({}, process.env, this.opts.env) | |||
this._env = Object.assign({}, process.env, this.opts.env, this.disposable ? {IPFS_PREGENERATED_PRIVATE_KEY: testIds()} : {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be passed as a command line option instead now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, missed that one
src/test-ids/index.js
Outdated
return pbm.PublicKey.encode({ // this is needed because the keys aren't wrapped in the usual privateKey pbuf container to save space | ||
Type: pbm.KeyType.RSA, | ||
Data: base.decode(Ids.pop()) | ||
}).toString('base64') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, how much bigger would the file be? It's currently ~250kb. I'm guessing you've checked this encode
/decode
/toString
has negligible overhead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~444kb would be the filesize for a base64 array
What's the ETA to ship this? |
I missed the new review. Added the changes. |
652b82c
to
8765395
Compare
I've been blocking this with ipfs/js-ipfs#1485 - sorry, more important things delayed me! Hoping to unblock this week. |
8765395
to
c710da2
Compare
License: MIT Signed-off-by: Alan Shaw <[email protected]>
@hugomrdias can you do the final review and handle the merge and release? |
there's still stuff pending from my last review |
@hugomrdias I couldn't find anything. Mind linking it? |
src/test-ids/index.js
Outdated
const pbm = protobuf(require('libp2p-crypto/src/keys/keys.proto')) | ||
|
||
module.exports = () => { | ||
if (!Ids.length) { // TODO: should this maybe re-use ids? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a note in the readme for disposable daemons explaining this error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or should this maybe re-use ids
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print a warning and just stop using pregenerated ones?
src/test-ids/index.js
Outdated
return a | ||
} | ||
|
||
const Ids = shuffle(require('./ids.json').split('"')) // file can be generated using mkg20001/test-peer-ids.tk patched with ipfs://QmVZRWjZoqve9UKgng2gymN8a3FQUENgsQaicQ2fWs7kGx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls change Ids
to ids
src/test-ids/index.js
Outdated
const Ids = shuffle(require('./ids.json').split('"')) // file can be generated using mkg20001/test-peer-ids.tk patched with ipfs://QmVZRWjZoqve9UKgng2gymN8a3FQUENgsQaicQ2fWs7kGx | ||
const base = require('base-x')(' !#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~') // "compression" aka "whatever part of ascii can be put into a JSON string without needing to get escaped"-base | ||
|
||
const protobuf = require('protons') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls move all the requires to the top, just a nitpick for consistency :)
ups the pending part was on my side lol, forgot to click to send review. |
This reverts commit cbc1ac6.
depends on ipfs/js-ipfs#1485
resolves #280