storj/internal/teststorj/node.go
Jennifer Li Johnson a2fa5c4c5a Proper NodeType Handling (#873)
* adds enums to nodetype

* updating nodetype todos

* ran pb updates

* reorder nodetypes

* adding checks

* wip

* wip

* wip

* bug in test-captplanet

* wip

* add values to storagenode, satellite, captplanet binaries

* Cleanup

* more cleanup

* wip

* lint

* lint

* wip

* fixes bug

* regenerate protos

Change-Id: Id270212e8c7479e52641058042cf23b5317ab773

* limit node type changes to kademlia

Change-Id: I9c1a6cc4a79e05086627f0fdeb5028c62ce754f4

* dpanic

Change-Id: Id952a2ad13c807ebaea0ec0a875405e267d81c3e

* review comments

Change-Id: I7f9b77ef22779dd012fd490375b136014f51f834
2019-01-02 11:47:34 -07:00

61 lines
1.4 KiB
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package teststorj
import (
"storj.io/storj/pkg/pb"
"storj.io/storj/pkg/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
node.Type = pb.NodeType_STORAGE
return &node
}