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"
|
|
|
|
|
|
|
|
"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
|
2021-10-29 13:29:14 +01:00
|
|
|
LastNet string
|
|
|
|
LastIPPort string
|
|
|
|
CountryCode location.CountryCode
|
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 {
|
|
|
|
copy := pb.CopyNode(&pb.Node{Id: node.ID, Address: node.Address})
|
2023-06-30 11:13:18 +01:00
|
|
|
tags := make([]NodeTag, len(node.Tags))
|
|
|
|
for ix, tag := range node.Tags {
|
|
|
|
tags[ix] = NodeTag{
|
|
|
|
NodeID: tag.NodeID,
|
|
|
|
SignedAt: tag.SignedAt,
|
|
|
|
Signer: tag.Signer,
|
|
|
|
Name: tag.Name,
|
|
|
|
Value: tag.Value,
|
|
|
|
}
|
|
|
|
}
|
2023-06-30 11:35:07 +01:00
|
|
|
return &SelectedNode{
|
|
|
|
ID: copy.Id,
|
|
|
|
Address: copy.Address,
|
2021-10-29 13:29:14 +01:00
|
|
|
LastNet: node.LastNet,
|
|
|
|
LastIPPort: node.LastIPPort,
|
|
|
|
CountryCode: node.CountryCode,
|
2023-06-30 11:13:18 +01:00
|
|
|
Tags: tags,
|
2020-05-15 15:32:28 +01:00
|
|
|
}
|
|
|
|
}
|