nodeselection

package
v1.7.3 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2020 License: AGPL-3.0 Imports: 6 Imported by: 5

Documentation

Overview

Package nodeselection implements node selection logic.

Index

Constants

This section is empty.

Variables

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 nodeselection error
	Error = errs.Class("nodeselection")
)

Functions

func ContainsID

func ContainsID(ids []storj.NodeID, id storj.NodeID) bool

ContainsID returns whether ids contains id.

Types

type Node

type Node struct {
	storj.NodeURL
	LastNet    string
	LastIPPort string
}

Node defines necessary information for node-selection.

func (*Node) Clone

func (node *Node) Clone() *Node

Clone returns a deep clone of the selected node.

type Request

type Request struct {
	Count       int
	NewFraction float64
	Distinct    bool
	ExcludedIDs []storj.NodeID
}

Request contains arguments for State.Request.

type SelectByID

type SelectByID []*Node

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, excludedIDs []storj.NodeID, excludedNets map[string]struct{}) []*Node

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 []*Node) 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, excludedIDs []storj.NodeID, excludedNets map[string]struct{}) []*Node

Select selects upto n nodes.

type Selector

type Selector interface {
	// Count returns the number of maximum number of nodes that it can return.
	Count() int
	// Select selects up-to n nodes and excluding the IDs.
	// When excludedNets is non-nil it will ensure that selected network is unique.
	Select(n int, excludedIDs []storj.NodeID, excludeNets map[string]struct{}) []*Node
}

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 []*Node) *State

NewState returns a state based on the input.

func (*State) Select

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

Select selects requestedCount nodes where there will be newFraction nodes.

func (*State) Stats

func (state *State) Stats() Stats

Stats returns state information.

type Stats

type Stats struct {
	New       int
	Reputable int

	NewDistinct       int
	ReputableDistinct int
}

Stats contains state information.

type Subnet

type Subnet struct {
	Net   string
	Nodes []*Node
}

Subnet groups together nodes with the same subnet.

Jump to

Keyboard shortcuts

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