{2 bytes Node ID} {4 bytes for random} {2 bytes zero}
(id uint64)
| 657 | |
| 658 | // {2 bytes Node ID} {4 bytes for random} {2 bytes zero} |
| 659 | func ProposalKey(id uint64) (uint64, error) { |
| 660 | random4Bytes := make([]byte, 4) |
| 661 | if _, err := cryptorand.Read(random4Bytes); err != nil { |
| 662 | return 0, err |
| 663 | } |
| 664 | proposalKey := id<<48 | uint64(binary.BigEndian.Uint32(random4Bytes))<<16 |
| 665 | // We want to avoid spillage to node id in case of overflow. For instance, if the |
| 666 | // random bytes end up being [xx,xx, 255, 255, 255, 255, 0 , 0] (xx, xx being the node id) |
| 667 | // we would spill to node id after 65535 calls to unique key. |
| 668 | // So by setting 48th bit to 0 we ensure that we never spill out to node ids. |
| 669 | proposalKey &= ^(uint64(1) << 47) |
| 670 | return proposalKey, nil |
| 671 | } |
| 672 | |
| 673 | // HasString returns whether the slice contains the given string. |
| 674 | func HasString(a []string, b string) bool { |
no test coverage detected