mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 20:57:36 +03:00
use a tracer to check for received 0-RTT packet in 0-RTT integration tests
This commit is contained in:
parent
7042ef8f8f
commit
bab0384444
1 changed files with 130 additions and 41 deletions
|
@ -11,15 +11,35 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
quic "github.com/lucas-clemente/quic-go"
|
"github.com/lucas-clemente/quic-go"
|
||||||
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
|
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
"github.com/lucas-clemente/quic-go/internal/wire"
|
"github.com/lucas-clemente/quic-go/internal/wire"
|
||||||
|
"github.com/lucas-clemente/quic-go/logging"
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type rcvdPacketTracer struct {
|
||||||
|
connTracer
|
||||||
|
closed chan struct{}
|
||||||
|
rcvdPackets []*logging.ExtendedHeader
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRcvdPacketTracer() *rcvdPacketTracer {
|
||||||
|
return &rcvdPacketTracer{closed: make(chan struct{})}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *rcvdPacketTracer) ReceivedPacket(hdr *logging.ExtendedHeader, _ logging.ByteCount, _ []logging.Frame) {
|
||||||
|
t.rcvdPackets = append(t.rcvdPackets, hdr)
|
||||||
|
}
|
||||||
|
func (t *rcvdPacketTracer) Close() { close(t.closed) }
|
||||||
|
func (t *rcvdPacketTracer) getRcvdPackets() []*logging.ExtendedHeader {
|
||||||
|
<-t.closed
|
||||||
|
return t.rcvdPackets
|
||||||
|
}
|
||||||
|
|
||||||
var _ = Describe("0-RTT", func() {
|
var _ = Describe("0-RTT", func() {
|
||||||
rtt := scaleDuration(5 * time.Millisecond)
|
rtt := scaleDuration(5 * time.Millisecond)
|
||||||
|
|
||||||
|
@ -45,8 +65,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
return proxy, &num0RTTPackets
|
return proxy, &num0RTTPackets
|
||||||
}
|
}
|
||||||
|
|
||||||
// serverConf can be nil. We'll use a config that disables Retries then.
|
dialAndReceiveSessionTicket := func(serverConf *quic.Config) (*tls.Config, *tls.Config) {
|
||||||
dialAndReceiveSessionTicket := func(serverConf *quic.Config) (quic.EarlyListener, *tls.Config, *tls.Config) {
|
|
||||||
tlsConf := getTLSConfig()
|
tlsConf := getTLSConfig()
|
||||||
if serverConf == nil {
|
if serverConf == nil {
|
||||||
serverConf = getQuicConfig(&quic.Config{
|
serverConf = getQuicConfig(&quic.Config{
|
||||||
|
@ -60,6 +79,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
serverConf,
|
serverConf,
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer ln.Close()
|
||||||
|
|
||||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||||
RemoteAddr: fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
|
RemoteAddr: fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
|
||||||
|
@ -92,7 +112,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
// received the session ticket. We're done here.
|
// received the session ticket. We're done here.
|
||||||
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
||||||
Eventually(done).Should(BeClosed())
|
Eventually(done).Should(BeClosed())
|
||||||
return ln, tlsConf, clientConf
|
return tlsConf, clientConf
|
||||||
}
|
}
|
||||||
|
|
||||||
transfer0RTTData := func(
|
transfer0RTTData := func(
|
||||||
|
@ -114,6 +134,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(data).To(Equal(testdata))
|
Expect(data).To(Equal(testdata))
|
||||||
Expect(sess.ConnectionState().TLS.Used0RTT).To(Equal(expect0RTT))
|
Expect(sess.ConnectionState().TLS.Used0RTT).To(Equal(expect0RTT))
|
||||||
|
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
||||||
close(done)
|
close(done)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -123,6 +144,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
|
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer sess.CloseWithError(0, "")
|
||||||
str, err := sess.OpenUniStream()
|
str, err := sess.OpenUniStream()
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
_, err = str.Write(testdata)
|
_, err = str.Write(testdata)
|
||||||
|
@ -130,6 +152,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
Expect(str.Close()).To(Succeed())
|
Expect(str.Close()).To(Succeed())
|
||||||
Expect(sess.ConnectionState().TLS.Used0RTT).To(Equal(expect0RTT))
|
Expect(sess.ConnectionState().TLS.Used0RTT).To(Equal(expect0RTT))
|
||||||
Eventually(done).Should(BeClosed())
|
Eventually(done).Should(BeClosed())
|
||||||
|
Eventually(sess.Context().Done()).Should(BeClosed())
|
||||||
}
|
}
|
||||||
|
|
||||||
check0RTTRejected := func(
|
check0RTTRejected := func(
|
||||||
|
@ -158,10 +181,36 @@ var _ = Describe("0-RTT", func() {
|
||||||
Expect(serverSess.ConnectionState().TLS.Used0RTT).To(BeFalse())
|
Expect(serverSess.ConnectionState().TLS.Used0RTT).To(BeFalse())
|
||||||
_, err = serverSess.AcceptUniStream(ctx)
|
_, err = serverSess.AcceptUniStream(ctx)
|
||||||
Expect(err).To(Equal(context.DeadlineExceeded))
|
Expect(err).To(Equal(context.DeadlineExceeded))
|
||||||
|
Expect(serverSess.CloseWithError(0, "")).To(Succeed())
|
||||||
|
Eventually(sess.Context().Done()).Should(BeClosed())
|
||||||
|
}
|
||||||
|
|
||||||
|
// can be used to extract 0-RTT from a rcvdPacketTracer
|
||||||
|
get0RTTPackets := func(hdrs []*logging.ExtendedHeader) []protocol.PacketNumber {
|
||||||
|
var zeroRTTPackets []protocol.PacketNumber
|
||||||
|
for _, hdr := range hdrs {
|
||||||
|
if hdr.Type == protocol.PacketType0RTT {
|
||||||
|
zeroRTTPackets = append(zeroRTTPackets, hdr.PacketNumber)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return zeroRTTPackets
|
||||||
}
|
}
|
||||||
|
|
||||||
It("transfers 0-RTT data", func() {
|
It("transfers 0-RTT data", func() {
|
||||||
ln, _, clientConf := dialAndReceiveSessionTicket(nil)
|
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
||||||
|
|
||||||
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
|
"localhost:0",
|
||||||
|
tlsConf,
|
||||||
|
getQuicConfig(&quic.Config{
|
||||||
|
Versions: []protocol.VersionNumber{version},
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer ln.Close()
|
||||||
|
|
||||||
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
||||||
defer proxy.Close()
|
defer proxy.Close()
|
||||||
|
|
||||||
|
@ -170,21 +219,31 @@ var _ = Describe("0-RTT", func() {
|
||||||
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
||||||
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
||||||
Expect(num0RTT).ToNot(BeZero())
|
Expect(num0RTT).ToNot(BeZero())
|
||||||
|
// TODO(#2629): ensure that this is a contiguous block of packets, starting at packet 0
|
||||||
|
Expect(get0RTTPackets(tracer.getRcvdPackets())).ToNot(BeEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
// Test that data intended to be sent with 1-RTT protection is not sent in 0-RTT packets.
|
// Test that data intended to be sent with 1-RTT protection is not sent in 0-RTT packets.
|
||||||
It("waits until a session until the handshake is done", func() {
|
It("waits until a session until the handshake is done", func() {
|
||||||
ln, _, clientConf := dialAndReceiveSessionTicket(nil)
|
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
|
||||||
defer proxy.Close()
|
|
||||||
|
|
||||||
zeroRTTData := GeneratePRData(2 * 1100) // 2 packets
|
zeroRTTData := GeneratePRData(2 * 1100) // 2 packets
|
||||||
oneRTTData := PRData
|
oneRTTData := PRData
|
||||||
|
|
||||||
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
|
"localhost:0",
|
||||||
|
tlsConf,
|
||||||
|
getQuicConfig(&quic.Config{
|
||||||
|
Versions: []protocol.VersionNumber{version},
|
||||||
|
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer ln.Close()
|
||||||
|
|
||||||
// now dial the second session, and use 0-RTT to send some data
|
// now dial the second session, and use 0-RTT to send some data
|
||||||
done := make(chan struct{})
|
|
||||||
go func() {
|
go func() {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
sess, err := ln.Accept(context.Background())
|
sess, err := ln.Accept(context.Background())
|
||||||
|
@ -199,9 +258,12 @@ var _ = Describe("0-RTT", func() {
|
||||||
data, err = ioutil.ReadAll(str)
|
data, err = ioutil.ReadAll(str)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(data).To(Equal(oneRTTData))
|
Expect(data).To(Equal(oneRTTData))
|
||||||
close(done)
|
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
||||||
|
defer proxy.Close()
|
||||||
|
|
||||||
sess, err := quic.DialAddrEarly(
|
sess, err := quic.DialAddrEarly(
|
||||||
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
|
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
|
||||||
clientConf,
|
clientConf,
|
||||||
|
@ -227,12 +289,13 @@ var _ = Describe("0-RTT", func() {
|
||||||
_, err = str.Write(PRData)
|
_, err = str.Write(PRData)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(str.Close()).To(Succeed())
|
Expect(str.Close()).To(Succeed())
|
||||||
|
<-sess.Context().Done()
|
||||||
Eventually(done).Should(BeClosed())
|
|
||||||
|
|
||||||
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
||||||
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
||||||
Expect(num0RTT).To(Or(BeEquivalentTo(2), BeEquivalentTo(3))) // the FIN might be sent in a separate packet
|
Expect(num0RTT).To(Or(BeEquivalentTo(2), BeEquivalentTo(3))) // the FIN might be sent in a separate packet
|
||||||
|
// TODO(#2629): check that packets are sent
|
||||||
|
// Expect(get0RTTPackets(tracer.getRcvdPackets())).ToNot(BeEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("transfers 0-RTT data, when 0-RTT packets are lost", func() {
|
It("transfers 0-RTT data, when 0-RTT packets are lost", func() {
|
||||||
|
@ -241,7 +304,18 @@ var _ = Describe("0-RTT", func() {
|
||||||
num0RTTDropped uint32
|
num0RTTDropped uint32
|
||||||
)
|
)
|
||||||
|
|
||||||
ln, _, clientConf := dialAndReceiveSessionTicket(nil)
|
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
||||||
|
|
||||||
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
|
"localhost:0",
|
||||||
|
tlsConf,
|
||||||
|
getQuicConfig(&quic.Config{
|
||||||
|
Versions: []protocol.VersionNumber{version},
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer ln.Close()
|
defer ln.Close()
|
||||||
|
|
||||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||||
|
@ -278,6 +352,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets. Dropped %d of those.", num0RTT, numDropped)
|
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets. Dropped %d of those.", num0RTT, numDropped)
|
||||||
Expect(numDropped).ToNot(BeZero())
|
Expect(numDropped).ToNot(BeZero())
|
||||||
Expect(num0RTT).ToNot(BeZero())
|
Expect(num0RTT).ToNot(BeZero())
|
||||||
|
Expect(get0RTTPackets(tracer.getRcvdPackets())).ToNot(BeEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("retransmits all 0-RTT data when the server performs a Retry", func() {
|
It("retransmits all 0-RTT data when the server performs a Retry", func() {
|
||||||
|
@ -285,8 +360,7 @@ var _ = Describe("0-RTT", func() {
|
||||||
var firstConnID, secondConnID protocol.ConnectionID
|
var firstConnID, secondConnID protocol.ConnectionID
|
||||||
var firstCounter, secondCounter protocol.ByteCount
|
var firstCounter, secondCounter protocol.ByteCount
|
||||||
|
|
||||||
ln, tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
countZeroRTTBytes := func(data []byte) (n protocol.ByteCount) {
|
countZeroRTTBytes := func(data []byte) (n protocol.ByteCount) {
|
||||||
for len(data) > 0 {
|
for len(data) > 0 {
|
||||||
|
@ -302,16 +376,20 @@ var _ = Describe("0-RTT", func() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ln2, err := quic.ListenAddrEarly(
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
"localhost:0",
|
"localhost:0",
|
||||||
tlsConf,
|
tlsConf,
|
||||||
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
|
getQuicConfig(&quic.Config{
|
||||||
|
Versions: []protocol.VersionNumber{version},
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
|
}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer ln2.Close()
|
defer ln.Close()
|
||||||
|
|
||||||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
|
||||||
RemoteAddr: fmt.Sprintf("localhost:%d", ln2.Addr().(*net.UDPAddr).Port),
|
RemoteAddr: fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
|
||||||
DelayPacket: func(dir quicproxy.Direction, data []byte) time.Duration {
|
DelayPacket: func(dir quicproxy.Direction, data []byte) time.Duration {
|
||||||
connID, err := wire.ParseConnectionID(data, 0)
|
connID, err := wire.ParseConnectionID(data, 0)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
@ -341,100 +419,109 @@ var _ = Describe("0-RTT", func() {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer proxy.Close()
|
defer proxy.Close()
|
||||||
|
|
||||||
transfer0RTTData(ln2, proxy.LocalPort(), clientConf, GeneratePRData(5000), true) // ~5 packets
|
transfer0RTTData(ln, proxy.LocalPort(), clientConf, GeneratePRData(5000), true) // ~5 packets
|
||||||
|
|
||||||
mutex.Lock()
|
mutex.Lock()
|
||||||
defer mutex.Unlock()
|
defer mutex.Unlock()
|
||||||
Expect(firstCounter).To(BeNumerically("~", 5000+100 /* framing overhead */, 100)) // the FIN bit might be sent extra
|
Expect(firstCounter).To(BeNumerically("~", 5000+100 /* framing overhead */, 100)) // the FIN bit might be sent extra
|
||||||
Expect(secondCounter).To(BeNumerically("~", firstCounter, 20))
|
Expect(secondCounter).To(BeNumerically("~", firstCounter, 20))
|
||||||
|
zeroRTTPackets := get0RTTPackets(tracer.getRcvdPackets())
|
||||||
|
// TODO(#2629): We should receive 5 packets here.
|
||||||
|
Expect(len(zeroRTTPackets)).To(BeNumerically(">=", 1))
|
||||||
|
Expect(zeroRTTPackets[0]).To(BeNumerically(">", protocol.PacketNumber(1)))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("rejects 0-RTT when the server's transport parameters changed", func() {
|
It("rejects 0-RTT when the server's transport parameters changed", func() {
|
||||||
const maxStreams = 42
|
const maxStreams = 42
|
||||||
ln, tlsConf, clientConf := dialAndReceiveSessionTicket(getQuicConfig(&quic.Config{
|
tlsConf, clientConf := dialAndReceiveSessionTicket(getQuicConfig(&quic.Config{
|
||||||
MaxIncomingStreams: maxStreams,
|
MaxIncomingStreams: maxStreams,
|
||||||
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
||||||
}))
|
}))
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
ln2, err := quic.ListenAddrEarly(
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
"localhost:0",
|
"localhost:0",
|
||||||
tlsConf,
|
tlsConf,
|
||||||
getQuicConfig(&quic.Config{
|
getQuicConfig(&quic.Config{
|
||||||
Versions: []protocol.VersionNumber{version},
|
Versions: []protocol.VersionNumber{version},
|
||||||
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
||||||
MaxIncomingStreams: maxStreams + 1,
|
MaxIncomingStreams: maxStreams + 1,
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer ln2.Close()
|
defer ln.Close()
|
||||||
proxy, num0RTTPackets := runCountingProxy(ln2.Addr().(*net.UDPAddr).Port)
|
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
||||||
defer proxy.Close()
|
defer proxy.Close()
|
||||||
check0RTTRejected(ln2, proxy.LocalPort(), clientConf)
|
check0RTTRejected(ln, proxy.LocalPort(), clientConf)
|
||||||
|
|
||||||
// The client should send 0-RTT packets, but the server doesn't process them.
|
// The client should send 0-RTT packets, but the server doesn't process them.
|
||||||
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
||||||
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
||||||
Expect(num0RTT).ToNot(BeZero())
|
Expect(num0RTT).ToNot(BeZero())
|
||||||
|
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(BeEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("rejects 0-RTT when the ALPN changed", func() {
|
It("rejects 0-RTT when the ALPN changed", func() {
|
||||||
ln, tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
||||||
defer ln.Close()
|
|
||||||
|
|
||||||
// now close the listener and dial new connection with a different ALPN
|
// now close the listener and dial new connection with a different ALPN
|
||||||
Expect(ln.Close()).To(Succeed())
|
|
||||||
clientConf.NextProtos = []string{"new-alpn"}
|
clientConf.NextProtos = []string{"new-alpn"}
|
||||||
tlsConf.NextProtos = []string{"new-alpn"}
|
tlsConf.NextProtos = []string{"new-alpn"}
|
||||||
ln2, err := quic.ListenAddrEarly(
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
"localhost:0",
|
"localhost:0",
|
||||||
tlsConf,
|
tlsConf,
|
||||||
getQuicConfig(&quic.Config{
|
getQuicConfig(&quic.Config{
|
||||||
Versions: []protocol.VersionNumber{version},
|
Versions: []protocol.VersionNumber{version},
|
||||||
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer ln2.Close()
|
defer ln.Close()
|
||||||
proxy, num0RTTPackets := runCountingProxy(ln2.Addr().(*net.UDPAddr).Port)
|
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
||||||
defer proxy.Close()
|
defer proxy.Close()
|
||||||
|
|
||||||
check0RTTRejected(ln2, proxy.LocalPort(), clientConf)
|
check0RTTRejected(ln, proxy.LocalPort(), clientConf)
|
||||||
|
|
||||||
// The client should send 0-RTT packets, but the server doesn't process them.
|
// The client should send 0-RTT packets, but the server doesn't process them.
|
||||||
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
||||||
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
||||||
Expect(num0RTT).ToNot(BeZero())
|
Expect(num0RTT).ToNot(BeZero())
|
||||||
|
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(BeEmpty())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("correctly deals with 0-RTT rejections", func() {
|
It("correctly deals with 0-RTT rejections", func() {
|
||||||
ln, tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
|
||||||
defer ln.Close()
|
|
||||||
// now dial new connection with different transport parameters
|
// now dial new connection with different transport parameters
|
||||||
ln2, err := quic.ListenAddrEarly(
|
tracer := newRcvdPacketTracer()
|
||||||
|
ln, err := quic.ListenAddrEarly(
|
||||||
"localhost:0",
|
"localhost:0",
|
||||||
tlsConf,
|
tlsConf,
|
||||||
getQuicConfig(&quic.Config{
|
getQuicConfig(&quic.Config{
|
||||||
Versions: []protocol.VersionNumber{version},
|
Versions: []protocol.VersionNumber{version},
|
||||||
MaxIncomingUniStreams: 1,
|
MaxIncomingUniStreams: 1,
|
||||||
|
Tracer: newTracer(func() logging.ConnectionTracer { return tracer }),
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
defer ln2.Close()
|
defer ln.Close()
|
||||||
proxy, num0RTTPackets := runCountingProxy(ln2.Addr().(*net.UDPAddr).Port)
|
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
|
||||||
defer proxy.Close()
|
defer proxy.Close()
|
||||||
|
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
go func() {
|
go func() {
|
||||||
defer GinkgoRecover()
|
defer GinkgoRecover()
|
||||||
defer close(done)
|
defer close(done)
|
||||||
sess, err := ln2.Accept(context.Background())
|
sess, err := ln.Accept(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
str, err := sess.AcceptUniStream(context.Background())
|
str, err := sess.AcceptUniStream(context.Background())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
data, err := ioutil.ReadAll(str)
|
data, err := ioutil.ReadAll(str)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(string(data)).To(Equal("second flight"))
|
Expect(string(data)).To(Equal("second flight"))
|
||||||
|
Expect(sess.CloseWithError(0, "")).To(Succeed())
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sess, err := quic.DialAddrEarly(
|
sess, err := quic.DialAddrEarly(
|
||||||
|
@ -470,11 +557,13 @@ var _ = Describe("0-RTT", func() {
|
||||||
Expect(str.Close()).To(Succeed())
|
Expect(str.Close()).To(Succeed())
|
||||||
|
|
||||||
Eventually(done).Should(BeClosed())
|
Eventually(done).Should(BeClosed())
|
||||||
|
Eventually(sess.Context().Done()).Should(BeClosed())
|
||||||
|
|
||||||
// The client should send 0-RTT packets, but the server doesn't process them.
|
// The client should send 0-RTT packets, but the server doesn't process them.
|
||||||
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
num0RTT := atomic.LoadUint32(num0RTTPackets)
|
||||||
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
|
||||||
Expect(num0RTT).ToNot(BeZero())
|
Expect(num0RTT).ToNot(BeZero())
|
||||||
|
Expect(get0RTTPackets(tracer.getRcvdPackets())).To(BeEmpty())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue