-
Notifications
You must be signed in to change notification settings - Fork 402
/
node.go
59 lines (51 loc) · 1.4 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package teststorj
import (
"storj.io/common/pb"
"storj.io/common/storj"
)
// NodeIDFromBytes returns a node ID consisting of the bytes
// and padding to the node ID length
func NodeIDFromBytes(b []byte) storj.NodeID {
id, _ := storj.NodeIDFromBytes(fit(b))
return id
}
// NodeIDFromString returns node ID consisting of the strings
// and padding to the node ID length
func NodeIDFromString(s string) storj.NodeID {
return NodeIDFromBytes([]byte(s))
}
// NodeIDsFromBytes returns node IDs consisting of the byte slices
// and padding to the node ID length
func NodeIDsFromBytes(bs ...[]byte) (ids storj.NodeIDList) {
for _, b := range bs {
ids = append(ids, NodeIDFromBytes(b))
}
return ids
}
// NodeIDsFromStrings returns node IDs consisting of the strings
// and padding to the node ID length
func NodeIDsFromStrings(strs ...string) (ids storj.NodeIDList) {
for _, s := range strs {
ids = append(ids, NodeIDFromString(s))
}
return ids
}
// used to pad node IDs
func fit(b []byte) []byte {
l := len(storj.NodeID{})
if len(b) < l {
return fit(append(b, 255))
// return fit(append([]byte{1}, b...))
}
return b[:l]
}
// MockNode returns a pb node with an ID consisting of the string
// and padding to the node ID length
func MockNode(s string) *pb.Node {
id := NodeIDFromString(s)
var node pb.Node
node.Id = id
return &node
}