Skip to content

Commit ee94b93

Browse files
committed
autonatv2: remove dependency on webrtc and webtransport
1 parent 5616d4d commit ee94b93

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

p2p/protocol/autonatv2/client.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/libp2p/go-libp2p/core/network"
1515
"github.com/libp2p/go-libp2p/core/peer"
1616
"github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pb"
17-
libp2pwebrtc "github.com/libp2p/go-libp2p/p2p/transport/webrtc"
18-
libp2pwebtransport "github.com/libp2p/go-libp2p/p2p/transport/webtransport"
1917
"github.com/libp2p/go-msgio/pbio"
2018
ma "github.com/multiformats/go-multiaddr"
2119
)
@@ -328,20 +326,20 @@ func (ac *client) handleDialBack(s network.Stream) {
328326
}
329327

330328
// normalizeMultiaddr returns a multiaddr suitable for equality checks.
331-
// If the multiaddr is a webtransport component, it removes the certhashes.
329+
// it removes trailing certhashes.
332330
func normalizeMultiaddr(addr ma.Multiaddr) ma.Multiaddr {
333-
ok, n := libp2pwebtransport.IsWebtransportMultiaddr(addr)
334-
if !ok {
335-
ok, n = libp2pwebrtc.IsWebRTCDirectMultiaddr(addr)
336-
}
337-
if ok && n > 0 {
338-
out := addr
339-
for i := 0; i < n; i++ {
340-
out, _ = ma.SplitLast(out)
331+
addr = removeTrailing(addr, ma.P_P2P)
332+
addr = removeTrailing(addr, ma.P_CERTHASH)
333+
return addr
334+
}
335+
336+
func removeTrailing(addr ma.Multiaddr, protocolCode int) ma.Multiaddr {
337+
for i := len(addr) - 1; i >= 0; i-- {
338+
if addr[i].Code() != protocolCode {
339+
return addr[0 : i+1]
341340
}
342-
return out
343341
}
344-
return addr
342+
return nil
345343
}
346344

347345
func (ac *client) areAddrsConsistent(connLocalAddr, dialedAddr ma.Multiaddr) bool {

0 commit comments

Comments
 (0)