js-libp2p icon indicating copy to clipboard operation
js-libp2p copied to clipboard

Prevent duplicate connections when dialing a multiaddr without a peer id

Open achingbrain opened this issue 1 year ago • 2 comments

If we dial a multiaddr without a peer id (e.g. /dns/example.com), and we exchange peer IDs with the remote, if we already have a non-circuit relay connection to that peer, the connection manager should close the new connection and return the existing connection.

At the moment we end up with multiple connections to the same peer which wastes resources.

achingbrain avatar Sep 23 '24 09:09 achingbrain

Could this be handled by the transports that initiate connections via a relayed connection? They would cleanup the connection after the direct connection is established.

tabcat avatar Sep 09 '25 17:09 tabcat

The issue of preventing duplicate connections to the same multiaddr looks like it was handled by https://github.com/libp2p/js-libp2p/commit/0c5957836d1416566f18233f58c92e7db6ab5525#diff-f67bf5a2d5ca417004f9cab5d20bb74d754a6a96cf4e4df6cf540d9a62388090R533-R540 two days after this issue was opened.

I'd be happy to work on a PR for a separate issue that addresses closing indirect connections used to open direct connections.

tabcat avatar Sep 09 '25 17:09 tabcat