Reduce VPN control packet latency

This commit is contained in:
2026-05-15 18:19:55 +03:00
parent ceda460d09
commit 52dfce316d
7 changed files with 194 additions and 15 deletions
@@ -76,6 +76,46 @@ func TestGatewayUploadPrioritizesTCPControlPackets(t *testing.T) {
}
}
func TestGatewayUploadMicroBatchesTCPControlPackets(t *testing.T) {
transport := &recordingGatewayTransport{}
gateway := &Gateway{Transport: transport, VPNConnectionID: "vpn-1"}
priorityPackets := make(chan []byte, 2)
packets := make(chan []byte, 1)
first := testIPv4TCPPacket([4]byte{192, 168, 200, 95}, [4]byte{10, 77, 0, 2}, 3389, 51000)
first[33] = 0x12
second := testIPv4TCPPacket([4]byte{188, 40, 167, 82}, [4]byte{10, 77, 0, 2}, 80, 51002)
second[33] = 0x12
priorityPackets <- first
priorityPackets <- second
ctx, cancel := context.WithCancel(context.Background())
done := make(chan error, 1)
go func() {
done <- gateway.uploadGatewayPackets(ctx, priorityPackets, packets)
}()
defer func() {
cancel()
<-done
}()
deadline := time.After(time.Second)
for {
if batch := transport.firstBatch(); len(batch) == 2 {
if string(batch[0]) != string(first) || string(batch[1]) != string(second) {
t.Fatalf("priority batch = %#v, want both control packets in order", batch)
}
return
}
select {
case <-deadline:
t.Fatal("timed out waiting for priority microbatch")
default:
time.Sleep(time.Millisecond)
}
}
}
func TestIsTCPControlPacket(t *testing.T) {
packet := testIPv4TCPPacket([4]byte{192, 168, 200, 95}, [4]byte{10, 77, 0, 2}, 3389, 51000)
if isTCPControlPacket(packet) {