Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat: peer-discovery not using peer-info #41

Merged
merged 3 commits into from
Apr 16, 2020

Conversation

vasco-santos
Copy link
Member

In the context of deprecating peer-info as described on libp2p/js-libp2p#589, this PR changes the peer-discovery interface to emit an object containing an id property and a multiaddrs property.

Future discovery services might gather other data, such as known protocols. However, we should specify those optional parameters when the time comes.

BREAKING CHANGE: peer-discovery emits object with id and multiaddrs properties

BREAKING CHANGE: peer-discovery emits object with id and multiaddrs properties
@vasco-santos
Copy link
Member Author

We currently do not have meaningful tests for this interface yet. Should we try to leverage this change to do it?

If we specify that the events should be emitted via a function _onPeer(peerId, multiaddrs), we could call this function. I am not a big fan of this solution though. We could also have a base class that discovery services extend and it would do the emit for them.

cc @jacobheun

@jacobheun
Copy link
Contributor

We currently do not have meaningful tests for this interface yet. Should we try to leverage this change to do it?

Yes we should.

If we specify that the events should be emitted via a function _onPeer(peerId, multiaddrs), we could call this function. I am not a big fan of this solution though. We could also have a base class that discovery services extend and it would do the emit for them.

What are you trying to get out of this? It seems like it's doing some unnecessary restrictions. If we specify the API requirements and add tests that should be sufficient.

@vasco-santos
Copy link
Member Author

What are you trying to get out of this? It seems like it's doing some unnecessary restrictions. If we specify the API requirements and add tests that should be sufficient.

I agree with not being nice to add unnecessary restrictions. However, we need to have a way of simulating the peer event from the discovery service and verify that it provided the peerId and multiaddrs. Any idea on how we should trigger it on a generic way?

@jacobheun
Copy link
Contributor

Any idea on how we should trigger it on a generic way?

I think this should just be handled by the common setup requirements of the test. Such as, once start is called, the handler discovery.on('peer', handler) should be called repeatedly until stop is called. This would allow us to validate start, stop and whatever required event handler methods we add.

The interface tests shouldn't trigger anything, just call methods.

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

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

Found a few things. Also, I think we should merge this into a new minor branch since we'll need to update a few of the other interfaces for the peer-info change.

src/peer-discovery/README.md Outdated Show resolved Hide resolved
Everytime a peer is discovered by a discovery service, it emmits a `peer` event with the discovered peer's information, which must contain the following properties:

- `<`[`PeerId`](https://github.com/libp2p/js-peer-id)`>` `peerInfo.id`
- `<Array<`[`Multiaddr`](https://github.com/multiformats/js-multiaddr)`>>` `peerInfo.multiaddrs`
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we change peerInfo to peerData everywhere to avoid confusion?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes please 😂

src/peer-discovery/tests/index.js Outdated Show resolved Hide resolved
src/peer-discovery/tests/index.js Outdated Show resolved Hide resolved
src/peer-discovery/tests/index.js Show resolved Hide resolved
},
async teardown () {
clearInterval(intervalId)
await new Promise(resolve => setTimeout(resolve, 10))
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't need to be here.

Suggested change
await new Promise(resolve => setTimeout(resolve, 10))

Co-Authored-By: Jacob Heun <jacobheun@gmail.com>
@vasco-santos vasco-santos force-pushed the feat/peer-discovery-not-using-peer-info branch from fff9c14 to 360a056 Compare April 16, 2020 10:02
@vasco-santos vasco-santos marked this pull request as ready for review April 16, 2020 10:02
@vasco-santos
Copy link
Member Author

Found a few things. Also, I think we should merge this into a new minor branch since we'll need to update a few of the other interfaces for the peer-info change.

What about an approach with a pre-release, so that we can start merging all the PRs related to peer-discovery as release candidates, and then we only need to change for the final release? All the needed PRs are open now as well, so I think the sooner we get them, the sooner we unblock other PRs

@jacobheun
Copy link
Contributor

What about an approach with a pre-release, so that we can start merging all the PRs related to peer-discovery as release candidates, and then we only need to change for the final release?

These aren't mutually exclusive options. We can do pre releases / RCs from any branch. The main reason for the separate branch is to keep master open for any patches that might be needed before this is released.

We can always cherry pick patches onto the latest tag and release that, but we'd also have to remember to pull those patches, as needed back into master. Putting everything into a new branch avoids the need to remember because we'll get the change when we go to merge into master.

@jacobheun
Copy link
Contributor

This also replaces #19 right?

@vasco-santos
Copy link
Member Author

vasco-santos commented Apr 16, 2020

These aren't mutually exclusive options. We can do pre releases / RCs from any branch. The main reason for the separate branch is to keep master open for any patches that might be needed before this is released.

We can always cherry pick patches onto the latest tag and release that, but we'd also have to remember to pull those patches, as needed back into master. Putting everything into a new branch avoids the need to remember because we'll get the change when we go to merge into master.

Yes, let's do it in a new branch then

This also replaces #19 right?

Oh yes! Just closed it, completely forgot about that initial PR

@jacobheun jacobheun changed the base branch from master to v0.3.x April 16, 2020 14:01
Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

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

LGTM, updated the base branch to 0.3.x

@jacobheun jacobheun merged commit 170c2fd into v0.3.x Apr 16, 2020
@jacobheun jacobheun deleted the feat/peer-discovery-not-using-peer-info branch April 16, 2020 14:02
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.

2 participants