From d46e631f8bdc8d6de81ae98a555f5a20bc7a5e12 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Wed, 16 Aug 2023 15:20:06 +0200 Subject: [PATCH] basichost: use byte representation of WebTransport multiaddr as map key (#2494) --- p2p/host/basic/basic_host.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 79f02e2c51..1f440fd946 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -942,17 +942,17 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { // Remove certhashes addr, _ = ma.SplitLast(addr) } - webtransportAddrs[addr.String()] = struct{}{} + webtransportAddrs[string(addr.Bytes())] = struct{}{} // Remove webtransport component, now it's a multiaddr that ends in /quic-v1 addr, _ = ma.SplitLast(addr) } if _, lastComponent := ma.SplitLast(addr); lastComponent.Protocol().Code == ma.P_QUIC_V1 { - addrStr := addr.String() - if _, ok := quicOrWebtransportAddrs[addrStr]; ok { + bytes := addr.Bytes() + if _, ok := quicOrWebtransportAddrs[string(bytes)]; ok { foundSameListeningAddr = true } else { - quicOrWebtransportAddrs[addrStr] = struct{}{} + quicOrWebtransportAddrs[string(bytes)] = struct{}{} } } } @@ -974,7 +974,7 @@ func inferWebtransportAddrsFromQuic(in []ma.Multiaddr) []ma.Multiaddr { if _, lastComponent := ma.SplitLast(addr); lastComponent.Protocol().Code == ma.P_QUIC_V1 { // Convert quic to webtransport addr = addr.Encapsulate(wtComponent) - if _, ok := webtransportAddrs[addr.String()]; ok { + if _, ok := webtransportAddrs[string(addr.Bytes())]; ok { // We already have this address continue }