-
Notifications
You must be signed in to change notification settings - Fork 298
Handle errors when unpacking swarm.peers() response #885
Comments
We can quickly fix ipfs/ipfs-webui#878 for now by switching to js-multiaddr v5.0.2. I feel we should do that and then try solving future problems proactively going the In the UI we should display "invalid" multiaddrs as-is (in faded out colors) or replace it with a placeholder text, just like we do with unknown countries for unknown geoip data. |
The case of js-multiaddr not being able to validate addrs for the quic protocol, opens up an interesting problem. The contract of a If an ipfs instance returns a peer-info object from a call to we could
|
I'm working on a PR for this. |
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 <oli@tableflip.io>
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 <oli@tableflip.io>
The addition of the quic protocol means there are now peers on the network with a multiaddr that cannot be unpacked by older verions of js-multiaddr, and it throws.
In the current implementation of
ipfsApi.swarm.peers()
we don't handle any errors that could occur when trying to wrap the peer addr from the repsonse in a Multiaddr:https://github.com/ipfs/js-ipfs-api/blob/ead35992e9d5c60f85d74f0d80aad1b0e994ea5c/src/swarm/peers.js#L46-L51
the simplest solution would be to re-throw the error with an informative error message, but that still leaves us with the siutation when newer peers get added to the network, they can break my user-experience, as I suddenly start seeing 0 peers; js-ipfs-api throws an error if 1 peer appears invalid like in ipfs/ipfs-webui#878
A more helpful solution might be to provide some way to signal to the caller that some peers have information that we can't validate, but still do a best effort to return information about the response.
If we go the best-effort route, we've got
easy
- remove peers from the list if we hit an error trying to validate their info, and write a debug log. This is simple, but leaves the peer list that you get from ipfs-api containing fewer items than the http repsonse did, which is undesireable.hard
- update the api response info to include peers that can't be validated. We could add a property to an idividual peer likeerror
with the validation error, and theraw
with the unvalidated response data. Or we could pull out unvalidtable peers into a sepearate list and return two arrays, could bepeers
(the valid ones) andrawPeers
(all peers)...The text was updated successfully, but these errors were encountered: