29fd36a20e
For nodes in excluded areas, we don't necessarily want to remove them from the pointer, but we do want to increase the number of pieces in the segment in case those excluded area nodes go down. To do that, we increase the number of pieces repaired by the number of pieces in excluded areas. Change-Id: I0424f1bcd7e93f33eb3eeeec79dbada3b3ea1f3a
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// Copyright (C) 2021 Storj Labs, Inc.
|
|
// See LICENSE for copying information
|
|
|
|
package uploadselection
|
|
|
|
import (
|
|
"storj.io/common/storj"
|
|
"storj.io/common/storj/location"
|
|
)
|
|
|
|
// 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
|
|
ExcludedCountryCodes []location.CountryCode
|
|
}
|
|
|
|
// 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{}{}
|
|
}
|
|
|
|
for _, code := range c.ExcludedCountryCodes {
|
|
if code.String() == "" {
|
|
continue
|
|
}
|
|
if node.CountryCode == code {
|
|
return false
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|