Skip to content

Commit

Permalink
webtransport: check for UDP multiaddr component in address matcher (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorropo authored Aug 16, 2023
1 parent 4090dcc commit 457f84a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
28 changes: 17 additions & 11 deletions p2p/transport/webtransport/multiaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,23 @@ func IsWebtransportMultiaddr(multiaddr ma.Multiaddr) (bool, int) {
certhashCount := 0

ma.ForEach(multiaddr, func(c ma.Component) bool {
if c.Protocol().Code == ma.P_QUIC_V1 && state == init {
state = foundUDP
}
if c.Protocol().Code == ma.P_QUIC_V1 && state == foundUDP {
state = foundQuicV1
}
if c.Protocol().Code == ma.P_WEBTRANSPORT && state == foundQuicV1 {
state = foundWebTransport
}
if c.Protocol().Code == ma.P_CERTHASH && state == foundWebTransport {
certhashCount++
switch c.Protocol().Code {
case ma.P_UDP:
if state == init {
state = foundUDP
}
case ma.P_QUIC_V1:
if state == foundUDP {
state = foundQuicV1
}
case ma.P_WEBTRANSPORT:
if state == foundQuicV1 {
state = foundWebTransport
}
case ma.P_CERTHASH:
if state == foundWebTransport {
certhashCount++
}
}
return true
})
Expand Down
1 change: 1 addition & 0 deletions p2p/transport/webtransport/multiaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func TestIsWebtransportMultiaddr(t *testing.T) {
{addr: "/ip4/1.2.3.4/udp/60042/quic-v1/webtransport/certhash/" + fooHash, want: true, certhashCount: 1},
{addr: "/ip4/1.2.3.4/udp/60042/quic-v1/webtransport/certhash/" + fooHash + "/certhash/" + barHash, want: true, certhashCount: 2},
{addr: "/dns4/example.com/udp/60042/quic-v1/webtransport/certhash/" + fooHash, want: true, certhashCount: 1},
{addr: "/dns4/example.com/tcp/60042/quic-v1/webtransport/certhash/" + fooHash, want: false},
{addr: "/dns4/example.com/udp/60042/webrtc/certhash/" + fooHash, want: false},
}

Expand Down

0 comments on commit 457f84a

Please sign in to comment.