-
Notifications
You must be signed in to change notification settings - Fork 57
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
refactor: wrap peer store #3051
Conversation
You can find the image built from this PR at
Built from 69a20a5 |
20cd4f0
to
63797a9
Compare
e574184
to
b11f23c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great PR! Thanks so much for it! 🥳
I've just suggested some minor changes.
On the other hand, I have the impression that we are encapsulating the code a little, which is great indeed, but we are not yet tackling the stale peers issue, isn't it?
@@ -73,7 +73,7 @@ const | |||
|
|||
type PeerManager* = ref object of RootObj | |||
switch*: Switch | |||
peerStore*: PeerStore | |||
peerStore*: WakuPeerStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should also remane the variable name. Maybe do the same in the tests
peerStore*: WakuPeerStore | |
wakuPeerStore*: WakuPeerStore |
@@ -16,14 +16,16 @@ import | |||
export peerstore, builders | |||
|
|||
type | |||
WakuPeerStore* = ref object | |||
store*: PeerStore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a great opportunity to make the field private. In the suggestion I'm also renaming the attribute :)
store*: PeerStore | |
peerStore: PeerStore |
proc connectedness*(peerStore: PeerStore, peerId: PeerID): Connectedness = | ||
peerStore[ConnectionBook].book.getOrDefault(peerId, NotConnected) | ||
proc connectedness*(wps: WakuPeerStore, peerId: PeerId): Connectedness = | ||
wps.store[ConnectionBook].book.getOrDefault(peerId, NotConnected) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if would it work the following, for consistency
wps.store[ConnectionBook].book.getOrDefault(peerId, NotConnected) | |
wps[ConnectionBook].book.getOrDefault(peerId, NotConnected) |
|
||
# TODO: Rename peers() to getPeersByProtocol() | ||
proc peers*(peerStore: PeerStore): seq[RemotePeerInfo] = | ||
## Get all the stored information of every peer. | ||
proc peers*(wps: WakuPeerStore): seq[RemotePeerInfo] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should also remane those to getPeers
or getWakuPeers
to make them more explicit and easier to lookup
Yes, this PR does not tackle the stale peer issues. That stale peer issue isn't as pressing as it seemed when I created it. That's why I focused on another aspect of refactoring. Regarding the stale peer issue, I will add another PR to separate the functionality of the peer manager and the connection lifecycle. In that, I will also improve stale peer management. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks so much!
Description
Refactored the peer manager to improve stale peer management.
Changes