Skip to content

Commit

Permalink
Merge pull request #131 from libp2p/fix/no-dns
Browse files Browse the repository at this point in the history
fix: avoid dialing/listening on dns addresses
  • Loading branch information
Stebalien committed Apr 3, 2020
2 parents 75a10a8 + d7e9747 commit d7a0402
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion p2p/transport/quic/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions p2p/transport/quic/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d7a0402

Please sign in to comment.