diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index afdd408dc0..27318f6b7d 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -1021,15 +1021,10 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { quicAddrCount++ } } - seenAddr := make(map[string]struct{}, len(in)) quicOrWebtransportAddrs := make(map[string]struct{}, quicAddrCount) webtransportAddrs := make(map[string]struct{}, quicAddrCount) foundSameListeningAddr := false for _, addr := range in { - if _, ok := seenAddr[addr.String()]; ok { - continue - } - seenAddr[addr.String()] = struct{}{} isWebtransport, numCertHashes := libp2pwebtransport.IsWebtransportMultiaddr(addr) if isWebtransport { for i := 0; i < numCertHashes; i++ { @@ -1061,15 +1056,8 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { return in } - // Dedup the output, because why not - seenAddr = make(map[string]struct{}, len(in)) out := make([]ma.Multiaddr, 0, len(in)+(quicAddrCount-len(webtransportAddrs))) for _, addr := range in { - if _, ok := seenAddr[addr.String()]; ok { - continue - } - seenAddr[addr.String()] = struct{}{} - // Add all the original addresses out = append(out, addr) if _, lastComponent := ma.SplitLast(addr); lastComponent.Protocol().Code == ma.P_QUIC_V1 { diff --git a/p2p/host/basic/basic_host_test.go b/p2p/host/basic/basic_host_test.go index e2abd2d1b6..5c1babd9d5 100644 --- a/p2p/host/basic/basic_host_test.go +++ b/p2p/host/basic/basic_host_test.go @@ -838,21 +838,6 @@ func TestInferWebtransportAddrsFromQuic(t *testing.T) { in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1"}, out: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport"}, }, - { - name: "Happy Path with Dupes", - in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1"}, - out: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport"}, - }, - { - name: "Doesn't dedupe if there's no inferring", - in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/tcp/9999"}, - out: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/tcp/9999"}, - }, - { - name: "Dedupes if we inferred a webtransport addr", - in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/0.0.0.0/tcp/9999", "/ip4/0.0.0.0/tcp/9999"}, - out: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport", "/ip4/0.0.0.0/tcp/9999"}, - }, { name: "Already discovered", in: []string{"/ip4/0.0.0.0/udp/9999/quic-v1", "/ip4/0.0.0.0/udp/9999/quic-v1/webtransport", "/ip4/1.2.3.4/udp/9999/quic-v1", "/ip4/1.2.3.4/udp/9999/quic-v1/webtransport"},