Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

fix: avoid dialing/listening on dns addresses #131

Merged
merged 2 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@marten-seemann marten-seemann Apr 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ Sorry for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's confusing. We may want to just go ahead and revert the change in mafmt (we changed it from IP only to IP+DNS). But it does make sense to allow DNS there, just not here.

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 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