Skip to content
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

Always add public key to constructor if possible, Fix for undefined pubKey in remote peers #68

Merged
merged 2 commits into from
Oct 12, 2017

Conversation

ya7ya
Copy link
Contributor

@ya7ya ya7ya commented Sep 14, 2017

hey @diasdavid , I noticed that whenever ipfs creates an Id , it usually uses peerId.createFromPrivKey , and this means you can add pubkey to the PeerId constructor call.

This is useful because it means the pubKey is available without ever triggering get pubKey(). so when this peer connects to another, the peer-id object would have the pubKey included. and won't equal undefined like the current situation.
pub included

I Also added a line to the tests to check if the pub key is valid.

@ya7ya
Copy link
Contributor Author

ya7ya commented Sep 19, 2017

@diasdavid Hey, How can I fix the codecov/patch and codecov/project error? it says No report found to compare against

@daviddias
Copy link
Member

ping @dignifiedquire

@dignifiedquire
Copy link
Member

that's because master is failing in ci. @diasdavid looks like you need to set some timeouts to get ci happy

@ya7ya
Copy link
Contributor Author

ya7ya commented Sep 28, 2017

hey @diasdavid , Can we get this merged ?

@@ -104,7 +105,7 @@ describe('PeerId', () => {

it('Non-default # of bits', function (done) {
// rsa is slow atm
this.timeout(20000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How slow is it? More than 20 seconds?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just ran the test again now, Non-default # of bits (90941ms) .
here are the result

Test Node.js                                                                                                                                                                                               [72/120]
 PASS  test/peer-id.spec.js (138.662s)
  PeerId
    ✓ create an id without 'new' (4ms)
    ✓ create a new id (4483ms)
    ✓ isPeerId (4959ms)
    ✓ throws on changing the id (2465ms)
    ✓ recreate an Id from Hex string (1ms)
    ✓ Recreate an Id from a Buffer (1ms)
    ✓ Recreate a B58 String (1ms)
    ✓ Recreate from a Public Key (7ms)
    ✓ Recreate from a Private Key (13ms)
    ✓ Compare generated ID with one created from PubKey (2408ms)
    ✓ **Non-default \# of bits (90941ms)**
    ✓ Pretty printing (1610ms)
    ✓ toBytes (1ms)
    ✓ isEqual (13666ms)
    ✓ set privKey (valid) (7129ms)
    ✓ set pubKey (valid) (3069ms)
    ✓ set privKey (invalid) (1889ms)
    ✓ set pubKey (invalid) (2178ms)
    fromJSON
      ✓ full node (331ms)
      ✓ only id (193ms)
      ✓ go interop (6ms)
    throws on inconsistent data
      ✓ missmatch private - public key (3ms)
      ✓ missmatch id - private - public key (3ms)
      ✓ invalid id (1ms)

Test Suites: 1 passed, 1 total
Tests:       24 passed, 24 total
Snapshots:   0 total
Time:        138.966s
Ran all test suites matching /test\/node.js$|test\/.*\.spec\.js$/i.                                                                                                                                        [30/112]
Test Browser


  PeerId
    ✓ create an id without 'new' (3ms)
    ✓ create a new id (437ms)
    ✓ isPeerId (158ms)
    ✓ throws on changing the id (111ms)
    ✓ recreate an Id from Hex string (15ms)
    ✓ Recreate an Id from a Buffer (1ms)
    ✓ Recreate a B58 String (1ms)
    ✓ Recreate from a Public Key (11ms)
    ✓ Recreate from a Private Key (43ms)
    ✓ Compare generated ID with one created from PubKey (347ms)
    ✓ Non-default # of bits (3501ms)
    ✓ Pretty printing (198ms)
    ✓ toBytes
    ✓ isEqual (716ms)
    ✓ set privKey (valid) (119ms)
    ✓ set pubKey (valid) (190ms)
    ✓ set privKey (invalid) (469ms)
    ✓ set pubKey (invalid) (349ms)
    fromJSON
      ✓ full node (45ms)
      ✓ only id (42ms)
      ✓ go interop (27ms)
    throws on inconsistent data
      ✓ missmatch private - public key (2ms)
      ✓ missmatch id - private - public key (3ms)
      ✓ invalid id (1ms)


  24 passing (16s)

Test Webworker


Chrome 61.0.3163 (Linux 0.0.0) LOG: '[karma-mocha-webworker] Skipping url because it does not match the given pattern(s)', '/base/test/fixtures/go-private-key.js'
Chrome 61.0.3163 (Linux 0.0.0) LOG: '[karma-mocha-webworker] Skipping url because it does not match the given pattern(s)', '/base/test/fixtures/sample-id.js'
  PeerId
    ✓ create an id without 'new' (3ms)
    ✓ create a new id (390ms)
    ✓ isPeerId (128ms)
    ✓ throws on changing the id (338ms)
    ✓ recreate an Id from Hex string (1ms)
    ✓ Recreate an Id from a Buffer (1ms)
    ✓ Recreate a B58 String (2ms)
    ✓ Recreate from a Public Key (7ms)
    ✓ Recreate from a Private Key (25ms)
    ✓ Compare generated ID with one created from PubKey (152ms)
    ✓ Non-default # of bits (3793ms)
    ✓ Pretty printing (439ms)
    ✓ toBytes
    ✓ isEqual (335ms)
    ✓ set privKey (valid) (347ms)
    ✓ set pubKey (valid) (553ms)
    ✓ set privKey (invalid) (239ms)
    ✓ set pubKey (invalid) (586ms)
    fromJSON
      ✓ full node (111ms)
      ✓ only id (54ms)
      ✓ go interop (5ms)
    throws on inconsistent data
      ✓ missmatch private - public key (2ms)
      ✓ missmatch id - private - public key (1ms)
      ✓ invalid id


  24 passing (14s)

@@ -202,7 +202,7 @@ exports.createFromPrivKey = function (key, callback) {
return callback(err)
}

callback(null, new PeerId(digest, privKey))
callback(null, new PeerId(digest, privKey, privKey.public))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should check if the public key is on the privKey, what was the case where it missed the public Key?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diasdavid the pubKey check only happens when it's requested, it's undefined before that because it isn't created in the constructor.

This method is used by js-ipfs pre-start. providing pubKey at this point means the key will also be validated

@daviddias daviddias merged commit 3abdcda into libp2p:master Oct 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants