Split VPN fabric batches by stream

This commit is contained in:
2026-05-16 12:33:27 +03:00
parent bbd9f8c257
commit bd70ca6342
3 changed files with 83 additions and 15 deletions
@@ -67,22 +67,24 @@ func (t *FabricSessionPacketTransport) SendGatewayPacketBatch(ctx context.Contex
if direction == "" {
direction = FabricDirectionGatewayToClient
}
streamID, trafficClass := t.selectStreamForPackets(packets)
frame, err := NewFabricVPNPacketDataFrame(FabricVPNPacketFrameInput{
StreamID: streamID,
Sequence: t.nextSequence(streamID),
VPNConnectionID: t.VPNConnectionID,
Direction: direction,
TrafficClass: trafficClass,
Packets: packets,
})
if err != nil {
return err
groups := t.groupPacketsByStream(packets)
for _, group := range groups {
frame, err := NewFabricVPNPacketDataFrame(FabricVPNPacketFrameInput{
StreamID: group.StreamID,
Sequence: t.nextSequence(group.StreamID),
VPNConnectionID: t.VPNConnectionID,
Direction: direction,
TrafficClass: group.TrafficClass,
Packets: group.Packets,
})
if err != nil {
return err
}
if err := t.Sender.Send(ctx, frame); err != nil {
return err
}
t.recordSend(group.StreamID, group.TrafficClass, len(group.Packets))
}
if err := t.Sender.Send(ctx, frame); err != nil {
return err
}
t.recordSend(streamID, trafficClass, len(packets))
return nil
}
@@ -227,6 +229,32 @@ func (t *FabricSessionPacketTransport) selectStreamForPackets(packets [][]byte)
return t.StreamID, trafficClass
}
type fabricSessionPacketGroup struct {
StreamID uint64
TrafficClass string
Packets [][]byte
}
func (t *FabricSessionPacketTransport) groupPacketsByStream(packets [][]byte) []fabricSessionPacketGroup {
groups := []fabricSessionPacketGroup{}
indexByKey := map[string]int{}
for _, packet := range packets {
streamID, trafficClass := t.selectStreamForPackets([][]byte{packet})
key := fmt.Sprintf("%d\x00%s", streamID, trafficClass)
index, ok := indexByKey[key]
if !ok {
index = len(groups)
indexByKey[key] = index
groups = append(groups, fabricSessionPacketGroup{
StreamID: streamID,
TrafficClass: trafficClass,
})
}
groups[index].Packets = append(groups[index].Packets, packet)
}
return groups
}
func (t *FabricSessionPacketTransport) allStreamIDs() []uint64 {
if t == nil {
return nil