nodeselection

package
v1.92.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2023 License: AGPL-3.0 Imports: 13 Imported by: 5

Documentation

Overview

Package uploadselection implements node selection logic for uploads.

Index

Constants

View Source
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"
)
View Source
const (
	// SelectionTypeByNetwork chooses subnets randomly, and one node from each subnet.
	SelectionTypeByNetwork = iota

	// SelectionTypeByID chooses nodes randomly.
	SelectionTypeByID
)

Variables

EeaCountriesWithoutEu defined the EEA countries.

View Source
var ErrNotEnoughNodes = errs.Class("not enough nodes")

ErrNotEnoughNodes is when selecting nodes failed with the given parameters.

View Source
var (

	// Error represents an uploadselection error.
	Error = errs.Class("uploadselection")
)

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) Match added in v1.88.2

func (a AnnotatedNodeFilter) Match(node *SelectedNode) bool

Match implements NodeFilter.

func (AnnotatedNodeFilter) String added in v1.89.2

func (a AnnotatedNodeFilter) String() string

type Annotation added in v1.87.1

type Annotation struct {
	Key   string
	Value string
}

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) Match added in v1.88.2

func (a Annotation) Match(node *SelectedNode) bool

Match implements NodeFilter.

func (Annotation) String added in v1.89.2

func (a Annotation) String() string

type AnyFilter added in v1.86.1

type AnyFilter struct{}

AnyFilter matches all the nodes.

func (AnyFilter) Match added in v1.88.2

func (a AnyFilter) Match(node *SelectedNode) bool

Match 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 NewCountryFilter added in v1.84.1

func NewCountryFilter(permit location.Set) *CountryFilter

NewCountryFilter creates a new CountryFilter.

func NewCountryFilterFromString added in v1.89.2

func NewCountryFilterFromString(countries []string) (*CountryFilter, error)

NewCountryFilterFromString parses country definitions like 'hu','!hu','*','none' and creates a CountryFilter.

func (*CountryFilter) Match added in v1.88.2

func (p *CountryFilter) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

func (*CountryFilter) String added in v1.89.2

func (p *CountryFilter) String() string

type ExcludeAllFilter added in v1.84.1

type ExcludeAllFilter struct{}

ExcludeAllFilter will never select any node.

func (ExcludeAllFilter) Match added in v1.88.2

func (ExcludeAllFilter) Match(node *SelectedNode) bool

Match 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) Match added in v1.88.2

func (e ExcludeFilter) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

func (ExcludeFilter) String added in v1.89.2

func (e ExcludeFilter) String() string

type ExcludedIDs added in v1.84.1

type ExcludedIDs []storj.NodeID

ExcludedIDs can blacklist NodeIDs.

func (ExcludedIDs) Match added in v1.88.2

func (e ExcludedIDs) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

type ExcludedNetworks added in v1.84.1

type ExcludedNetworks []string

ExcludedNetworks will exclude nodes with specified networks.

func (ExcludedNetworks) Match added in v1.88.2

func (e ExcludedNetworks) Match(node *SelectedNode) bool

Match 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) Match added in v1.88.2

func (e ExcludedNodeNetworks) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

type NodeFilter added in v1.84.1

type NodeFilter interface {
	Match(node *SelectedNode) bool
}

NodeFilter can decide if a Node should be part of the selection or not.

type NodeFilterFunc added in v1.84.1

type NodeFilterFunc func(node *SelectedNode) bool

NodeFilterFunc is helper to use func as NodeFilter.

func (NodeFilterFunc) Match added in v1.88.2

func (n NodeFilterFunc) Match(node *SelectedNode) bool

Match 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) Match added in v1.88.2

func (n NodeFilters) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

func (NodeFilters) String added in v1.89.2

func (n NodeFilters) String() string

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.

func (NodeTags) FindBySignerAndName added in v1.84.1

func (n NodeTags) FindBySignerAndName(signer storj.NodeID, name string) (NodeTag, error)

FindBySignerAndName selects first tag with same name / NodeID.

type OrFilter added in v1.91.2

type OrFilter []NodeFilter

OrFilter will include the node, if at lest one of the filters are matched.

func (OrFilter) Match added in v1.91.2

func (n OrFilter) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

func (OrFilter) String added in v1.91.2

func (n OrFilter) String() string

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
	Email       string
	Wallet      string
	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.

func (*State) Select

func (state *State) Select(ctx context.Context, request Request) (_ []*SelectedNode, err error)

Select selects requestedCount nodes where there will be newFraction nodes.

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

func NewTagFilter(id storj.NodeID, name string, value []byte, match ValueMatch) TagFilter

NewTagFilter creates a new tag filter.

func (TagFilter) Match added in v1.88.2

func (t TagFilter) Match(node *SelectedNode) bool

Match implements NodeFilter interface.

func (TagFilter) String added in v1.89.2

func (t TagFilter) String() string

type ValueMatch added in v1.89.2

type ValueMatch func(a []byte, b []byte) bool

ValueMatch defines how to compare tag value with the defined one.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL