Skip to content

Commit

Permalink
Merge branch 'master' into fix-checksum-check
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniels authored Feb 26, 2024
2 parents b42ee14 + ee5f2e7 commit d5f1a88
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -2238,14 +2238,15 @@ func (a *Association) bundleDataChunksIntoPackets(chunks []*chunkPayloadData) []
// single packet. Furthermore, DATA chunks being retransmitted MAY be
// bundled with new DATA chunks, as long as the resulting packet size
// does not exceed the path MTU.
if bytesInPacket+len(c.userData) > int(a.MTU()) {
chunkSizeInPacket := int(dataChunkHeaderSize) + len(c.userData)
chunkSizeInPacket += getPadding(chunkSizeInPacket)
if bytesInPacket+chunkSizeInPacket > int(a.MTU()) {
packets = append(packets, a.createPacket(chunksToSend))
chunksToSend = []chunk{}
bytesInPacket = int(commonHeaderSize)
}

chunksToSend = append(chunksToSend, c)
bytesInPacket += int(dataChunkHeaderSize) + len(c.userData)
bytesInPacket += chunkSizeInPacket
}

if len(chunksToSend) > 0 {
Expand Down
16 changes: 16 additions & 0 deletions association_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3156,3 +3156,19 @@ func TestAssociation_ZeroChecksum(t *testing.T) {
require.NoError(t, a2.Close())
}
}

func TestDataChunkBundlingIntoPacket(t *testing.T) {
a := &Association{mtu: initialMTU}
chunks := make([]*chunkPayloadData, 300)
for i := 0; i < 300; i++ {
chunks[i] = &chunkPayloadData{userData: []byte{1}}
}
packets := a.bundleDataChunksIntoPackets(chunks)
for _, p := range packets {
raw, err := p.marshal(false)
require.NoError(t, err)
if len(raw) > int(initialMTU) {
t.Error("packet too long: ", len(raw))
}
}
}

0 comments on commit d5f1a88

Please sign in to comment.