2021-10-25 13:27:59 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
2020-05-15 15:32:28 +01:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2023-07-07 09:31:58 +01:00
|
|
|
package nodeselection
|
2020-05-15 15:32:28 +01:00
|
|
|
|
|
|
|
import (
|
2023-06-30 11:35:07 +01:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
2023-07-31 23:18:32 +01:00
|
|
|
"golang.org/x/exp/slices"
|
2023-06-30 11:35:07 +01:00
|
|
|
|
|
|
|
"storj.io/common/pb"
|
2020-05-15 15:32:28 +01:00
|
|
|
"storj.io/common/storj"
|
2021-10-29 13:29:14 +01:00
|
|
|
"storj.io/common/storj/location"
|
2020-05-15 15:32:28 +01:00
|
|
|
)
|
|
|
|
|
2023-06-30 11:35:07 +01:00
|
|
|
// NodeTag is a tag associated with a node (approved by signer).
|
|
|
|
type NodeTag struct {
|
2023-06-30 11:35:16 +01:00
|
|
|
NodeID storj.NodeID
|
|
|
|
SignedAt time.Time
|
|
|
|
Signer storj.NodeID
|
|
|
|
Name string
|
|
|
|
Value []byte
|
2023-06-30 11:35:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// NodeTags is a collection of multiple NodeTag.
|
|
|
|
type NodeTags []NodeTag
|
|
|
|
|
|
|
|
// FindBySignerAndName selects first tag with same name / NodeID.
|
|
|
|
func (n NodeTags) FindBySignerAndName(signer storj.NodeID, name string) (NodeTag, error) {
|
|
|
|
for _, tag := range n {
|
|
|
|
if tag.Name == name && signer == tag.Signer {
|
|
|
|
return tag, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NodeTag{}, errs.New("tags not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
// SelectedNode is used as a result for creating orders limits.
|
|
|
|
type SelectedNode struct {
|
|
|
|
ID storj.NodeID
|
|
|
|
Address *pb.NodeAddress
|
2023-10-03 10:07:51 +01:00
|
|
|
Email string
|
|
|
|
Wallet string
|
2021-10-29 13:29:14 +01:00
|
|
|
LastNet string
|
|
|
|
LastIPPort string
|
|
|
|
CountryCode location.CountryCode
|
2023-07-31 23:18:32 +01:00
|
|
|
Exiting bool
|
|
|
|
Suspended bool
|
|
|
|
Online bool
|
2023-06-30 11:13:18 +01:00
|
|
|
Tags NodeTags
|
2020-05-15 15:32:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clone returns a deep clone of the selected node.
|
2023-06-30 11:35:07 +01:00
|
|
|
func (node *SelectedNode) Clone() *SelectedNode {
|
2023-07-31 23:18:32 +01:00
|
|
|
newNode := *node
|
|
|
|
newNode.Address = pb.CopyNodeAddress(node.Address)
|
|
|
|
newNode.Tags = slices.Clone(node.Tags)
|
|
|
|
return &newNode
|
2020-05-15 15:32:28 +01:00
|
|
|
}
|