Skip to content
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

feat: enable event emission for peer discovery/connection in ConnectionManager #1438

Merged
merged 20 commits into from
Jul 26, 2023

Conversation

danisharora099
Copy link
Collaborator

Problem

This PR aims to make the process of finding/displaying total peers found via a discovery protocol vs actually connected.

It is part of https://github.com/orgs/waku-org/projects/2/views/1?pane=issue&itemId=26409725

Solution

  • creates a public function to fetch all discovered and connected peers, separated by their discovery protocol
  • sets up ConnectionManager to emit events as a new peer is discovered/connected

Notes

@danisharora099 danisharora099 requested a review from a team July 26, 2023 09:59
@github-actions
Copy link

github-actions bot commented Jul 26, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 30.26 KB (+1.63% 🔺) 606 ms (+1.63% 🔺) 506 ms (-15.67% 🔽) 1.2 s
Waku Simple Light Node 235.43 KB (+0.11% 🔺) 4.8 s (+0.11% 🔺) 1.9 s (+30.33% 🔺) 6.6 s
ECIES encryption 28.54 KB (0%) 571 ms (0%) 564 ms (-3.26% 🔽) 1.2 s
Symmetric encryption 28.55 KB (0%) 571 ms (0%) 531 ms (-25.77% 🔽) 1.2 s
DNS discovery 108.36 KB (0%) 2.2 s (0%) 1.1 s (+5.48% 🔺) 3.3 s
Privacy preserving protocols 122.73 KB (+0.21% 🔺) 2.5 s (+0.21% 🔺) 1.3 s (+50.34% 🔺) 3.8 s
Light protocols 31.72 KB (+1.57% 🔺) 635 ms (+1.57% 🔺) 558 ms (+29.69% 🔺) 1.2 s
History retrieval protocols 30.94 KB (+1.49% 🔺) 619 ms (+1.49% 🔺) 466 ms (-20.73% 🔽) 1.1 s
Deterministic Message Hashing 5.78 KB (0%) 116 ms (0%) 184 ms (-31.64% 🔽) 300 ms

const peersConnectedByPeerExchange: Peer[] = [];

for (const peer of peersDiscovered) {
const tags = await this.getTagNamesForPeer(peer.id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't need to use getTagNamesForPeer but you can directly refer to peer.tags.keys() to avoid async operation

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is done to keep fetching tags consistent through this function; agreed that it is async, but it is computationally low demand so should be ok

Copy link
Collaborator

Choose a reason for hiding this comment

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

I am wondering what is the difference if the same tags are present on peer in the loop as well as those you'd get from this.getTagNamesForPeer?

@@ -44,12 +52,57 @@ export class ConnectionManager {
return instance;
}

public async getPeersByDiscovery(): Promise<PeersByDiscovery> {
const peersDiscovered = await this.libp2p.peerStore.all();
const peersConnected = this.libp2p
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess we can optimize here and just getConnections which returns tags as well so that later there is no reason to await for peer store

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct. that is a more efficient way, agreed.
related comment: #1438 (comment)

@weboko
Copy link
Collaborator

weboko commented Jul 26, 2023

Thank you for promptly addressing the comments!

@danisharora099 danisharora099 merged commit 6ce898d into master Jul 26, 2023
8 of 9 checks passed
@danisharora099 danisharora099 deleted the feat/improve-conn-manager branch July 26, 2023 17:21
This was referenced Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants