From a21a9e8c62e864a41e666308d3a9e2995797dd36 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 2 Apr 2020 22:36:47 -0700 Subject: [PATCH 1/2] fix: avoid dialing/listening on dns addresses See https://github.com/libp2p/go-libp2p/issues/841 --- transport.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/transport.go b/transport.go index fa54bd8..fcb6c82 100644 --- a/transport.go +++ b/transport.go @@ -190,9 +190,12 @@ func (t *transport) Dial(ctx context.Context, raddr ma.Multiaddr, p peer.ID) (tp }, nil } +// Don't use mafmt.QUIC as we don't want to dial DNS addresses. Just /ip{4,6}/udp/quic +var dialMatcher = mafmt.And(mafmt.IP, mafmt.Base(ma.P_UDP), mafmt.Base(ma.P_QUIC)) + // CanDial determines if we can dial to an address func (t *transport) CanDial(addr ma.Multiaddr) bool { - return mafmt.QUIC.Matches(addr) + return dialMatcher.Matches(addr) } // Listen listens for new QUIC connections on the passed multiaddr. From e713a9fa7f82d3c89340b3553dda6517f527d840 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Mon, 16 Mar 2020 18:46:35 +0700 Subject: [PATCH 2/2] test that CanDial fails on /dns addresses --- transport_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/transport_test.go b/transport_test.go index 8dfece4..111b702 100644 --- a/transport_test.go +++ b/transport_test.go @@ -24,6 +24,12 @@ var _ = Describe("Transport", func() { Expect(t.CanDial(validAddr)).To(BeTrue()) }) + It("says that it cannot dial /dns addresses", func() { + addr, err := ma.NewMultiaddr("/dns/google.com/udp/443/quic") + Expect(err).ToNot(HaveOccurred()) + Expect(t.CanDial(addr)).To(BeFalse()) + }) + It("supports the QUIC protocol", func() { protocols := t.Protocols() Expect(protocols).To(HaveLen(1))