Update error log for wrong node id.

When custom NodeBits was set, the node number may bigger than 1023.
This commit is contained in:
龚尚 2018-04-07 14:46:40 +08:00 committed by GitHub
parent f613937295
commit 4ca43961f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,10 +89,6 @@ type ID int64
// IDs
func NewNode(node int64) (*Node, error) {
if node < 0 || node > nodeMax {
return nil, errors.New("Node number must be between 0 and 1023")
}
// re-calc in case custom NodeBits or StepBits were set
nodeMax = -1 ^ (-1 << NodeBits)
nodeMask = nodeMax << StepBits
@ -100,6 +96,10 @@ func NewNode(node int64) (*Node, error) {
timeShift = NodeBits + StepBits
nodeShift = StepBits
if node < 0 || node > nodeMax {
return nil, errors.New("Node number must be between 0 and " + strconv.Itoa(nodeMax))
}
return &Node{
time: 0,
node: node,