-
Notifications
You must be signed in to change notification settings - Fork 28
Should multiaddr set .replace maintain order? #75
Comments
cc @libp2p/javascript-team |
Why is it important to do this? My gut feeling is that |
For your nodes addresses specifically. When I listen, transports may replace addresses in the multiaddr list with new addresses. For example When that node dials me, if they dial in serial, they'll start with their transport order and then the ordered list of multiaddrs for that transport. In js, since we don't have a mechanism to properly handle merging/aborting dials we'll be doing serial dials in the interim, to avoid flooding peers with connections that aren't properly accounted for. This is less of an issue with parallel dials. There are other protocols we've discussed like dialme that are better suited for getting peers to connect over preferred addresses. And in the future we'll likely look to have a way to deterministically select the best connection and just use that. Additionally, I would expect any
doesn't make a lot of sense to me. |
Initially I had the same feeling as @alanshaw, but after running through a few scenarios in my head it doesn't sound like such a bad idea... Overall, while not ideal it should work relatively well for most scenarios that are currently supported. This is actually a bit of a rabbit hole of complexity, here are just a few cases I can think of that I'm not sure how to handle:
In this context, something like the above mentioned |
I neglected to mention, I'm not against If the API changed to a single item replace If that solves a priority issue as a side effect then 👍, but we should be aware that it is a side effect and not a proper solution. |
Currently
peerInfo.multiaddrs.replace
simply deletes all instances of the existing addresses and pushes the new addresses onto the internal array. This prevents the multiaddr set from maintaining any type of order.Ideally, I think
replace
should insert the new addresses at the first index on the existing addresses. This would allow PeerInfo to maintain an order of preference. In libp2p-switch we already deprioritize circuit addresses by adding them to the end of the list. If any addresses are replaced during listening, it's possible that an unwanted order could occur.For example, currently in js-ipfs addresses before start for nodejs would look like:
And after startup they look something like:
Because the tcp wildcard addresses are replaced, they end up getting added after
/p2p-websocket-star/
, instead of inserted in the place of the old addresses.The text was updated successfully, but these errors were encountered: