storj/satellite/nodeselection/node.go
Márton Elek 6304046e80 satellite/nodeselection: read email + wallet from db to SelectedNode
NodeSelection struct is used to make decisions (and assertions) related to node selection.

Usually we don't use email and wallet for placement decision, as they are not reliable.

But there are cases, when we know that the email address is confirmed. Also, it can be used for upper-bound estimations (if same wallet is used for too many pieces in a segment, it's a sign of a risk, even if not all the risks can be detected with this approach, as one owner can use different wallets).

Long story short: let's put wallet and email to the SelectedNode.

Change-Id: I922185e3769d43eb7762b8d60d88ecd3d50991bb
2023-10-03 18:15:56 +00:00

61 lines
1.4 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package nodeselection
import (
"time"
"github.com/zeebo/errs"
"golang.org/x/exp/slices"
"storj.io/common/pb"
"storj.io/common/storj"
"storj.io/common/storj/location"
)
// NodeTag is a tag associated with a node (approved by signer).
type NodeTag struct {
NodeID storj.NodeID
SignedAt time.Time
Signer storj.NodeID
Name string
Value []byte
}
// 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
Email string
Wallet string
LastNet string
LastIPPort string
CountryCode location.CountryCode
Exiting bool
Suspended bool
Online bool
Tags NodeTags
}
// Clone returns a deep clone of the selected node.
func (node *SelectedNode) Clone() *SelectedNode {
newNode := *node
newNode.Address = pb.CopyNodeAddress(node.Address)
newNode.Tags = slices.Clone(node.Tags)
return &newNode
}