Decode a fragmented handshake message straight into its packet, behind room for the Nebula header, instead of copying it there

This commit is contained in:
JackDoan committed 2026-10-15 10:42:39 -05:00
1 parent 4b295e086e
commit cbcf441d7c
8 files changed
+49 -30

No files matched your search

+4 -3
View File
@@ -50,9 +50,10 @@ func (a *Assembly) wouldStore(h Header, sym []byte) int {
return len(sym)
}
// Decode reconstructs the message. It requires Add to have reported ready.
func (a *Assembly) Decode() ([]byte, error) {
return a.dec.Decode()
// Decode reconstructs the message and appends it to dst, see fec.Decoder.Decode.
// It requires Add to have reported ready.
func (a *Assembly) Decode(dst []byte) ([]byte, error) {
return a.dec.Decode(dst)
}
// Stored returns the number of symbol bytes held.
+2
View File
@@ -241,6 +241,8 @@ func TestLossy(t *testing.T) {
// duplicate can complete one again; the handshake layer
// recognises the repeat.
require.True(t, bytes.Equal(msg, res.Msg))
require.Len(t, res.Packet, header.Len+len(msg))
require.Equal(t, &res.Packet[header.Len], &res.Msg[0], "Msg follows room for a header")
got = res
}
checkInvariants(t, tb)
+4 -1
View File
@@ -91,6 +91,7 @@ func NewTable[K, S comparable](cfg TableConfig) *Table[K, S] {
// Result describes a completed message.
type Result struct {
Msg []byte // the decoded message, nil for a repeat
Packet []byte // header.Len bytes for the caller's Nebula header, then Msg
Hash [sha256.Size]byte // sha256 of the message
Received int // packet bytes received for it, for the amplification budget
@@ -159,12 +160,14 @@ func (t *Table[K, S]) Add(key K, source S, now time.Time, h Header, sym []byte)
t.remove(key, e)
t.mu.Unlock()
msg, err := e.a.Decode()
pkt, err := e.a.Decode(make([]byte, header.Len))
if err != nil {
return nil, err
}
msg := pkt[header.Len:]
return &Result{
Msg: msg,
Packet: pkt,
Hash: sha256.Sum256(msg),
Received: e.a.Received(),
msgLen: e.a.msgLen,