Skip to content
This repository was archived by the owner on Feb 26, 2021. It is now read-only.
This repository was archived by the owner on Feb 26, 2021. It is now read-only.

Should multiaddr set .replace maintain order? #75

@jacobheun

Description

@jacobheun

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:

/ip4/0.0.0.0/tcp/4002
/ip6/::/tcp/4009
/ip4/0.0.0.0/tcp/4003/ws
/dns4/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star

And after startup they look something like:

/p2p-websocket-star/ipfs/Qm...
/ip4/127.0.0.1/tcp/4002/ipfs/Qm...
/ip6/::/tcp/4009/ipfs/Qm...
/ip4/127.0.0.1/tcp/4003/ws/ipfs/Qm...
/p2p-circuit/ipfs/Qm...
/p2p-circuit/p2p-websocket-star/ipfs/Qm...
...

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions