diff --git a/client.go b/client.go index 9c4e35267..2c765b296 100644 --- a/client.go +++ b/client.go @@ -51,6 +51,20 @@ func DialAddr(addr string, config *Config) (Session, error) { return Dial(udpConn, udpAddr, addr, config) } +// DialAddrNonFWSecure establishes a new QUIC connection to a server. +// The hostname for SNI is taken from the given address. +func DialAddrNonFWSecure(addr string, config *Config) (NonFWSession, error) { + udpAddr, err := net.ResolveUDPAddr("udp", addr) + if err != nil { + return nil, err + } + udpConn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.IPv4zero, Port: 0}) + if err != nil { + return nil, err + } + return DialNonFWSecure(udpConn, udpAddr, addr, config) +} + // DialNonFWSecure establishes a new non-forward-secure QUIC connection to a server using a net.PacketConn. // The host parameter is used for SNI. func DialNonFWSecure(pconn net.PacketConn, remoteAddr net.Addr, host string, config *Config) (NonFWSession, error) { diff --git a/client_test.go b/client_test.go index bf40d044e..ffba513b9 100644 --- a/client_test.go +++ b/client_test.go @@ -82,6 +82,20 @@ var _ = Describe("Client", func() { close(done) }) + It("dials a non-forward-secure address", func(done Done) { + var dialedSess Session + go func() { + defer GinkgoRecover() + var err error + dialedSess, err = DialAddrNonFWSecure("localhost:18901", config) + Expect(err).ToNot(HaveOccurred()) + }() + Consistently(func() Session { return dialedSess }).Should(BeNil()) + sess.handshakeChan <- handshakeEvent{encLevel: protocol.EncryptionSecure} + Eventually(func() Session { return dialedSess }).ShouldNot(BeNil()) + close(done) + }) + It("Dial only returns after the handshake is complete", func(done Done) { var dialedSess Session go func() {