Commit bc2cddfc authored by Kirill Smelkov's avatar Kirill Smelkov

X go/neo: Switch to NEO-kind SHA1

NEO/py sends all zeros for empty data. Without this fix tests fail:

    --- FAIL: TestLoad/py (0.74s)
        xtesting.go:297: load 0285cbacc06d3a4c:0000000000000007: returned err unexpected:
            have: neo://1@127.0.0.1:25910: load 0285cbacc06d3a4c:0000000000000007: data corrupt: checksum mismatch
            want: neo://1@127.0.0.1:25910: load 0285cbacc06d3a4c:0000000000000007: 0000000000000007: object was deleted @0285cbacc06d3a4c
        xtesting.go:297: load 0285cbad858bf2e6:0000000000000006: returned err unexpected:
            have: neo://1@127.0.0.1:25910: load 0285cbad858bf2e6:0000000000000006: data corrupt: checksum mismatch
            want: neo://1@127.0.0.1:25910: load 0285cbad858bf2e6:0000000000000006: 0000000000000006: object was deleted @0285cbad858bf2e6
        xtesting.go:315: load 7fffffffffffffff:0000000000000006: returned err unexpected:
            have: neo://1@127.0.0.1:25910: load 7fffffffffffffff:0000000000000006: data corrupt: checksum mismatch
            want: neo://1@127.0.0.1:25910: load 7fffffffffffffff:0000000000000006: 0000000000000006: object was deleted @0285cbad858bf2e6
        xtesting.go:315: load 7fffffffffffffff:0000000000000007: returned err unexpected:
            have: neo://1@127.0.0.1:25910: load 7fffffffffffffff:0000000000000007: data corrupt: checksum mismatch
            want: neo://1@127.0.0.1:25910: load 7fffffffffffffff:0000000000000007: 0000000000000007: object was deleted @0285cbacc06d3a4c
parent a2088ea6
......@@ -463,7 +463,7 @@ func (c *Client) Load(ctx context.Context, xid zodb.Xid) (buf *mem.Buf, serial z
buf = resp.Data
if !xsha1.Skip {
checksum := xsha1.Sum(buf.Data)
checksum := xsha1.NEOSum(buf.Data)
if checksum != resp.Checksum {
return nil, 0, fmt.Errorf("data corrupt: checksum mismatch")
}
......
// Copyright (C) 2017-2018 Nexedi SA and Contributors.
// Copyright (C) 2017-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -43,3 +43,14 @@ func Sum(b []byte) [sha1.Size]byte {
return [sha1.Size]byte{} // all 0
}
// NEOSum returns SHA1(b) computed by NEO rules.
//
// it is the same as regular SHA1, but returns all-zeros for empty b.
// https://lab.nexedi.com/nexedi/neoppod/blob/c1c26894/neo/client/app.py#L464-468
func NEOSum(b []byte) [sha1.Size]byte {
if len(b) == 0 {
return [sha1.Size]byte{} // all 0
}
return Sum(b)
}
// Copyright (C) 2016-2018 Nexedi SA and Contributors.
// Copyright (C) 2016-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
......@@ -85,7 +85,7 @@ func (f *Backend) Load(ctx context.Context, xid zodb.Xid) (*proto.AnswerObject,
Compression: false,
Data: buf,
Checksum: xsha1.Sum(buf.Data), // XXX computing every time
Checksum: xsha1.NEOSum(buf.Data), // XXX computing every time
// XXX .DataSerial
}, nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment