Documentation ¶
Overview ¶
Package uploadselection implements node selection logic for uploads.
Index ¶
- Constants
- Variables
- func AllowSameSubnet(filter NodeFilter) bool
- func GetAnnotation(filter NodeFilter, name string) string
- type AnnotatedNodeFilter
- type Annotation
- type AnyFilter
- type CountryFilter
- type ExcludeAllFilter
- type ExcludeFilter
- type ExcludedIDs
- type ExcludedNetworks
- type ExcludedNodeNetworks
- type NodeFilter
- type NodeFilterFunc
- type NodeFilterWithAnnotation
- type NodeFilters
- type NodeTag
- type NodeTags
- type RandomOrder
- type Request
- type SelectByID
- type SelectBySubnet
- type SelectedNode
- type SelectionType
- type Selector
- type State
- type Subnet
- type TagFilter
Constants ¶
const ( // AutoExcludeSubnet is placement annotation key to turn off subnet // restrictions. AutoExcludeSubnet = "autoExcludeSubnet" // AutoExcludeSubnetOFF is the value of AutoExcludeSubnet to disable subnet // restrictions. AutoExcludeSubnetOFF = "off" // Location is the placement annotation key for meaningful and // human-readable descriptions of placements. Location = "location" )
const ( // SelectionTypeByNetwork chooses subnets randomly, and one node from each subnet. SelectionTypeByNetwork = iota // SelectionTypeByID chooses nodes randomly. SelectionTypeByID )
Variables ¶
var EeaCountriesWithoutEu = []location.CountryCode{ location.Iceland, location.Liechtenstein, location.Norway, }
EeaCountriesWithoutEu defined the EEA countries.
var ErrNotEnoughNodes = errs.Class("not enough nodes")
ErrNotEnoughNodes is when selecting nodes failed with the given parameters.
var ( // Error represents an uploadselection error. Error = errs.Class("uploadselection") )
var EuCountries = []location.CountryCode{ location.Austria, location.Belgium, location.Bulgaria, location.Croatia, location.Cyprus, location.Czechia, location.Denmark, location.Estonia, location.Finland, location.France, location.Germany, location.Greece, location.Hungary, location.Ireland, location.Italy, location.Lithuania, location.Latvia, location.Luxembourg, location.Malta, location.Netherlands, location.Poland, location.Portugal, location.Romania, location.Slovenia, location.Slovakia, location.Spain, location.Sweden, }
EuCountries defines the member countries of European Union.
Functions ¶
func AllowSameSubnet ¶ added in v1.86.2
func AllowSameSubnet(filter NodeFilter) bool
AllowSameSubnet is a short to check if Subnet exclusion is disabled == allow pick nodes from the same subnet.
func GetAnnotation ¶ added in v1.86.1
func GetAnnotation(filter NodeFilter, name string) string
GetAnnotation retrieves annotation from AnnotatedNodeFilter.
Types ¶
type AnnotatedNodeFilter ¶ added in v1.86.1
type AnnotatedNodeFilter struct { Filter NodeFilter Annotations []Annotation }
AnnotatedNodeFilter is just a NodeFilter with additional annotations.
func (AnnotatedNodeFilter) GetAnnotation ¶ added in v1.87.1
func (a AnnotatedNodeFilter) GetAnnotation(name string) string
GetAnnotation implements NodeFilterWithAnnotation.
func (AnnotatedNodeFilter) MatchInclude ¶ added in v1.86.1
func (a AnnotatedNodeFilter) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter.
type Annotation ¶ added in v1.87.1
Annotation can be used as node filters in 'XX && annotation('...')' like struct.
func (Annotation) GetAnnotation ¶ added in v1.87.1
func (a Annotation) GetAnnotation(name string) string
GetAnnotation implements NodeFilterWithAnnotation.
func (Annotation) MatchInclude ¶ added in v1.87.1
func (a Annotation) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter.
type AnyFilter ¶ added in v1.86.1
type AnyFilter struct{}
AnyFilter matches all the nodes.
func (AnyFilter) MatchInclude ¶ added in v1.86.1
func (a AnyFilter) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type CountryFilter ¶ added in v1.84.1
type CountryFilter struct {
// contains filtered or unexported fields
}
CountryFilter can select nodes based on the condition of the country code.
func (*CountryFilter) MatchInclude ¶ added in v1.84.1
func (p *CountryFilter) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type ExcludeAllFilter ¶ added in v1.84.1
type ExcludeAllFilter struct{}
ExcludeAllFilter will never select any node.
func (ExcludeAllFilter) MatchInclude ¶ added in v1.84.1
func (ExcludeAllFilter) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type ExcludeFilter ¶ added in v1.86.1
type ExcludeFilter struct {
// contains filtered or unexported fields
}
ExcludeFilter excludes only the matched nodes.
func NewExcludeFilter ¶ added in v1.86.1
func NewExcludeFilter(filter NodeFilter) ExcludeFilter
NewExcludeFilter creates filter, nodes matching the given filter will be excluded.
func (ExcludeFilter) MatchInclude ¶ added in v1.86.1
func (e ExcludeFilter) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type ExcludedIDs ¶ added in v1.84.1
ExcludedIDs can blacklist NodeIDs.
func (ExcludedIDs) MatchInclude ¶ added in v1.84.1
func (e ExcludedIDs) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type ExcludedNetworks ¶ added in v1.84.1
type ExcludedNetworks []string
ExcludedNetworks will exclude nodes with specified networks.
func (ExcludedNetworks) MatchInclude ¶ added in v1.84.1
func (e ExcludedNetworks) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type ExcludedNodeNetworks ¶ added in v1.86.1
type ExcludedNodeNetworks []*SelectedNode
ExcludedNodeNetworks exclude nodes which has same net as the one of the specified.
func (ExcludedNodeNetworks) MatchInclude ¶ added in v1.86.1
func (e ExcludedNodeNetworks) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type NodeFilter ¶ added in v1.84.1
type NodeFilter interface {
MatchInclude(node *SelectedNode) bool
}
NodeFilter can decide if a Node should be part of the selection or not.
func NewCountryFilter ¶ added in v1.84.1
func NewCountryFilter(permit location.Set) NodeFilter
NewCountryFilter creates a new CountryFilter.
type NodeFilterFunc ¶ added in v1.84.1
type NodeFilterFunc func(node *SelectedNode) bool
NodeFilterFunc is helper to use func as NodeFilter.
func (NodeFilterFunc) MatchInclude ¶ added in v1.84.1
func (n NodeFilterFunc) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
type NodeFilterWithAnnotation ¶ added in v1.87.1
type NodeFilterWithAnnotation interface { NodeFilter GetAnnotation(name string) string }
NodeFilterWithAnnotation is a NodeFilter with additional annotations.
func WithAnnotation ¶ added in v1.86.1
func WithAnnotation(filter NodeFilter, name string, value string) NodeFilterWithAnnotation
WithAnnotation adds annotations to a NodeFilter.
type NodeFilters ¶ added in v1.84.1
type NodeFilters []NodeFilter
NodeFilters is a collection of multiple node filters (all should vote with true).
func (NodeFilters) GetAnnotation ¶ added in v1.87.1
func (n NodeFilters) GetAnnotation(name string) string
GetAnnotation implements NodeFilterWithAnnotation.
func (NodeFilters) MatchInclude ¶ added in v1.84.1
func (n NodeFilters) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.
func (NodeFilters) WithCountryFilter ¶ added in v1.84.1
func (n NodeFilters) WithCountryFilter(permit location.Set) NodeFilters
WithCountryFilter is a helper to create a new filter with additional CountryFilter.
func (NodeFilters) WithExcludedIDs ¶ added in v1.84.1
func (n NodeFilters) WithExcludedIDs(ds []storj.NodeID) NodeFilters
WithExcludedIDs is a helper to create a new filter with additional WithExcludedIDs.
type NodeTag ¶ added in v1.84.1
type NodeTag struct { NodeID storj.NodeID SignedAt time.Time Signer storj.NodeID Name string Value []byte }
NodeTag is a tag associated with a node (approved by signer).
type NodeTags ¶ added in v1.84.1
type NodeTags []NodeTag
NodeTags is a collection of multiple NodeTag.
type RandomOrder ¶ added in v1.86.1
type RandomOrder struct {
// contains filtered or unexported fields
}
RandomOrder as an iterator of a pseudo-random permutation set.
func NewRandomOrder ¶ added in v1.86.1
func NewRandomOrder(n int) RandomOrder
NewRandomOrder creates new iterator, returns number between [0,n) in pseudo-random order.
func (*RandomOrder) At ¶ added in v1.86.1
func (r *RandomOrder) At() uint64
At returns the current number in the permutations.
func (*RandomOrder) Next ¶ added in v1.86.1
func (r *RandomOrder) Next() bool
Next generates the next number.
type Request ¶
type Request struct { Count int NewFraction float64 NodeFilters NodeFilters SelectionType SelectionType }
Request contains arguments for State.Request.
type SelectByID ¶
type SelectByID []*SelectedNode
SelectByID implements selection from nodes with every node having equal probability.
func (SelectByID) Count ¶
func (nodes SelectByID) Count() int
Count returns the number of maximum number of nodes that it can return.
func (SelectByID) Select ¶
func (nodes SelectByID) Select(n int, nodeFilter NodeFilter) []*SelectedNode
Select selects upto n nodes.
type SelectBySubnet ¶
type SelectBySubnet []Subnet
SelectBySubnet implements selection from nodes with every subnet having equal probability.
func SelectBySubnetFromNodes ¶
func SelectBySubnetFromNodes(nodes []*SelectedNode) SelectBySubnet
SelectBySubnetFromNodes creates SelectBySubnet selector from nodes.
func (SelectBySubnet) Count ¶
func (subnets SelectBySubnet) Count() int
Count returns the number of maximum number of nodes that it can return.
func (SelectBySubnet) Select ¶
func (subnets SelectBySubnet) Select(n int, filter NodeFilter) []*SelectedNode
Select selects upto n nodes.
type SelectedNode ¶ added in v1.84.1
type SelectedNode struct { ID storj.NodeID Address *pb.NodeAddress LastNet string LastIPPort string CountryCode location.CountryCode Exiting bool Suspended bool Online bool Tags NodeTags }
SelectedNode is used as a result for creating orders limits.
func (*SelectedNode) Clone ¶ added in v1.84.1
func (node *SelectedNode) Clone() *SelectedNode
Clone returns a deep clone of the selected node.
type SelectionType ¶ added in v1.86.1
type SelectionType int8
SelectionType defines how to select nodes randomly.
type Selector ¶
type Selector interface { // Select selects up-to n nodes which are included by the criteria. // empty criteria includes all the nodes Select(n int, nodeFilter NodeFilter) []*SelectedNode }
Selector defines interface for selecting nodes.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State defines a node selector state that allows for selection.
func NewState ¶
func NewState(reputableNodes, newNodes []*SelectedNode) *State
NewState returns a state based on the input.
func (*State) ExcludeNetworksBasedOnNodes ¶ added in v1.84.1
func (state *State) ExcludeNetworksBasedOnNodes(ds []storj.NodeID) NodeFilter
ExcludeNetworksBasedOnNodes will create a NodeFilter which exclude all nodes which shares subnet with the specified ones.
type Subnet ¶
type Subnet struct { Net string Nodes []*SelectedNode }
Subnet groups together nodes with the same subnet.
type TagFilter ¶ added in v1.84.1
type TagFilter struct {
// contains filtered or unexported fields
}
TagFilter matches nodes with specific tags.
func NewTagFilter ¶ added in v1.84.1
NewTagFilter creates a new tag filter.
func (TagFilter) MatchInclude ¶ added in v1.84.1
func (t TagFilter) MatchInclude(node *SelectedNode) bool
MatchInclude implements NodeFilter interface.