[#125] Added exact eacl checking

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2021-07-09 17:06:35 +03:00
parent e78543adf3
commit acc2cdd96c

View file

@ -1,6 +1,7 @@
package layer package layer
import ( import (
"bytes"
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
@ -165,7 +166,7 @@ func (n *layer) setContainerEACL(ctx context.Context, cid *cid.ID, gateKey *keys
return err return err
} }
if err := n.waitEACLPresence(ctx, cid, defaultWaitParams()); err != nil { if err := n.waitEACLPresence(ctx, cid, table, defaultWaitParams()); err != nil {
return err return err
} }
@ -205,7 +206,12 @@ func defaultWaitParams() *waitParams {
} }
} }
func (n *layer) waitEACLPresence(ctx context.Context, cid *cid.ID, params *waitParams) error { func (n *layer) waitEACLPresence(ctx context.Context, cid *cid.ID, table *eacl.Table, params *waitParams) error {
exp, err := table.Marshal()
if err != nil {
return fmt.Errorf("couldn't marshal eacl: %w", err)
}
wctx, cancel := context.WithTimeout(ctx, params.WaitTimeout) wctx, cancel := context.WithTimeout(ctx, params.WaitTimeout)
defer cancel() defer cancel()
ticker := time.NewTimer(params.PollInterval) ticker := time.NewTimer(params.PollInterval)
@ -219,9 +225,13 @@ func (n *layer) waitEACLPresence(ctx context.Context, cid *cid.ID, params *waitP
case <-wdone: case <-wdone:
return wctx.Err() return wctx.Err()
case <-ticker.C: case <-ticker.C:
if _, err := n.pool.GetEACL(ctx, cid); err == nil { signedEacl, err := n.pool.GetEACL(ctx, cid)
if err == nil {
got, err := signedEacl.EACL().Marshal()
if err == nil && bytes.Equal(exp, got) {
return nil return nil
} }
}
ticker.Reset(params.PollInterval) ticker.Reset(params.PollInterval)
} }
} }