From 041c47afb6285a2513cbf1398dbc38b4dc19ae9a Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Wed, 15 May 2024 02:34:30 +0000 Subject: [PATCH] make Receive usage stricter, and document --- mixing/mixpool/mixpool.go | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/mixing/mixpool/mixpool.go b/mixing/mixpool/mixpool.go index 80b7b8b6f..5d82a9dc5 100644 --- a/mixing/mixpool/mixpool.go +++ b/mixing/mixpool/mixpool.go @@ -651,8 +651,9 @@ PRLoop: } // Received is a parameter for Pool.Receive describing the session and run to -// receive messages for, and slices for returning results. Only non-nil slices -// will be appended to. Received messages are unsorted. +// receive messages for, and slices for returning results. A single non-nil +// slices is required and indicates which message slice will be will be +// appended to. Received messages are unsorted. type Received struct { Sid [32]byte Run uint32 @@ -696,6 +697,32 @@ func (p *Pool) Receive(ctx context.Context, expectedMessages int, r *Received) e } rs = &ses.runs[run] + nonNilSlices := 0 + if r.KEs != nil { + nonNilSlices++ + } + if r.CTs != nil { + nonNilSlices++ + } + if r.SRs != nil { + nonNilSlices++ + } + if r.DCs != nil { + nonNilSlices++ + } + if r.CMs != nil { + nonNilSlices++ + } + if r.FPs != nil { + nonNilSlices++ + } + if r.RSs != nil { + nonNilSlices++ + } + if nonNilSlices != 1 { + return fmt.Errorf("mixpool: exactly one Received slice must be non-nil") + } + Loop: for { // Pool is locked for reads. Count if the total number of