replace usages of session in variable names

This commit is contained in:
Marten Seemann 2022-03-26 15:05:35 +01:00
parent e71c236232
commit fda9f72161
23 changed files with 373 additions and 373 deletions

View file

@ -22,7 +22,7 @@ var _ = Describe("Stream Cancelations", func() {
Context("canceling the read side", func() {
var server quic.Listener
// The server accepts a single session, and then opens numStreams unidirectional streams.
// The server accepts a single connection, and then opens numStreams unidirectional streams.
// On each of these streams, it (tries to) write PRData.
// When done, it sends the number of canceled streams on the channel.
runServer := func(data []byte) <-chan int32 {
@ -36,13 +36,13 @@ var _ = Describe("Stream Cancelations", func() {
defer GinkgoRecover()
var wg sync.WaitGroup
wg.Add(numStreams)
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
for i := 0; i < numStreams; i++ {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
if _, err := str.Write(data); err != nil {
Expect(err).To(MatchError(&quic.StreamError{
@ -71,7 +71,7 @@ var _ = Describe("Stream Cancelations", func() {
It("downloads when the client immediately cancels most streams", func() {
serverCanceledCounterChan := runServer(PRData)
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
@ -85,7 +85,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
// cancel around 2/3 of the streams
if rand.Int31()%3 != 0 {
@ -102,7 +102,7 @@ var _ = Describe("Stream Cancelations", func() {
var serverCanceledCounter int32
Eventually(serverCanceledCounterChan).Should(Receive(&serverCanceledCounter))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
clientCanceledCounter := atomic.LoadInt32(&canceledCounter)
// The server will only count a stream as being reset if learns about the cancelation before it finished writing all data.
@ -115,7 +115,7 @@ var _ = Describe("Stream Cancelations", func() {
It("downloads when the client cancels streams after reading from them for a bit", func() {
serverCanceledCounterChan := runServer(PRData)
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
@ -129,7 +129,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
// only read some data from about 1/3 of the streams
if rand.Int31()%3 != 0 {
@ -150,7 +150,7 @@ var _ = Describe("Stream Cancelations", func() {
var serverCanceledCounter int32
Eventually(serverCanceledCounterChan).Should(Receive(&serverCanceledCounter))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
clientCanceledCounter := atomic.LoadInt32(&canceledCounter)
// The server will only count a stream as being reset if learns about the cancelation before it finished writing all data.
@ -165,7 +165,7 @@ var _ = Describe("Stream Cancelations", func() {
// see https://github.com/lucas-clemente/quic-go/issues/3239.
serverCanceledCounterChan := runServer(make([]byte, 100)) // make sure the FIN is sent with the STREAM frame
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
@ -179,7 +179,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
done := make(chan struct{})
@ -198,7 +198,7 @@ var _ = Describe("Stream Cancelations", func() {
}()
}
wg.Wait()
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
numCanceled := atomic.LoadInt32(&counter)
fmt.Fprintf(GinkgoWriter, "canceled %d out of %d streams", numCanceled, numStreams)
Expect(numCanceled).ToNot(BeZero())
@ -208,7 +208,7 @@ var _ = Describe("Stream Cancelations", func() {
Context("canceling the write side", func() {
runClient := func(server quic.Listener) int32 /* number of canceled streams */ {
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
@ -222,7 +222,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
if err != nil {
@ -242,7 +242,7 @@ var _ = Describe("Stream Cancelations", func() {
fmt.Fprintf(GinkgoWriter, "Canceled writing on %d of %d streams\n", streamCount, numStreams)
Expect(streamCount).To(BeNumerically(">", numStreams/10))
Expect(numStreams - streamCount).To(BeNumerically(">", numStreams/10))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Expect(server.Close()).To(Succeed())
return streamCount
}
@ -254,12 +254,12 @@ var _ = Describe("Stream Cancelations", func() {
var canceledCounter int32
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
for i := 0; i < numStreams; i++ {
go func() {
defer GinkgoRecover()
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
// cancel about 2/3 of the streams
if rand.Int31()%3 != 0 {
@ -285,12 +285,12 @@ var _ = Describe("Stream Cancelations", func() {
var canceledCounter int32
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
for i := 0; i < numStreams; i++ {
go func() {
defer GinkgoRecover()
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
// only write some data from about 1/3 of the streams, then cancel
if rand.Int31()%3 != 0 {
@ -323,13 +323,13 @@ var _ = Describe("Stream Cancelations", func() {
defer GinkgoRecover()
var wg sync.WaitGroup
wg.Add(numStreams)
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
for i := 0; i < numStreams; i++ {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
// cancel about half of the streams
if rand.Int31()%2 == 0 {
@ -353,7 +353,7 @@ var _ = Describe("Stream Cancelations", func() {
close(done)
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
@ -367,7 +367,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
// cancel around half of the streams
if rand.Int31()%2 == 0 {
@ -392,7 +392,7 @@ var _ = Describe("Stream Cancelations", func() {
Expect(count).To(BeNumerically(">", numStreams/15))
fmt.Fprintf(GinkgoWriter, "Successfully read from %d of %d streams.\n", count, numStreams)
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Eventually(done).Should(BeClosed())
Expect(server.Close()).To(Succeed())
})
@ -405,7 +405,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer close(done)
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
var wg sync.WaitGroup
wg.Add(numStreams)
@ -413,7 +413,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
// cancel about half of the streams
length := len(PRData)
@ -438,7 +438,7 @@ var _ = Describe("Stream Cancelations", func() {
wg.Wait()
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 2}),
@ -453,7 +453,7 @@ var _ = Describe("Stream Cancelations", func() {
defer GinkgoRecover()
defer wg.Done()
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
r := io.Reader(str)
@ -488,7 +488,7 @@ var _ = Describe("Stream Cancelations", func() {
Expect(count).To(BeNumerically(">", numStreams/15))
fmt.Fprintf(GinkgoWriter, "Successfully read from %d of %d streams.\n", count, numStreams)
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Expect(server.Close()).To(Succeed())
})
})
@ -500,14 +500,14 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
ticker := time.NewTicker(5 * time.Millisecond)
for i := 0; i < numStreams; i++ {
<-ticker.C
go func() {
defer GinkgoRecover()
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
@ -516,7 +516,7 @@ var _ = Describe("Stream Cancelations", func() {
}
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: numStreams / 3}),
@ -539,7 +539,7 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
str, err := sess.AcceptUniStream(ctx)
str, err := conn.AcceptUniStream(ctx)
if err != nil {
if err.Error() == "context canceled" {
atomic.AddInt32(&counter, 1)
@ -557,7 +557,7 @@ var _ = Describe("Stream Cancelations", func() {
count := atomic.LoadInt32(&counter)
fmt.Fprintf(GinkgoWriter, "Canceled AcceptStream %d times\n", count)
Expect(count).To(BeNumerically(">", numStreams/2))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Expect(server.Close()).To(Succeed())
})
@ -574,14 +574,14 @@ var _ = Describe("Stream Cancelations", func() {
go func() {
defer GinkgoRecover()
defer close(msg)
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
var numOpened int
for numOpened < numStreams {
ctx, cancel := context.WithTimeout(context.Background(), scaleDuration(20*time.Millisecond))
defer cancel()
str, err := sess.OpenUniStreamSync(ctx)
str, err := conn.OpenUniStreamSync(ctx)
if err != nil {
Expect(err).To(MatchError(context.DeadlineExceeded))
atomic.AddInt32(&numCanceled, 1)
@ -601,7 +601,7 @@ var _ = Describe("Stream Cancelations", func() {
}
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIncomingUniStreams: maxIncomingStreams}),
@ -612,7 +612,7 @@ var _ = Describe("Stream Cancelations", func() {
wg.Add(numStreams)
for i := 0; i < numStreams; i++ {
<-msg
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
go func(str quic.ReceiveStream) {
defer GinkgoRecover()
@ -627,7 +627,7 @@ var _ = Describe("Stream Cancelations", func() {
count := atomic.LoadInt32(&numCanceled)
fmt.Fprintf(GinkgoWriter, "Canceled OpenStreamSync %d times\n", count)
Expect(count).To(BeNumerically(">=", numStreams-maxIncomingStreams))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Expect(server.Close()).To(Succeed())
})
})
@ -686,7 +686,7 @@ var _ = Describe("Stream Cancelations", func() {
for {
str, err := conn.AcceptStream(context.Background())
if err != nil {
// Make sure the session is closed regularly.
// Make sure the connection is closed regularly.
Expect(err).To(BeAssignableToTypeOf(&quic.ApplicationError{}))
return
}
@ -694,7 +694,7 @@ var _ = Describe("Stream Cancelations", func() {
}
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{}),
@ -702,21 +702,21 @@ var _ = Describe("Stream Cancelations", func() {
Expect(err).ToNot(HaveOccurred())
for i := 0; i < maxIncomingStreams; i++ {
str, err := sess.OpenStreamSync(context.Background())
str, err := conn.OpenStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
handleStream(str)
}
// We don't expect to accept any stream here.
// We're just making sure the session stays open and there's no error.
// We're just making sure the connection stays open and there's no error.
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
defer cancel()
_, err = sess.AcceptStream(ctx)
_, err = conn.AcceptStream(ctx)
Expect(err).To(MatchError(context.DeadlineExceeded))
wg.Wait()
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Eventually(serverRunning).Should(BeClosed())
})
})

View file

@ -7,7 +7,7 @@ import (
"math/rand"
"net"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
@ -26,13 +26,13 @@ var _ = Describe("Connection ID lengths tests", func() {
go func() {
defer GinkgoRecover()
for {
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
if err != nil {
return
}
go func() {
defer GinkgoRecover()
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(PRData)

View file

@ -47,9 +47,9 @@ var _ = Describe("Datagram test", func() {
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(sess.ConnectionState().SupportsDatagrams).To(BeTrue())
Expect(conn.ConnectionState().SupportsDatagrams).To(BeTrue())
var wg sync.WaitGroup
wg.Add(num)
@ -59,7 +59,7 @@ var _ = Describe("Datagram test", func() {
defer wg.Done()
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, uint64(i))
Expect(sess.SendMessage(b)).To(Succeed())
Expect(conn.SendMessage(b)).To(Succeed())
}(i)
}
wg.Wait()
@ -102,7 +102,7 @@ var _ = Describe("Datagram test", func() {
startServerAndProxy()
raddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("localhost:%d", proxy.LocalPort()))
Expect(err).ToNot(HaveOccurred())
sess, err := quic.Dial(
conn, err := quic.Dial(
clientConn,
raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
@ -113,14 +113,14 @@ var _ = Describe("Datagram test", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
Expect(sess.ConnectionState().SupportsDatagrams).To(BeTrue())
Expect(conn.ConnectionState().SupportsDatagrams).To(BeTrue())
var counter int
for {
// Close the session if no message is received for 100 ms.
// Close the connection if no message is received for 100 ms.
timer := time.AfterFunc(scaleDuration(100*time.Millisecond), func() {
sess.CloseWithError(0, "")
conn.CloseWithError(0, "")
})
if _, err := sess.ReceiveMessage(); err != nil {
if _, err := conn.ReceiveMessage(); err != nil {
break
}
timer.Stop()

View file

@ -20,22 +20,22 @@ var _ = Describe("Stream deadline tests", func() {
strChan := make(chan quic.SendStream)
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
_, err = str.Read([]byte{0})
Expect(err).ToNot(HaveOccurred())
strChan <- str
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(nil),
)
Expect(err).ToNot(HaveOccurred())
clientStr, err := sess.OpenStream()
clientStr, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = clientStr.Write([]byte{0}) // need to write one byte so the server learns about the stream
Expect(err).ToNot(HaveOccurred())

View file

@ -8,7 +8,7 @@ import (
"sync/atomic"
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -87,9 +87,9 @@ var _ = Describe("Drop Tests", func() {
done := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
for i := uint8(1); i <= numMessages; i++ {
n, err := str.Write([]byte{i})
@ -98,17 +98,17 @@ var _ = Describe("Drop Tests", func() {
time.Sleep(messageInterval)
}
<-done
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
str, err := sess.AcceptStream(context.Background())
defer conn.CloseWithError(0, "")
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
for i := uint8(1); i <= numMessages; i++ {
b := []byte{0}

View file

@ -7,7 +7,7 @@ import (
"net"
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -32,16 +32,16 @@ var _ = Describe("early data", func() {
go func() {
defer GinkgoRecover()
defer close(done)
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("early data"))
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
// make sure the Write finished before the handshake completed
Expect(sess.HandshakeComplete().Done()).ToNot(BeClosed())
Eventually(sess.Context().Done()).Should(BeClosed())
Expect(conn.HandshakeComplete().Done()).ToNot(BeClosed())
Eventually(conn.Context().Done()).Should(BeClosed())
}()
serverPort := ln.Addr().(*net.UDPAddr).Port
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{
@ -53,18 +53,18 @@ var _ = Describe("early data", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal([]byte("early data")))
sess.CloseWithError(0, "")
conn.CloseWithError(0, "")
Eventually(done).Should(BeClosed())
})
})

View file

@ -71,20 +71,20 @@ var _ = Describe("Handshake drop tests", func() {
clientSpeaksFirst := &applicationProtocol{
name: "client speaks first",
run: func(version protocol.VersionNumber) {
serverSessionChan := make(chan quic.Connection)
serverConnChan := make(chan quic.Connection)
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
str, err := sess.AcceptStream(context.Background())
defer conn.CloseWithError(0, "")
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
b, err := io.ReadAll(gbytes.TimeoutReader(str, timeout))
Expect(err).ToNot(HaveOccurred())
Expect(b).To(Equal(data))
serverSessionChan <- sess
serverConnChan <- conn
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -94,35 +94,35 @@ var _ = Describe("Handshake drop tests", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(data)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
var serverSession quic.Connection
Eventually(serverSessionChan, timeout).Should(Receive(&serverSession))
sess.CloseWithError(0, "")
serverSession.CloseWithError(0, "")
var serverConn quic.Connection
Eventually(serverConnChan, timeout).Should(Receive(&serverConn))
conn.CloseWithError(0, "")
serverConn.CloseWithError(0, "")
},
}
serverSpeaksFirst := &applicationProtocol{
name: "server speaks first",
run: func(version protocol.VersionNumber) {
serverSessionChan := make(chan quic.Connection)
serverConnChan := make(chan quic.Connection)
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(data)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
serverSessionChan <- sess
serverConnChan <- conn
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -132,30 +132,30 @@ var _ = Describe("Handshake drop tests", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
b, err := io.ReadAll(gbytes.TimeoutReader(str, timeout))
Expect(err).ToNot(HaveOccurred())
Expect(b).To(Equal(data))
var serverSession quic.Connection
Eventually(serverSessionChan, timeout).Should(Receive(&serverSession))
sess.CloseWithError(0, "")
serverSession.CloseWithError(0, "")
var serverConn quic.Connection
Eventually(serverConnChan, timeout).Should(Receive(&serverConn))
conn.CloseWithError(0, "")
serverConn.CloseWithError(0, "")
},
}
nobodySpeaks := &applicationProtocol{
name: "nobody speaks",
run: func(version protocol.VersionNumber) {
serverSessionChan := make(chan quic.Connection)
serverConnChan := make(chan quic.Connection)
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
serverSessionChan <- sess
serverConnChan <- conn
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -165,11 +165,11 @@ var _ = Describe("Handshake drop tests", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
var serverSession quic.Connection
Eventually(serverSessionChan, timeout).Should(Receive(&serverSession))
// both server and client accepted a session. Close now.
sess.CloseWithError(0, "")
serverSession.CloseWithError(0, "")
var serverConn quic.Connection
Eventually(serverConnChan, timeout).Should(Receive(&serverConn))
// both server and client accepted a connection. Close now.
conn.CloseWithError(0, "")
serverConn.CloseWithError(0, "")
},
}

View file

@ -131,14 +131,14 @@ var _ = Describe("Handshake tests", func() {
runServer(getTLSConfig())
defer server.Close()
clientTracer := &versionNegotiationTracer{}
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Tracer: newTracer(func() logging.ConnectionTracer { return clientTracer })}),
)
Expect(err).ToNot(HaveOccurred())
Expect(sess.(versioner).GetVersion()).To(Equal(expectedVersion))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.(versioner).GetVersion()).To(Equal(expectedVersion))
Expect(conn.CloseWithError(0, "")).To(Succeed())
Expect(clientTracer.chosen).To(Equal(expectedVersion))
Expect(clientTracer.receivedVersionNegotiation).To(BeFalse())
Expect(clientTracer.clientVersions).To(Equal(protocol.SupportedVersions))
@ -159,7 +159,7 @@ var _ = Describe("Handshake tests", func() {
defer server.Close()
clientVersions := []protocol.VersionNumber{7, 8, 9, protocol.SupportedVersions[0], 10}
clientTracer := &versionNegotiationTracer{}
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -168,8 +168,8 @@ var _ = Describe("Handshake tests", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
Expect(sess.(versioner).GetVersion()).To(Equal(protocol.SupportedVersions[0]))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.(versioner).GetVersion()).To(Equal(protocol.SupportedVersions[0]))
Expect(conn.CloseWithError(0, "")).To(Succeed())
Expect(clientTracer.chosen).To(Equal(expectedVersion))
Expect(clientTracer.receivedVersionNegotiation).To(BeTrue())
Expect(clientTracer.clientVersions).To(Equal(clientVersions))
@ -199,28 +199,28 @@ var _ = Describe("Handshake tests", func() {
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
nil,
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRData))
Expect(sess.ConnectionState().TLS.CipherSuite).To(Equal(suiteID))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.ConnectionState().TLS.CipherSuite).To(Equal(suiteID))
Expect(conn.CloseWithError(0, "")).To(Succeed())
})
}
})
@ -280,19 +280,19 @@ var _ = Describe("Handshake tests", func() {
tlsConf.ClientAuth = tls.RequireAndVerifyClientCert
runServer(tlsConf)
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
clientConfig,
)
// Usually, the error will occur after the client already finished the handshake.
// However, there's a race condition here. The server's CONNECTION_CLOSE might be
// received before the session is returned, so we might already get the error while dialing.
// received before the connection is returned, so we might already get the error while dialing.
if err == nil {
errChan := make(chan error)
go func() {
defer GinkgoRecover()
_, err := sess.AcceptStream(context.Background())
_, err := conn.AcceptStream(context.Background())
errChan <- err
}()
Eventually(errChan).Should(Receive(&err))
@ -368,11 +368,11 @@ var _ = Describe("Handshake tests", func() {
It("rejects new connection attempts if connections don't get accepted", func() {
for i := 0; i < protocol.MaxAcceptQueueSize; i++ {
sess, err := dial()
conn, err := dial()
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
defer conn.CloseWithError(0, "")
}
time.Sleep(25 * time.Millisecond) // wait a bit for the sessions to be queued
time.Sleep(25 * time.Millisecond) // wait a bit for the connection to be queued
_, err := dial()
Expect(err).To(HaveOccurred())
@ -380,14 +380,14 @@ var _ = Describe("Handshake tests", func() {
Expect(errors.As(err, &transportErr)).To(BeTrue())
Expect(transportErr.ErrorCode).To(Equal(quic.ConnectionRefused))
// now accept one session, freeing one spot in the queue
// now accept one connection, freeing one spot in the queue
_, err = server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
// dial again, and expect that this dial succeeds
sess, err := dial()
conn, err := dial()
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
time.Sleep(25 * time.Millisecond) // wait a bit for the session to be queued
defer conn.CloseWithError(0, "")
time.Sleep(25 * time.Millisecond) // wait a bit for the connection to be queued
_, err = dial()
Expect(err).To(HaveOccurred())
@ -396,15 +396,15 @@ var _ = Describe("Handshake tests", func() {
})
It("removes closed connections from the accept queue", func() {
firstSess, err := dial()
firstConn, err := dial()
Expect(err).ToNot(HaveOccurred())
for i := 1; i < protocol.MaxAcceptQueueSize; i++ {
sess, err := dial()
conn, err := dial()
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
defer conn.CloseWithError(0, "")
}
time.Sleep(scaleDuration(20 * time.Millisecond)) // wait a bit for the sessions to be queued
time.Sleep(scaleDuration(20 * time.Millisecond)) // wait a bit for the connection to be queued
_, err = dial()
Expect(err).To(HaveOccurred())
@ -412,16 +412,16 @@ var _ = Describe("Handshake tests", func() {
Expect(errors.As(err, &transportErr)).To(BeTrue())
Expect(transportErr.ErrorCode).To(Equal(quic.ConnectionRefused))
// Now close the one of the session that are waiting to be accepted.
// Now close the one of the connection that are waiting to be accepted.
// This should free one spot in the queue.
Expect(firstSess.CloseWithError(0, ""))
Eventually(firstSess.Context().Done()).Should(BeClosed())
Expect(firstConn.CloseWithError(0, ""))
Eventually(firstConn.Context().Done()).Should(BeClosed())
time.Sleep(scaleDuration(20 * time.Millisecond))
// dial again, and expect that this dial succeeds
_, err = dial()
Expect(err).ToNot(HaveOccurred())
time.Sleep(scaleDuration(20 * time.Millisecond)) // wait a bit for the session to be queued
time.Sleep(scaleDuration(20 * time.Millisecond)) // wait a bit for the connection to be queued
_, err = dial()
Expect(err).To(HaveOccurred())
@ -438,21 +438,21 @@ var _ = Describe("Handshake tests", func() {
done := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
cs := sess.ConnectionState()
cs := conn.ConnectionState()
Expect(cs.TLS.NegotiatedProtocol).To(Equal(alpn))
close(done)
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
nil,
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
cs := sess.ConnectionState()
defer conn.CloseWithError(0, "")
cs := conn.ConnectionState()
Expect(cs.TLS.NegotiatedProtocol).To(Equal(alpn))
Eventually(done).Should(BeClosed())
Expect(ln.Close()).To(Succeed())
@ -489,7 +489,7 @@ var _ = Describe("Handshake tests", func() {
server, err := quic.ListenAddr("localhost:0", getTLSConfig(), serverConfig)
Expect(err).ToNot(HaveOccurred())
// dial the first session and receive the token
// dial the first connection and receive the token
go func() {
defer GinkgoRecover()
_, err := server.Accept(context.Background())
@ -500,7 +500,7 @@ var _ = Describe("Handshake tests", func() {
puts := make(chan string, 100)
tokenStore := newTokenStore(gets, puts)
quicConf := getQuicConfig(&quic.Config{TokenStore: tokenStore})
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
quicConf,
@ -509,10 +509,10 @@ var _ = Describe("Handshake tests", func() {
Expect(gets).To(Receive())
Eventually(puts).Should(Receive())
Expect(tokenChan).ToNot(Receive())
// received a token. Close this session.
Expect(sess.CloseWithError(0, "")).To(Succeed())
// received a token. Close this connection.
Expect(conn.CloseWithError(0, "")).To(Succeed())
// dial the second session and verify that the token was used
// dial the second connection and verify that the token was used
done := make(chan struct{})
go func() {
defer GinkgoRecover()
@ -520,13 +520,13 @@ var _ = Describe("Handshake tests", func() {
_, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
}()
sess, err = quic.DialAddr(
conn, err = quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
quicConf,
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
defer conn.CloseWithError(0, "")
Expect(gets).To(Receive())
Expect(tokenChan).To(Receive())

View file

@ -171,7 +171,7 @@ var _ = Describe("HTTP3 Server hotswap test", func() {
Expect(ln.listenerClosed).ToNot(BeTrue())
Expect(client.Transport.(*http3.RoundTripper).Close()).NotTo(HaveOccurred())
// verify that new sessions are being initiated from the second server now
// verify that new connections are being initiated from the second server now
resp, err = client.Get("https://localhost:" + port + "/hello2")
Expect(err).ToNot(HaveOccurred())
Expect(resp.StatusCode).To(Equal(200))

View file

@ -6,7 +6,7 @@ import (
"io"
"net"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/handshake"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/logging"
@ -66,9 +66,9 @@ var _ = Describe("Key Update tests", func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(PRDataLong)
@ -82,18 +82,18 @@ var _ = Describe("Key Update tests", func() {
handshake.KeyUpdateInterval = 1 // update keys as frequently as possible
runServer()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Tracer: newTracer(func() logging.ConnectionTracer { return &keyUpdateConnTracer{} })}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRDataLong))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
keyPhasesSent, keyPhasesReceived := countKeyPhases()
fmt.Fprintf(GinkgoWriter, "Used %d key phases on outgoing and %d key phases on incoming packets.\n", keyPhasesSent, keyPhasesReceived)

View file

@ -30,24 +30,24 @@ var _ = Describe("MITM test", func() {
var (
proxy *quicproxy.QuicProxy
serverConn, clientConn *net.UDPConn
serverSess quic.Connection
serverUDPConn, clientUDPConn *net.UDPConn
serverConn quic.Connection
serverConfig *quic.Config
)
startServerAndProxy := func(delayCb quicproxy.DelayCallback, dropCb quicproxy.DropCallback) {
addr, err := net.ResolveUDPAddr("udp", "localhost:0")
Expect(err).ToNot(HaveOccurred())
serverConn, err = net.ListenUDP("udp", addr)
serverUDPConn, err = net.ListenUDP("udp", addr)
Expect(err).ToNot(HaveOccurred())
ln, err := quic.Listen(serverConn, getTLSConfig(), serverConfig)
ln, err := quic.Listen(serverUDPConn, getTLSConfig(), serverConfig)
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
var err error
serverSess, err = ln.Accept(context.Background())
serverConn, err = ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := serverSess.OpenUniStream()
str, err := serverConn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
@ -69,17 +69,17 @@ var _ = Describe("MITM test", func() {
})
addr, err := net.ResolveUDPAddr("udp", "localhost:0")
Expect(err).ToNot(HaveOccurred())
clientConn, err = net.ListenUDP("udp", addr)
clientUDPConn, err = net.ListenUDP("udp", addr)
Expect(err).ToNot(HaveOccurred())
})
Context("unsuccessful attacks", func() {
AfterEach(func() {
Eventually(serverSess.Context().Done()).Should(BeClosed())
Eventually(serverConn.Context().Done()).Should(BeClosed())
// Test shutdown is tricky due to the proxy. Just wait for a bit.
time.Sleep(50 * time.Millisecond)
Expect(clientConn.Close()).To(Succeed())
Expect(serverConn.Close()).To(Succeed())
Expect(clientUDPConn.Close()).To(Succeed())
Expect(serverUDPConn.Close()).To(Succeed())
Expect(proxy.Close()).To(Succeed())
})
@ -123,8 +123,8 @@ var _ = Describe("MITM test", func() {
startServerAndProxy(delayCb, nil)
raddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("localhost:%d", proxy.LocalPort()))
Expect(err).ToNot(HaveOccurred())
sess, err := quic.Dial(
clientConn,
conn, err := quic.Dial(
clientUDPConn,
raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
@ -134,19 +134,19 @@ var _ = Describe("MITM test", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRData))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
}
It("downloads a message when the packets are injected towards the server", func() {
delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration {
if dir == quicproxy.DirectionIncoming {
defer GinkgoRecover()
go sendRandomPacketsOfSameType(clientConn, serverConn.LocalAddr(), raw)
go sendRandomPacketsOfSameType(clientUDPConn, serverUDPConn.LocalAddr(), raw)
}
return rtt / 2
}
@ -157,7 +157,7 @@ var _ = Describe("MITM test", func() {
delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration {
if dir == quicproxy.DirectionOutgoing {
defer GinkgoRecover()
go sendRandomPacketsOfSameType(serverConn, clientConn.LocalAddr(), raw)
go sendRandomPacketsOfSameType(serverUDPConn, clientUDPConn.LocalAddr(), raw)
}
return rtt / 2
}
@ -169,8 +169,8 @@ var _ = Describe("MITM test", func() {
startServerAndProxy(nil, dropCb)
raddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("localhost:%d", proxy.LocalPort()))
Expect(err).ToNot(HaveOccurred())
sess, err := quic.Dial(
clientConn,
conn, err := quic.Dial(
clientUDPConn,
raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
@ -180,12 +180,12 @@ var _ = Describe("MITM test", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRData))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
}
Context("duplicating packets", func() {
@ -193,7 +193,7 @@ var _ = Describe("MITM test", func() {
dropCb := func(dir quicproxy.Direction, raw []byte) bool {
defer GinkgoRecover()
if dir == quicproxy.DirectionIncoming {
_, err := clientConn.WriteTo(raw, serverConn.LocalAddr())
_, err := clientUDPConn.WriteTo(raw, serverUDPConn.LocalAddr())
Expect(err).ToNot(HaveOccurred())
}
return false
@ -205,7 +205,7 @@ var _ = Describe("MITM test", func() {
dropCb := func(dir quicproxy.Direction, raw []byte) bool {
defer GinkgoRecover()
if dir == quicproxy.DirectionOutgoing {
_, err := serverConn.WriteTo(raw, clientConn.LocalAddr())
_, err := serverUDPConn.WriteTo(raw, clientUDPConn.LocalAddr())
Expect(err).ToNot(HaveOccurred())
}
return false
@ -230,8 +230,8 @@ var _ = Describe("MITM test", func() {
fmt.Fprintf(GinkgoWriter, "Corrupted %d of %d packets.", num, atomic.LoadInt32(&numPackets))
Expect(num).To(BeNumerically(">=", 1))
// If the packet containing the CONNECTION_CLOSE is corrupted,
// we have to wait for the session to time out.
Eventually(serverSess.Context().Done(), 3*idleTimeout).Should(BeClosed())
// we have to wait for the connection to time out.
Eventually(serverConn.Context().Done(), 3*idleTimeout).Should(BeClosed())
})
It("downloads a message when packet are corrupted towards the server", func() {
@ -243,7 +243,7 @@ var _ = Describe("MITM test", func() {
if mrand.Intn(interval) == 0 {
pos := mrand.Intn(len(raw))
raw[pos] = byte(mrand.Intn(256))
_, err := clientConn.WriteTo(raw, serverConn.LocalAddr())
_, err := clientUDPConn.WriteTo(raw, serverUDPConn.LocalAddr())
Expect(err).ToNot(HaveOccurred())
atomic.AddInt32(&numCorrupted, 1)
return true
@ -263,7 +263,7 @@ var _ = Describe("MITM test", func() {
if mrand.Intn(interval) == 0 {
pos := mrand.Intn(len(raw))
raw[pos] = byte(mrand.Intn(256))
_, err := serverConn.WriteTo(raw, clientConn.LocalAddr())
_, err := serverUDPConn.WriteTo(raw, clientUDPConn.LocalAddr())
Expect(err).ToNot(HaveOccurred())
atomic.AddInt32(&numCorrupted, 1)
return true
@ -292,7 +292,7 @@ var _ = Describe("MITM test", func() {
})
// sendForgedVersionNegotiationPacket sends a fake VN packet with no supported versions
// from serverConn to client's remoteAddr
// from serverUDPConn to client's remoteAddr
// expects hdr from an Initial packet intercepted from client
sendForgedVersionNegotationPacket := func(conn net.PacketConn, remoteAddr net.Addr, hdr *wire.Header) {
// Create fake version negotiation packet with no supported versions
@ -305,7 +305,7 @@ var _ = Describe("MITM test", func() {
}
// sendForgedRetryPacket sends a fake Retry packet with a modified srcConnID
// from serverConn to client's remoteAddr
// from serverUDPConn to client's remoteAddr
// expects hdr from an Initial packet intercepted from client
sendForgedRetryPacket := func(conn net.PacketConn, remoteAddr net.Addr, hdr *wire.Header) {
var x byte = 0x12
@ -339,7 +339,7 @@ var _ = Describe("MITM test", func() {
raddr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("localhost:%d", proxy.LocalPort()))
Expect(err).ToNot(HaveOccurred())
_, err = quic.Dial(
clientConn,
clientUDPConn,
raddr,
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
@ -365,7 +365,7 @@ var _ = Describe("MITM test", func() {
return 0
}
sendForgedVersionNegotationPacket(serverConn, clientConn.LocalAddr(), hdr)
sendForgedVersionNegotationPacket(serverUDPConn, clientUDPConn.LocalAddr(), hdr)
}
return rtt / 2
}
@ -392,7 +392,7 @@ var _ = Describe("MITM test", func() {
}
initialPacketIntercepted = true
sendForgedRetryPacket(serverConn, clientConn.LocalAddr(), hdr)
sendForgedRetryPacket(serverUDPConn, clientUDPConn.LocalAddr(), hdr)
}
return rtt / 2
}
@ -416,7 +416,7 @@ var _ = Describe("MITM test", func() {
return 0
}
sendForgedInitialPacket(serverConn, clientConn.LocalAddr(), hdr)
sendForgedInitialPacket(serverUDPConn, clientUDPConn.LocalAddr(), hdr)
}
return rtt
}
@ -427,7 +427,7 @@ var _ = Describe("MITM test", func() {
// client connection closes immediately on receiving ack for unsent packet
It("fails when a forged initial packet with ack for unsent packet is sent to client", func() {
clientAddr := clientConn.LocalAddr()
clientAddr := clientUDPConn.LocalAddr()
delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration {
if dir == quicproxy.DirectionIncoming {
hdr, _, _, err := wire.ParsePacket(raw, connIDLen)
@ -435,7 +435,7 @@ var _ = Describe("MITM test", func() {
if hdr.Type != protocol.PacketTypeInitial {
return 0
}
sendForgedInitialPacketWithAck(serverConn, clientAddr, hdr)
sendForgedInitialPacketWithAck(serverUDPConn, clientAddr, hdr)
}
return rtt
}

View file

@ -8,7 +8,7 @@ import (
"runtime"
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go/internal/protocol"
. "github.com/onsi/ginkgo"
@ -24,13 +24,13 @@ var _ = Describe("Multiplexing", func() {
go func() {
defer GinkgoRecover()
for {
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
if err != nil {
return
}
go func() {
defer GinkgoRecover()
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
defer str.Close()
_, err = str.Write(PRData)
@ -40,17 +40,17 @@ var _ = Describe("Multiplexing", func() {
}()
}
dial := func(conn net.PacketConn, addr net.Addr) {
sess, err := quic.Dial(
conn,
dial := func(pconn net.PacketConn, addr net.Addr) {
conn, err := quic.Dial(
pconn,
addr,
fmt.Sprintf("localhost:%d", addr.(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
str, err := sess.AcceptStream(context.Background())
defer conn.CloseWithError(0, "")
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())

View file

@ -45,7 +45,7 @@ var _ = Describe("Packetization", func() {
defer proxy.Close()
clientTracer := newPacketTracer()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -57,9 +57,9 @@ var _ = Describe("Packetization", func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
b := make([]byte, 1)
// Echo every byte received from the client.
@ -72,7 +72,7 @@ var _ = Describe("Packetization", func() {
}
}()
str, err := sess.OpenStreamSync(context.Background())
str, err := conn.OpenStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
b := make([]byte, 1)
// Send numMsg 1-byte messages.
@ -83,7 +83,7 @@ var _ = Describe("Packetization", func() {
Expect(err).ToNot(HaveOccurred())
Expect(b[0]).To(Equal(uint8(i)))
}
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
countBundledPackets := func(packets []packet) (numBundled int) {
for _, p := range packets {

View file

@ -7,7 +7,7 @@ import (
"net"
"sync"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@ -57,7 +57,7 @@ var _ = Describe("TLS session resumption", func() {
cache := newClientSessionCache(gets, puts)
tlsConf := getTLSClientConfig()
tlsConf.ClientSessionCache = cache
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
tlsConf,
nil,
@ -65,24 +65,24 @@ var _ = Describe("TLS session resumption", func() {
Expect(err).ToNot(HaveOccurred())
var sessionKey string
Eventually(puts).Should(Receive(&sessionKey))
Expect(sess.ConnectionState().TLS.DidResume).To(BeFalse())
Expect(conn.ConnectionState().TLS.DidResume).To(BeFalse())
serverSess, err := server.Accept(context.Background())
serverConn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeFalse())
Expect(serverConn.ConnectionState().TLS.DidResume).To(BeFalse())
sess, err = quic.DialAddr(
conn, err = quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
tlsConf,
nil,
)
Expect(err).ToNot(HaveOccurred())
Expect(gets).To(Receive(Equal(sessionKey)))
Expect(sess.ConnectionState().TLS.DidResume).To(BeTrue())
Expect(conn.ConnectionState().TLS.DidResume).To(BeTrue())
serverSess, err = server.Accept(context.Background())
serverConn, err = server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeTrue())
Expect(serverConn.ConnectionState().TLS.DidResume).To(BeTrue())
})
It("doesn't use session resumption, if the config disables it", func() {
@ -97,29 +97,29 @@ var _ = Describe("TLS session resumption", func() {
cache := newClientSessionCache(gets, puts)
tlsConf := getTLSClientConfig()
tlsConf.ClientSessionCache = cache
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
tlsConf,
nil,
)
Expect(err).ToNot(HaveOccurred())
Consistently(puts).ShouldNot(Receive())
Expect(sess.ConnectionState().TLS.DidResume).To(BeFalse())
Expect(conn.ConnectionState().TLS.DidResume).To(BeFalse())
serverSess, err := server.Accept(context.Background())
serverConn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeFalse())
Expect(serverConn.ConnectionState().TLS.DidResume).To(BeFalse())
sess, err = quic.DialAddr(
conn, err = quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
tlsConf,
nil,
)
Expect(err).ToNot(HaveOccurred())
Expect(sess.ConnectionState().TLS.DidResume).To(BeFalse())
Expect(conn.ConnectionState().TLS.DidResume).To(BeFalse())
serverSess, err = server.Accept(context.Background())
serverConn, err = server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
Expect(serverSess.ConnectionState().TLS.DidResume).To(BeFalse())
Expect(serverConn.ConnectionState().TLS.DidResume).To(BeFalse())
})
})

View file

@ -7,7 +7,7 @@ import (
"net"
"time"
quic "github.com/lucas-clemente/quic-go"
"github.com/lucas-clemente/quic-go"
quicproxy "github.com/lucas-clemente/quic-go/integrationtests/tools/proxy"
"github.com/lucas-clemente/quic-go/internal/protocol"
@ -28,9 +28,9 @@ var _ = Describe("non-zero RTT", func() {
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
@ -40,18 +40,18 @@ var _ = Describe("non-zero RTT", func() {
}
downloadFile := func(port int) {
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRData))
sess.CloseWithError(0, "")
conn.CloseWithError(0, "")
}
Context(fmt.Sprintf("with QUIC version %s", version), func() {
@ -76,18 +76,18 @@ var _ = Describe("non-zero RTT", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(PRData))
sess.CloseWithError(0, "")
conn.CloseWithError(0, "")
})
}

View file

@ -35,9 +35,9 @@ var _ = Describe("Stateless Resets", func() {
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
@ -56,7 +56,7 @@ var _ = Describe("Stateless Resets", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -65,7 +65,7 @@ var _ = Describe("Stateless Resets", func() {
}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data := make([]byte, 6)
_, err = str.Read(data)

View file

@ -42,11 +42,11 @@ var _ = Describe("Bidirectional streams", func() {
server.Close()
})
runSendingPeer := func(sess quic.Connection) {
runSendingPeer := func(conn quic.Connection) {
var wg sync.WaitGroup
wg.Add(numStreams)
for i := 0; i < numStreams; i++ {
str, err := sess.OpenStreamSync(context.Background())
str, err := conn.OpenStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
data := GeneratePRData(25 * i)
go func() {
@ -66,11 +66,11 @@ var _ = Describe("Bidirectional streams", func() {
wg.Wait()
}
runReceivingPeer := func(sess quic.Connection) {
runReceivingPeer := func(conn quic.Connection) {
var wg sync.WaitGroup
wg.Add(numStreams)
for i := 0; i < numStreams; i++ {
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
@ -88,13 +88,13 @@ var _ = Describe("Bidirectional streams", func() {
}
It(fmt.Sprintf("client opening %d streams to a server", numStreams), func() {
var sess quic.Connection
var conn quic.Connection
go func() {
defer GinkgoRecover()
var err error
sess, err = server.Accept(context.Background())
conn, err = server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
runReceivingPeer(sess)
runReceivingPeer(conn)
}()
client, err := quic.DialAddr(
@ -109,10 +109,10 @@ var _ = Describe("Bidirectional streams", func() {
It(fmt.Sprintf("server opening %d streams to a client", numStreams), func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
runSendingPeer(sess)
sess.CloseWithError(0, "")
runSendingPeer(conn)
conn.CloseWithError(0, "")
}()
client, err := quic.DialAddr(
@ -129,15 +129,15 @@ var _ = Describe("Bidirectional streams", func() {
done1 := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
done := make(chan struct{})
go func() {
defer GinkgoRecover()
runReceivingPeer(sess)
runReceivingPeer(conn)
close(done)
}()
runSendingPeer(sess)
runSendingPeer(conn)
<-done
close(done1)
}()

View file

@ -125,9 +125,9 @@ var _ = Describe("Timeout tests", func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenStream()
str, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
@ -144,15 +144,15 @@ var _ = Describe("Timeout tests", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{DisablePathMTUDiscovery: true, MaxIdleTimeout: idleTimeout}),
)
Expect(err).ToNot(HaveOccurred())
strIn, err := sess.AcceptStream(context.Background())
strIn, err := conn.AcceptStream(context.Background())
Expect(err).ToNot(HaveOccurred())
strOut, err := sess.OpenStream()
strOut, err := conn.OpenStream()
Expect(err).ToNot(HaveOccurred())
_, err = strIn.Read(make([]byte, 6))
Expect(err).ToNot(HaveOccurred())
@ -167,13 +167,13 @@ var _ = Describe("Timeout tests", func() {
checkTimeoutError(err)
_, err = strOut.Read([]byte{0})
checkTimeoutError(err)
_, err = sess.OpenStream()
_, err = conn.OpenStream()
checkTimeoutError(err)
_, err = sess.OpenUniStream()
_, err = conn.OpenUniStream()
checkTimeoutError(err)
_, err = sess.AcceptStream(context.Background())
_, err = conn.AcceptStream(context.Background())
checkTimeoutError(err)
_, err = sess.AcceptUniStream(context.Background())
_, err = conn.AcceptUniStream(context.Background())
checkTimeoutError(err)
})
@ -193,17 +193,17 @@ var _ = Describe("Timeout tests", func() {
Expect(err).ToNot(HaveOccurred())
defer server.Close()
serverSessionClosed := make(chan struct{})
serverConnClosed := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
sess.AcceptStream(context.Background()) // blocks until the session is closed
close(serverSessionClosed)
conn.AcceptStream(context.Background()) // blocks until the connection is closed
close(serverConnClosed)
}()
tr := newPacketTracer()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", server.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -216,7 +216,7 @@ var _ = Describe("Timeout tests", func() {
done := make(chan struct{})
go func() {
defer GinkgoRecover()
_, err := sess.AcceptStream(context.Background())
_, err := conn.AcceptStream(context.Background())
checkTimeoutError(err)
close(done)
}()
@ -244,11 +244,11 @@ var _ = Describe("Timeout tests", func() {
BeNumerically(">=", idleTimeout),
BeNumerically("<", idleTimeout*6/5),
))
Consistently(serverSessionClosed).ShouldNot(BeClosed())
Consistently(serverConnClosed).ShouldNot(BeClosed())
// make the go routine return
Expect(server.Close()).To(Succeed())
Eventually(serverSessionClosed).Should(BeClosed())
Eventually(serverConnClosed).Should(BeClosed())
})
It("times out after sending a packet", func() {
@ -273,16 +273,16 @@ var _ = Describe("Timeout tests", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
serverSessionClosed := make(chan struct{})
serverConnClosed := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
<-sess.Context().Done() // block until the session is closed
close(serverSessionClosed)
<-conn.Context().Done() // block until the connection is closed
close(serverConnClosed)
}()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{MaxIdleTimeout: idleTimeout, DisablePathMTUDiscovery: true}),
@ -292,7 +292,7 @@ var _ = Describe("Timeout tests", func() {
// wait half the idle timeout, then send a packet
time.Sleep(idleTimeout / 2)
drop.Set(true)
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
@ -302,7 +302,7 @@ var _ = Describe("Timeout tests", func() {
done := make(chan struct{})
go func() {
defer GinkgoRecover()
_, err := sess.AcceptStream(context.Background())
_, err := conn.AcceptStream(context.Background())
checkTimeoutError(err)
close(done)
}()
@ -312,11 +312,11 @@ var _ = Describe("Timeout tests", func() {
BeNumerically(">=", idleTimeout),
BeNumerically("<", idleTimeout*12/10),
))
Consistently(serverSessionClosed).ShouldNot(BeClosed())
Consistently(serverConnClosed).ShouldNot(BeClosed())
// make the go routine return
Expect(server.Close()).To(Succeed())
Eventually(serverSessionClosed).Should(BeClosed())
Eventually(serverConnClosed).Should(BeClosed())
})
})
@ -331,13 +331,13 @@ var _ = Describe("Timeout tests", func() {
Expect(err).ToNot(HaveOccurred())
defer server.Close()
serverSessionClosed := make(chan struct{})
serverConnClosed := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
sess.AcceptStream(context.Background()) // blocks until the session is closed
close(serverSessionClosed)
conn.AcceptStream(context.Background()) // blocks until the connection is closed
close(serverConnClosed)
}()
drop := utils.AtomicBool{}
@ -350,7 +350,7 @@ var _ = Describe("Timeout tests", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -363,11 +363,11 @@ var _ = Describe("Timeout tests", func() {
// wait longer than the idle timeout
time.Sleep(3 * idleTimeout)
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
Consistently(serverSessionClosed).ShouldNot(BeClosed())
Consistently(serverConnClosed).ShouldNot(BeClosed())
// idle timeout will still kick in if pings are dropped
drop.Set(true)
@ -376,7 +376,7 @@ var _ = Describe("Timeout tests", func() {
checkTimeoutError(err)
Expect(server.Close()).To(Succeed())
Eventually(serverSessionClosed).Should(BeClosed())
Eventually(serverConnClosed).Should(BeClosed())
})
Context("faulty packet conns", func() {
@ -391,11 +391,11 @@ var _ = Describe("Timeout tests", func() {
})
runServer := func(ln quic.Listener) error {
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
if err != nil {
return err
}
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
if err != nil {
return err
}
@ -404,8 +404,8 @@ var _ = Describe("Timeout tests", func() {
return err
}
runClient := func(sess quic.Connection) error {
str, err := sess.AcceptUniStream(context.Background())
runClient := func(conn quic.Connection) error {
str, err := conn.AcceptUniStream(context.Background())
if err != nil {
return err
}
@ -414,7 +414,7 @@ var _ = Describe("Timeout tests", func() {
return err
}
Expect(data).To(Equal(PRData))
return sess.CloseWithError(0, "done")
return conn.CloseWithError(0, "done")
}
It("deals with an erroring packet conn, on the server side", func() {
@ -440,7 +440,7 @@ var _ = Describe("Timeout tests", func() {
clientErrChan := make(chan error, 1)
go func() {
defer GinkgoRecover()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
getQuicConfig(&quic.Config{
@ -453,7 +453,7 @@ var _ = Describe("Timeout tests", func() {
clientErrChan <- err
return
}
clientErrChan <- runClient(sess)
clientErrChan <- runClient(conn)
}()
var clientErr error
@ -501,7 +501,7 @@ var _ = Describe("Timeout tests", func() {
clientErrChan := make(chan error, 1)
go func() {
defer GinkgoRecover()
sess, err := quic.Dial(
conn, err := quic.Dial(
&faultyConn{PacketConn: conn, MaxPackets: maxPackets},
ln.Addr(),
"localhost",
@ -512,7 +512,7 @@ var _ = Describe("Timeout tests", func() {
clientErrChan <- err
return
}
clientErrChan <- runClient(sess)
clientErrChan <- runClient(conn)
}()
var clientErr error

View file

@ -115,9 +115,9 @@ var _ = Describe("Handshake tests", func() {
ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), quicServerConf)
Expect(err).ToNot(HaveOccurred())
serverChan <- ln
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
@ -127,14 +127,14 @@ var _ = Describe("Handshake tests", func() {
ln := <-serverChan
defer ln.Close()
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", ln.Addr().(*net.UDPAddr).Port),
getTLSClientConfig(),
quicClientConf,
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
str, err := sess.AcceptUniStream(context.Background())
defer conn.CloseWithError(0, "")
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())

View file

@ -39,9 +39,9 @@ var _ = Describe("Unidirectional Streams", func() {
return GeneratePRData(10 * int(id))
}
runSendingPeer := func(sess quic.Connection) {
runSendingPeer := func(conn quic.Connection) {
for i := 0; i < numStreams; i++ {
str, err := sess.OpenUniStreamSync(context.Background())
str, err := conn.OpenUniStreamSync(context.Background())
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
@ -52,11 +52,11 @@ var _ = Describe("Unidirectional Streams", func() {
}
}
runReceivingPeer := func(sess quic.Connection) {
runReceivingPeer := func(conn quic.Connection) {
var wg sync.WaitGroup
wg.Add(numStreams)
for i := 0; i < numStreams; i++ {
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
@ -72,10 +72,10 @@ var _ = Describe("Unidirectional Streams", func() {
It(fmt.Sprintf("client opening %d streams to a server", numStreams), func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
runReceivingPeer(sess)
sess.CloseWithError(0, "")
runReceivingPeer(conn)
conn.CloseWithError(0, "")
}()
client, err := quic.DialAddr(
@ -91,9 +91,9 @@ var _ = Describe("Unidirectional Streams", func() {
It(fmt.Sprintf("server opening %d streams to a client", numStreams), func() {
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
runSendingPeer(sess)
runSendingPeer(conn)
}()
client, err := quic.DialAddr(
@ -109,15 +109,15 @@ var _ = Describe("Unidirectional Streams", func() {
done1 := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := server.Accept(context.Background())
conn, err := server.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
done := make(chan struct{})
go func() {
defer GinkgoRecover()
runReceivingPeer(sess)
runReceivingPeer(conn)
close(done)
}()
runSendingPeer(sess)
runSendingPeer(conn)
<-done
close(done1)
}()

View file

@ -75,21 +75,21 @@ var _ = Describe("0-RTT", func() {
Expect(err).ToNot(HaveOccurred())
defer proxy.Close()
// dial the first session in order to receive a session ticket
// dial the first connection in order to receive a session ticket
done := make(chan struct{})
go func() {
defer GinkgoRecover()
defer close(done)
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
<-sess.Context().Done()
<-conn.Context().Done()
}()
clientConf := getTLSClientConfig()
gets := make(chan string, 100)
puts := make(chan string, 100)
clientConf.ClientSessionCache = newClientSessionCache(gets, puts)
sess, err := quic.DialAddr(
conn, err := quic.DialAddr(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
clientConf,
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
@ -97,7 +97,7 @@ var _ = Describe("0-RTT", func() {
Expect(err).ToNot(HaveOccurred())
Eventually(puts).Should(Receive())
// received the session ticket. We're done here.
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
Eventually(done).Should(BeClosed())
return tlsConf, clientConf
}
@ -109,40 +109,40 @@ var _ = Describe("0-RTT", func() {
clientConf *quic.Config,
testdata []byte, // data to transfer
) {
// now dial the second session, and use 0-RTT to send some data
// now dial the second connection, and use 0-RTT to send some data
done := make(chan struct{})
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(testdata))
Expect(sess.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(conn.CloseWithError(0, "")).To(Succeed())
close(done)
}()
if clientConf == nil {
clientConf = getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}})
}
sess, err := quic.DialAddrEarly(
conn, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxyPort),
clientTLSConf,
clientConf,
)
Expect(err).ToNot(HaveOccurred())
defer sess.CloseWithError(0, "")
str, err := sess.OpenUniStream()
defer conn.CloseWithError(0, "")
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(testdata)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
Expect(sess.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(conn.ConnectionState().TLS.Used0RTT).To(BeTrue())
Eventually(done).Should(BeClosed())
Eventually(sess.Context().Done()).Should(BeClosed())
Eventually(conn.Context().Done()).Should(BeClosed())
}
check0RTTRejected := func(
@ -150,29 +150,29 @@ var _ = Describe("0-RTT", func() {
proxyPort int,
clientConf *tls.Config,
) {
sess, err := quic.DialAddrEarly(
conn, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxyPort),
clientConf,
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(make([]byte, 3000))
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
Expect(sess.ConnectionState().TLS.Used0RTT).To(BeFalse())
Expect(conn.ConnectionState().TLS.Used0RTT).To(BeFalse())
// make sure the server doesn't process the data
ctx, cancel := context.WithTimeout(context.Background(), scaleDuration(50*time.Millisecond))
defer cancel()
serverSess, err := ln.Accept(ctx)
serverConn, err := ln.Accept(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(serverSess.ConnectionState().TLS.Used0RTT).To(BeFalse())
_, err = serverSess.AcceptUniStream(ctx)
Expect(serverConn.ConnectionState().TLS.Used0RTT).To(BeFalse())
_, err = serverConn.AcceptUniStream(ctx)
Expect(err).To(Equal(context.DeadlineExceeded))
Expect(serverSess.CloseWithError(0, "")).To(Succeed())
Eventually(sess.Context().Done()).Should(BeClosed())
Expect(serverConn.CloseWithError(0, "")).To(Succeed())
Eventually(conn.Context().Done()).Should(BeClosed())
}
// can be used to extract 0-RTT from a packetTracer
@ -244,7 +244,7 @@ var _ = Describe("0-RTT", func() {
}
// 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 for a connection until the handshake is done", func() {
tlsConf, clientConf := dialAndReceiveSessionTicket(nil)
zeroRTTData := GeneratePRData(2 * 1100) // 2 packets
@ -263,28 +263,28 @@ var _ = Describe("0-RTT", func() {
Expect(err).ToNot(HaveOccurred())
defer ln.Close()
// now dial the second session, and use 0-RTT to send some data
// now dial the second connection, and use 0-RTT to send some data
go func() {
defer GinkgoRecover()
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
str, err := sess.AcceptUniStream(context.Background())
str, err := conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(zeroRTTData))
str, err = sess.AcceptUniStream(context.Background())
str, err = conn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err = io.ReadAll(str)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(oneRTTData))
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
}()
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
defer proxy.Close()
sess, err := quic.DialAddrEarly(
conn, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
clientConf,
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
@ -294,7 +294,7 @@ var _ = Describe("0-RTT", func() {
go func() {
defer GinkgoRecover()
defer close(sent0RTT)
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(zeroRTTData)
Expect(err).ToNot(HaveOccurred())
@ -303,13 +303,13 @@ var _ = Describe("0-RTT", func() {
Eventually(sent0RTT).Should(BeClosed())
// wait for the handshake to complete
Eventually(sess.HandshakeComplete().Done()).Should(BeClosed())
str, err := sess.OpenUniStream()
Eventually(conn.HandshakeComplete().Done()).Should(BeClosed())
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write(PRData)
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
<-sess.Context().Done()
<-conn.Context().Done()
num0RTT := atomic.LoadUint32(num0RTTPackets)
fmt.Fprintf(GinkgoWriter, "Sent %d 0-RTT packets.", num0RTT)
@ -472,27 +472,27 @@ var _ = Describe("0-RTT", func() {
proxy, _ := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
defer proxy.Close()
sess, err := quic.DialAddrEarly(
conn, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
clientConf,
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = str.Write([]byte("foobar"))
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
// The client remembers the old limit and refuses to open a new stream.
_, err = sess.OpenUniStream()
_, err = conn.OpenUniStream()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("too many open streams"))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err = sess.OpenUniStreamSync(ctx)
_, err = conn.OpenUniStreamSync(ctx)
Expect(err).ToNot(HaveOccurred())
Expect(sess.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(conn.CloseWithError(0, "")).To(Succeed())
})
It("rejects 0-RTT when the server's stream limit decreased", func() {
@ -582,13 +582,13 @@ var _ = Describe("0-RTT", func() {
proxy, _ := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
defer proxy.Close()
sess, err := quic.DialAddrEarly(
conn, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
clientConf,
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
str, err := sess.OpenUniStream()
str, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
written := make(chan struct{})
go func() {
@ -601,16 +601,16 @@ var _ = Describe("0-RTT", func() {
Eventually(written).Should(BeClosed())
serverSess, err := ln.Accept(context.Background())
serverConn, err := ln.Accept(context.Background())
Expect(err).ToNot(HaveOccurred())
rstr, err := serverSess.AcceptUniStream(context.Background())
rstr, err := serverConn.AcceptUniStream(context.Background())
Expect(err).ToNot(HaveOccurred())
data, err := io.ReadAll(rstr)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal([]byte("foobar")))
Expect(serverSess.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(serverSess.CloseWithError(0, "")).To(Succeed())
Eventually(sess.Context().Done()).Should(BeClosed())
Expect(serverConn.ConnectionState().TLS.Used0RTT).To(BeTrue())
Expect(serverConn.CloseWithError(0, "")).To(Succeed())
Eventually(conn.Context().Done()).Should(BeClosed())
var processedFirst bool
for _, p := range tracer.getRcvdPackets() {
@ -656,14 +656,14 @@ var _ = Describe("0-RTT", func() {
proxy, num0RTTPackets := runCountingProxy(ln.Addr().(*net.UDPAddr).Port)
defer proxy.Close()
sess, err := quic.DialAddrEarly(
conn, err := quic.DialAddrEarly(
fmt.Sprintf("localhost:%d", proxy.LocalPort()),
clientConf,
getQuicConfig(&quic.Config{Versions: []protocol.VersionNumber{version}}),
)
Expect(err).ToNot(HaveOccurred())
// The client remembers that it was allowed to open 2 uni-directional streams.
firstStr, err := sess.OpenUniStream()
firstStr, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
written := make(chan struct{}, 2)
go func() {
@ -672,7 +672,7 @@ var _ = Describe("0-RTT", func() {
_, err := firstStr.Write([]byte("first flight"))
Expect(err).ToNot(HaveOccurred())
}()
secondStr, err := sess.OpenUniStream()
secondStr, err := conn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
go func() {
defer GinkgoRecover()
@ -683,28 +683,28 @@ var _ = Describe("0-RTT", func() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err = sess.AcceptStream(ctx)
_, err = conn.AcceptStream(ctx)
Expect(err).To(MatchError(quic.Err0RTTRejected))
Eventually(written).Should(Receive())
Eventually(written).Should(Receive())
_, err = firstStr.Write([]byte("foobar"))
Expect(err).To(MatchError(quic.Err0RTTRejected))
_, err = sess.OpenUniStream()
_, err = conn.OpenUniStream()
Expect(err).To(MatchError(quic.Err0RTTRejected))
_, err = sess.AcceptStream(ctx)
_, err = conn.AcceptStream(ctx)
Expect(err).To(Equal(quic.Err0RTTRejected))
newSess := sess.NextSession()
str, err := newSess.OpenUniStream()
newConn := conn.NextSession()
str, err := newConn.OpenUniStream()
Expect(err).ToNot(HaveOccurred())
_, err = newSess.OpenUniStream()
_, err = newConn.OpenUniStream()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("too many open streams"))
_, err = str.Write([]byte("second flight"))
Expect(err).ToNot(HaveOccurred())
Expect(str.Close()).To(Succeed())
Expect(sess.CloseWithError(0, "")).To(Succeed())
Expect(conn.CloseWithError(0, "")).To(Succeed())
// The client should send 0-RTT packets, but the server doesn't process them.
num0RTT := atomic.LoadUint32(num0RTTPackets)

View file

@ -84,25 +84,25 @@ type client struct {
quicConf *quic.Config
once sync.Once
sess quic.EarlySession
conn quic.EarlySession
dialErr error
}
func (c *client) RoundTrip(req *http.Request) (*http.Response, error) {
c.once.Do(func() {
c.sess, c.dialErr = quic.DialAddrEarly(c.hostname, c.tlsConf, c.quicConf)
c.conn, c.dialErr = quic.DialAddrEarly(c.hostname, c.tlsConf, c.quicConf)
})
if c.dialErr != nil {
return nil, c.dialErr
}
if req.Method != MethodGet0RTT {
<-c.sess.HandshakeComplete().Done()
<-c.conn.HandshakeComplete().Done()
}
return c.doRequest(req)
}
func (c *client) doRequest(req *http.Request) (*http.Response, error) {
str, err := c.sess.OpenStreamSync(context.Background())
str, err := c.conn.OpenStreamSync(context.Background())
if err != nil {
return nil, err
}
@ -124,10 +124,10 @@ func (c *client) doRequest(req *http.Request) (*http.Response, error) {
}
func (c *client) Close() error {
if c.sess == nil {
if c.conn == nil {
return nil
}
return c.sess.CloseWithError(0, "")
return c.conn.CloseWithError(0, "")
}
func hostnameFromRequest(req *http.Request) string {

View file

@ -78,17 +78,17 @@ func (s *Server) ListenAndServe() error {
s.mutex.Unlock()
for {
sess, err := ln.Accept(context.Background())
conn, err := ln.Accept(context.Background())
if err != nil {
return err
}
go s.handleConn(sess)
go s.handleConn(conn)
}
}
func (s *Server) handleConn(sess quic.Connection) {
func (s *Server) handleConn(conn quic.Connection) {
for {
str, err := sess.AcceptStream(context.Background())
str, err := conn.AcceptStream(context.Background())
if err != nil {
log.Printf("Error accepting stream: %s\n", err.Error())
return