From acc2cdd96cd253f3741ba0e5c90753ebd691c03b Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Fri, 9 Jul 2021 17:06:35 +0300 Subject: [PATCH] [#125] Added exact eacl checking Signed-off-by: Denis Kirillov --- api/layer/container.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/api/layer/container.go b/api/layer/container.go index 36ef2de4..ce302327 100644 --- a/api/layer/container.go +++ b/api/layer/container.go @@ -1,6 +1,7 @@ package layer import ( + "bytes" "context" "crypto/ecdsa" "fmt" @@ -165,7 +166,7 @@ func (n *layer) setContainerEACL(ctx context.Context, cid *cid.ID, gateKey *keys return err } - if err := n.waitEACLPresence(ctx, cid, defaultWaitParams()); err != nil { + if err := n.waitEACLPresence(ctx, cid, table, defaultWaitParams()); err != nil { 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) defer cancel() ticker := time.NewTimer(params.PollInterval) @@ -219,8 +225,12 @@ func (n *layer) waitEACLPresence(ctx context.Context, cid *cid.ID, params *waitP case <-wdone: return wctx.Err() case <-ticker.C: - if _, err := n.pool.GetEACL(ctx, cid); err == nil { - return 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 + } } ticker.Reset(params.PollInterval) }