-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// We can't reliably set the DF bit on macOS, so we can't do Path MTU discovery. | ||
//go:build !darwin | ||
|
||
package self_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net" | ||
"sync" | ||
"time" | ||
|
||
"github.com/quic-go/quic-go" | ||
quicproxy "github.com/quic-go/quic-go/integrationtests/tools/proxy" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("DPLPMTUD", func() { | ||
It("discovers the MTU", func() { | ||
const rtt = 100 * time.Millisecond | ||
const mtu = 1400 | ||
|
||
ln, err := quic.ListenAddr("localhost:0", getTLSConfig(), getQuicConfig(&quic.Config{DisablePathMTUDiscovery: true})) | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer ln.Close() | ||
go func() { | ||
defer GinkgoRecover() | ||
conn, err := ln.Accept(context.Background()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
str, err := conn.AcceptStream(context.Background()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
_, err = io.Copy(str, str) | ||
Expect(err).ToNot(HaveOccurred()) | ||
str.Close() | ||
}() | ||
|
||
var mx sync.Mutex | ||
var maxPacketSizeClient, maxPacketSizeServer int | ||
serverPort := ln.Addr().(*net.UDPAddr).Port | ||
proxy, err := quicproxy.NewQuicProxy("localhost:0", &quicproxy.Opts{ | ||
RemoteAddr: fmt.Sprintf("localhost:%d", serverPort), | ||
DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, | ||
DropPacket: func(dir quicproxy.Direction, packet []byte) bool { | ||
if len(packet) > mtu { | ||
return true | ||
} | ||
mx.Lock() | ||
defer mx.Unlock() | ||
switch dir { | ||
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.21.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
Check failure on line 52 in integrationtests/self/dplpmtud_test.go GitHub Actions / golangci-lint (Go 1.22.x)
|
||
case quicproxy.DirectionIncoming: | ||
if len(packet) > maxPacketSizeClient { | ||
maxPacketSizeClient = len(packet) | ||
} | ||
case quicproxy.DirectionOutgoing: | ||
if len(packet) > maxPacketSizeServer { | ||
maxPacketSizeServer = len(packet) | ||
} | ||
} | ||
return false | ||
}, | ||
}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer proxy.Close() | ||
|
||
conn, err := quic.DialAddr( | ||
context.Background(), | ||
fmt.Sprintf("localhost:%d", proxy.LocalPort()), | ||
getTLSClientConfig(), | ||
getQuicConfig(nil), | ||
) | ||
Expect(err).ToNot(HaveOccurred()) | ||
defer conn.CloseWithError(0, "") | ||
str, err := conn.OpenStream() | ||
Expect(err).ToNot(HaveOccurred()) | ||
done := make(chan struct{}) | ||
go func() { | ||
defer close(done) | ||
defer GinkgoRecover() | ||
data, err := io.ReadAll(str) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(data).To(Equal(PRDataLong)) | ||
}() | ||
_, err = str.Write(PRDataLong) | ||
Expect(err).ToNot(HaveOccurred()) | ||
str.Close() | ||
Eventually(done).Should(BeClosed()) | ||
|
||
mx.Lock() | ||
defer mx.Unlock() | ||
fmt.Fprintf(GinkgoWriter, "max client packet size: %d, MTU: %d\n", maxPacketSizeClient, mtu) | ||
fmt.Fprintf(GinkgoWriter, "max server packet size: %d, MTU: %d\n", maxPacketSizeServer, mtu) | ||
Expect(maxPacketSizeClient).To(BeNumerically(">=", mtu-25)) | ||
}) | ||
}) |