9bdcc415bc
Closes https://github.com/storj/storj/issues/4242 Change-Id: Ieda59a4f37c673e4e81abb4c89c09daf3199bbc7
45 lines
997 B
Go
45 lines
997 B
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information
|
|
|
|
package uploadselection
|
|
|
|
import (
|
|
"storj.io/common/storj"
|
|
)
|
|
|
|
// Criteria to filter nodes.
|
|
type Criteria struct {
|
|
ExcludeNodeIDs []storj.NodeID
|
|
AutoExcludeSubnets map[string]struct{} // initialize it with empty map to keep only one node per subnet.
|
|
Placement storj.PlacementConstraint
|
|
}
|
|
|
|
// MatchInclude returns with true if node is selected.
|
|
func (c *Criteria) MatchInclude(node *Node) bool {
|
|
if ContainsID(c.ExcludeNodeIDs, node.ID) {
|
|
return false
|
|
}
|
|
|
|
if !c.Placement.AllowedCountry(node.CountryCode) {
|
|
return false
|
|
}
|
|
|
|
if c.AutoExcludeSubnets != nil {
|
|
if _, excluded := c.AutoExcludeSubnets[node.LastNet]; excluded {
|
|
return false
|
|
}
|
|
c.AutoExcludeSubnets[node.LastNet] = struct{}{}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// ContainsID returns whether ids contain id.
|
|
func ContainsID(ids []storj.NodeID, id storj.NodeID) bool {
|
|
for _, k := range ids {
|
|
if k == id {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|