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

refactor: peerConnector #665

Merged
merged 4 commits into from
Aug 28, 2023
Merged

refactor: peerConnector #665

merged 4 commits into from
Aug 28, 2023

Conversation

harsh-98
Copy link
Contributor

@harsh-98 harsh-98 commented Aug 22, 2023

Understanding:

  • why does subscriptions array in Peerconnector exist?
    Reason: if Peerconnector isn't running and either of the peer discovery protocols (rendezvous/peer_exchange/discv5) adds a subscription. that subscription needs to be stored. So that once peer connector is running we can start getting peers from these saved subscriptions.

  • Why are there different peerCh and dialCh channels?
    Reason: peerCh also have origin information that has to be added to peerManager. Where is dialCh is peerInfo field of peerCh which is only used for establishing connection.

  • why are there workerCtx, workerCancel and shouldDialPeers?
    Reason: if no of outConnection exceeds outRelayTarget, then pause.

  • Let's consider host connected relay peers are more than outRelayTarget, then shouldDialPeers will pause PeerConnector. Since peerCh is unbuffered, this will block rendezvous(https://github.com/waku-org/go-waku/blob/master/waku/v2/rendezvous/rendezvous.go#L95). Not block peer_exchange(as response is handled asynchronisely)/discv5(async runDiscoveryV5Loop-> peerLoop-> peerConnector.Subscribe)

Note: if new peers are discovered and peerConnector is paused we don't drop those peers, waits peerConnector to unPaused.

  • Why is waitGroup needed?
    it can happen that one of goroutine ends after the peerCh or dialCh is closed. So it might type to send to that routine which will panic.

Problem with workerCtx, scenario:

  • AddDiscoveredPeer called for PeerData.
  • peerConnector is in paused state. workerCancel is called.
    This new peer will not make the connection even though it is saved in host due to AddDiscoveredPeer call.

Questions:

  • shouldn't c.pm.GroupPeersByDirection() be c.pm.relayPeers()? Since GroupPeersByDirection doesn't filter by relay.
  • should we drop the peers from subscription when the peerConnector is paused? There can be multiple handling routine bcz of this.

@status-im-auto
Copy link

status-im-auto commented Aug 22, 2023

Jenkins Builds

Click to see older builds (18)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ bf3e9b5 #1 2023-08-22 19:09:40 ~1 min linux 📦deb
✔️ bf3e9b5 #1 2023-08-22 19:10:18 ~1 min nix-flake 📄log
✔️ bf3e9b5 #1 2023-08-22 19:11:17 ~2 min tests 📄log
✔️ bf3e9b5 #1 2023-08-22 19:11:32 ~3 min tests 📄log
✔️ bf3e9b5 #1 2023-08-22 19:12:18 ~4 min android 📦tgz
✔️ bf3e9b5 #1 2023-08-22 19:12:54 ~4 min ios 📦tgz
✔️ 5219e7b #2 2023-08-22 19:20:09 ~32 sec linux 📦deb
✔️ 5219e7b #2 2023-08-22 19:20:59 ~1 min tests 📄log
✔️ 5219e7b #2 2023-08-22 19:21:18 ~1 min tests 📄log
✔️ 5219e7b #2 2023-08-22 19:21:31 ~1 min nix-flake 📄log
✔️ 5219e7b #2 2023-08-22 19:22:45 ~3 min android 📦tgz
✔️ 5219e7b #2 2023-08-22 19:23:34 ~3 min ios 📦tgz
✔️ 8c76b87 #3 2023-08-25 07:05:28 ~1 min linux 📦deb
✔️ 8c76b87 #3 2023-08-25 07:06:38 ~2 min nix-flake 📄log
✔️ 8c76b87 #3 2023-08-25 07:07:11 ~2 min tests 📄log
✔️ 8c76b87 #3 2023-08-25 07:07:24 ~3 min tests 📄log
✔️ 8c76b87 #3 2023-08-25 07:07:56 ~3 min android 📦tgz
✔️ 8c76b87 #3 2023-08-25 07:08:05 ~3 min ios 📦tgz
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ c76ad7f #4 2023-08-25 09:00:57 ~39 sec linux 📦deb
✔️ c76ad7f #4 2023-08-25 09:01:41 ~1 min tests 📄log
✔️ c76ad7f #4 2023-08-25 09:02:05 ~1 min tests 📄log
✔️ c76ad7f #4 2023-08-25 09:02:16 ~1 min nix-flake 📄log
✔️ c76ad7f #4 2023-08-25 09:03:35 ~3 min android 📦tgz
✔️ c76ad7f #4 2023-08-25 09:04:30 ~4 min ios 📦tgz
✔️ 224cab9 #5 2023-08-25 10:42:11 ~33 sec linux 📦deb
✔️ 224cab9 #5 2023-08-25 10:43:03 ~1 min tests 📄log
✔️ 224cab9 #5 2023-08-25 10:43:17 ~1 min tests 📄log
✔️ 224cab9 #5 2023-08-25 10:43:27 ~1 min nix-flake 📄log
✔️ 224cab9 #5 2023-08-25 10:44:58 ~3 min android 📦tgz
✔️ 224cab9 #5 2023-08-25 10:45:44 ~4 min ios 📦tgz

