fix: do not allow dial to large number of multiaddrs #954
+34
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There are peers on the wild that advertise hundreds of multiaddrs, either by bugs with weird UPnP behavior/Port mapping on their router, or even by potential disturbers in the network. These peers make a libp2p node attempt to dial every single multiaddr and likely fail for all the hundreds of discovered multiaddrs for the peer. Moreover, libp2p will attempt over and over again if it has a small number of peers connected.
A dialable peer from
js-libp2p
will advertiseTCP || Websockets || WebRTCStar || WebRTCDirect
+IPv4 || IPv6
, which means 8 different combinations. However, a peer should be able to advertise multiple different addresses for a single transport and it is typical to have peers advertising public and private addresses.In this PR, we will start by a quick in solution, until we have multiaddr confidence in place.
Reasonably, a dialable peer should not have more than 25 multiaddrs supported by a js-libp2p node. This PR adds a limit of 25 addresses when creating a dial target (after filtering out incompatible addresses like QUIC). If a peer has more than 25 dialable multiaddrs, the dial will throw without attempting to dial all of them and the peer will be removed from the PeerStore to not be advertised.
Closes #928