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

chore: use new peer store api #179

Merged
merged 1 commit into from
Apr 16, 2020
Merged

Conversation

vasco-santos
Copy link
Member

@vasco-santos vasco-santos commented Apr 1, 2020

In the context of the PeerStore improvements specified on libp2p/js-libp2p#582 and as a follow up of libp2p/js-libp2p#590, this PR switches libp2p-kad-dht usage of peer-store to its new API.

Moreover, there were some places where data was being added to the peerStore with any benefit. In some cases the data was already there and in other cases there was nothing new to add at that point.

BREAKING CHANGE: uses new peer-store api

Needs:

Unblocks:

@@ -76,14 +76,14 @@
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"it-pair": "^1.0.0",
"libp2p": "libp2p/js-libp2p#chore/deprecate-old-peer-store-api",
Copy link
Member Author

Choose a reason for hiding this comment

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

@jacobheun I am not sure if mocking the peerStore is the best thing to do here, or depend on libp2p as a dev dependency again. What do you think? It could be worth having a mocks repo for this kind of stuff, but we would need to make sure it was properly updated with new changes

Copy link
Contributor

Choose a reason for hiding this comment

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

@vasco-santos something I think could be a better setup is to have libp2p as a dev dependency of the modules, and then have the libp2p test suite just try to run these tests as part of CI. I know we'd need to overcome some hurdles of what happens during breaking change releases, but this might be an opportunity to trial that flow with the 0.28 release and maybe just do the DHT to start with. If we're able to make that a smooth process, we could do that for the other modules.

This gets us a step in that direction, so I am good with having it as a dev dep.

return dht.peerStore.get(p)
}

return dht.peerStore.put(new PeerInfo(p))
Copy link
Member Author

Choose a reason for hiding this comment

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

Already known providers, no need to add to the peerStore. Moreover, the peerInfo is just created here, so there is nothing relevant to add

@@ -244,7 +244,6 @@ class WorkerQueue {
if (this.dht._isSelf(closer.id)) {
return
}
closer = this.dht.peerStore.put(closer)
Copy link
Member Author

Choose a reason for hiding this comment

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

No new information of the peer at this point

Copy link
Contributor

Choose a reason for hiding this comment

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

Also it's unnecessary as the emit below will cause libp2p to update the peer store

BREAKING CHANGE: uses new peer-store api
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 👍

@@ -76,14 +76,14 @@
"delay": "^4.3.0",
"dirty-chai": "^2.0.1",
"it-pair": "^1.0.0",
"libp2p": "libp2p/js-libp2p#chore/deprecate-old-peer-store-api",
Copy link
Contributor

Choose a reason for hiding this comment

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

@vasco-santos something I think could be a better setup is to have libp2p as a dev dependency of the modules, and then have the libp2p test suite just try to run these tests as part of CI. I know we'd need to overcome some hurdles of what happens during breaking change releases, but this might be an opportunity to trial that flow with the 0.28 release and maybe just do the DHT to start with. If we're able to make that a smooth process, we could do that for the other modules.

This gets us a step in that direction, so I am good with having it as a dev dep.

@@ -169,7 +173,7 @@ module.exports = (dht) => {
result.paths.forEach((result) => {
if (result.success) {
success = true
dht.peerStore.put(result.peer)
dht.peerStore.addressBook.add(result.peer.id, result.peer.multiaddrs.toArray())
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that this is now a discrete action. It's much clearer what's happening than a put imo.

@@ -244,7 +244,6 @@ class WorkerQueue {
if (this.dht._isSelf(closer.id)) {
return
}
closer = this.dht.peerStore.put(closer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Also it's unnecessary as the emit below will cause libp2p to update the peer store

@vasco-santos vasco-santos merged commit 194c701 into master Apr 16, 2020
@jacobheun jacobheun deleted the chore/use-new-peer-store-api branch July 10, 2020 11:22
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