@richard-ramos
Copy link
Member

should we drop the peers from subscription when the peerConnector is paused? There can be multiple handling routine bcz of this.

Not sure. IIUC, peers from the subscription be consumed only while the peerConnector is running. If so, the worst that could happen is that you end up receiving peers that are not online when the peerConnector runs again, and you'd waste some seconds while attempting to connect to them.

@chaitanyaprem
Copy link
Collaborator

shouldn't c.pm.GroupPeersByDirection() be c.pm.relayPeers()? Since GroupPeersByDirection doesn't filter by relay.

GroupPeersByDirection is just grouping all peers we are connected to. There can be peers which is not a relayPeer and can just be providing other Waku services only. So, would not recommend renaming it.

Also note that, the current peerMgmt implementation is tied with managing relay peer connections. In future this will get expanded to manage connections towards other service peers as well.

Copy link
Collaborator

@chaitanyaprem chaitanyaprem left a comment

Choose a reason for hiding this comment

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

Nice PR.
Cleans up some of the remnants of code which i missed removing.

waku/v2/peermanager/peer_connector.go Outdated Show resolved Hide resolved
waku/v2/peermanager/peer_connector.go Show resolved Hide resolved
waku/v2/peermanager/peer_manager.go Show resolved Hide resolved
@harsh-98
Copy link
Contributor Author

shouldn't c.pm.GroupPeersByDirection() be c.pm.relayPeers()? Since GroupPeersByDirection doesn't filter by relay.

GroupPeersByDirection is just grouping all peers we are connected to. There can be peers which is not a relayPeer and can just be providing other Waku services only. So, would not recommend renaming it.

Also note that, the current peerMgmt implementation is tied with managing relay peer connections. In future this will get expanded to manage connections towards other service peers as well.

Currently peerConector is paused when inDirectionPeer > inRelayPeersTarget. Whereas at another place in peerManager, we have similar check inRelayPeer>pm.InRelayPeersTarget. There after getting the direction peers we also filter by proto(/relay/2.0.0 in this case).

@chaitanyaprem
Copy link
Collaborator

shouldn't c.pm.GroupPeersByDirection() be c.pm.relayPeers()? Since GroupPeersByDirection doesn't filter by relay.

GroupPeersByDirection is just grouping all peers we are connected to. There can be peers which is not a relayPeer and can just be providing other Waku services only. So, would not recommend renaming it.
Also note that, the current peerMgmt implementation is tied with managing relay peer connections. In future this will get expanded to manage connections towards other service peers as well.

Currently peerConector is paused when inDirectionPeer > inRelayPeersTarget. Whereas at another place in peerManager, we have similar check inRelayPeer>pm.InRelayPeersTarget. There after getting the direction peers we also filter by proto(/relay/2.0.0 in this case).

PeerConnector is paused when outPeersTarget is reached. Whereas in peerManager we have checks for both inPeers and outPeers target.
Did not get your point here. Maybe i am missing something. Can you elaborate?

@harsh-98
Copy link
Contributor Author

harsh-98 commented Aug 25, 2023

Sorry, i confused with inRelay.
What i meant to say was:

  • OutDirectionPeer is more than or eq to outRelayPeers.
  • Let say OutDirectionPeer = 4 and outRelayPeer are 2. If if outTarget in peerManager is 3, currently peerConnector will be paused but peerManager will keep sending peer to connect as outRelayPeer<outRelayTarget. Where as peerConnector is using OutDirectionPeer, so it will think needed no of out relay peer is already achieved.

@chaitanyaprem
Copy link
Collaborator

Now i see what you are referring to. Understood.

@harsh-98 harsh-98 merged commit 467d1b2 into master Aug 28, 2023
2 checks passed
@harsh-98 harsh-98 deleted the peerConnector branch August 28, 2023 06:47
@harsh-98
Copy link
Contributor Author

#634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants