Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

fix: handle peer-info validation errors #887

Merged
merged 4 commits into from
Nov 26, 2018
Merged

fix: handle peer-info validation errors #887

merged 4 commits into from
Nov 26, 2018

Conversation

olizilla
Copy link
Contributor

@olizilla olizilla commented Nov 6, 2018

BREAKING CHANGE. Previously swarm.peers would throw an uncaught error
if any peer in the reponse couldn't have its peerId or multiaddr validated.

This PR catches errors that occur while validating the peer info. The
returned array will contain an entry for every peer in the ipfs response.
peer-info objects that couldn't be validated, now have an error property
and a rawPeerInfo property. This at least means the count of peers in
the response will be accurate, and there the info is available to the caller.

This means that callers now have to deal with peer-info objects that may
not have a peer or addr property.

Adds nock tests to exercice the code under different error conditions.
Doing so uncovered a bug in our legacy go-ipfs <= 0.4.4 peer info parsing,
which is also fixed. The code was trying to decapusalate the peerId from
the multiaddr, but doing so trims the peerId rather than returning it.

fixes #885

License: MIT
Signed-off-by: Oli Evans [email protected]

BREAKING CHANGE. Previously swarm.peers would throw an uncaught error
if any peer in the reponse could have its peerId or multiaddr validated.

This PR catches errors that occur while validating the peer info. The
returned array will contain an entry for every peer in the ipfs response.
peer-info objects that couldn't be validated, now have an `error` property
and a `rawPeerInfo` property. This at least means the count of peers in
the response will be accurate, and there the info is available to the caller.

This means that callers now have to deal with peer-info objects that may
not have a `peer or `addr` property.

Adds `nock` tests to exercice the code under different error conditions.
Doing so uncovered a bug in our legacy go-ipfs <= 0.4.4 peer info parsing,
which is also fixed. The code was trying to decapusalate the peerId from
the multiaddr, but doing so trims the peerId rather than returning it.

fixes #885

License: MIT
Signed-off-by: Oli Evans <[email protected]>
@ghost ghost assigned olizilla Nov 6, 2018
@olizilla olizilla requested a review from alanshaw November 6, 2018 17:15
@ghost ghost added the in progress label Nov 6, 2018
@olizilla olizilla requested a review from daviddias November 6, 2018 17:15
@olizilla
Copy link
Contributor Author

olizilla commented Nov 6, 2018

This also fixes ipfs/ipfs-webui#878

@olizilla
Copy link
Contributor Author

olizilla commented Nov 7, 2018

I need to figure out how to tell ageir to only run the nock tests in node. Any clues?

@daviddias
Copy link
Contributor

daviddias commented Nov 7, 2018

@olizilla Remove the .spec from the filename and add a node.js file that has a require for those tests. See https://github.com/ipfs/js-ipfs/blob/master/test/core/node.js for example

Copy link
Contributor

@alanshaw alanshaw left a comment

Choose a reason for hiding this comment

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

Code LGTM. Do you have a moment to PR https://github.com/ipfs/interface-ipfs-core/blob/master/SPEC/SWARM.md#swarmpeers to make a note of the change?

@olizilla
Copy link
Contributor Author

olizilla commented Nov 9, 2018

@alanshaw related to our conversations about the multiaddr validation problem, I found this multiformats/multiaddr#70

olizilla added a commit to ipfs-inactive/interface-js-ipfs-core that referenced this pull request Nov 13, 2018
js-ipfs-api can encounter individual peer info objects that have newer multiaddrs or, in theory, a new format for PeerId that it cannot parse. Allowing for individiual peerInfo validation errors allows us to return a response which has the right number of peers in, and peerId and multiaddr info for all the other peers that could be validated, along with a info about peers that failed to validate.

See: ipfs-inactive/js-ipfs-http-client#887
@olizilla
Copy link
Contributor Author

The codelint and linux/8.12/test:node CI failures are unrelated to this PR

There is a PR to update the interface-core spec here ipfs-inactive/interface-js-ipfs-core#393

daviddias pushed a commit to ipfs-inactive/interface-js-ipfs-core that referenced this pull request Nov 14, 2018
js-ipfs-api can encounter individual peer info objects that have newer multiaddrs or, in theory, a new format for PeerId that it cannot parse. Allowing for individiual peerInfo validation errors allows us to return a response which has the right number of peers in, and peerId and multiaddr info for all the other peers that could be validated, along with a info about peers that failed to validate.

See: ipfs-inactive/js-ipfs-http-client#887
License: MIT
Signed-off-by: Alan Shaw <[email protected]>
@ghost ghost assigned alanshaw Nov 26, 2018
@alanshaw alanshaw merged commit 6e6d7a2 into master Nov 26, 2018
@alanshaw alanshaw deleted the swarm-peers-tests branch November 26, 2018 12:05
@ghost ghost removed the in progress label Nov 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle errors when unpacking swarm.peers() response
3 participants