planning

package
v0.0.0-...-de8e8a8 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: MIT, Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTransport = fmt.Errorf("no routes available")

ErrNoTransport is an error option a transport plan my emit when no transports are currently possible

Functions

This section is empty.

Types

type Board

type Board struct {
	Possible []*TransportRequest
	Pending  []*TransportRequest
	Failed   []*TransportRequest
	Complete []*TransportRequest
	// contains filtered or unexported fields
}

Board keeps track of the state machine of transfers. requests transition from possible->pending->{failed, complete}

func NewBoard

func NewBoard() *Board

NewBoard initializes a new Board for planning requests

func (*Board) Active

func (b *Board) Active() bool

Active returns if there is active work ongoing or available from the board

func (*Board) AddPossible

func (b *Board) AddPossible(r *TransportRequest)

AddPossible tells the board about a new potential transfer

func (*Board) Begin

func (b *Board) Begin(r *TransportRequest)

Begin starts a possible transport request (moves it to pending)

func (*Board) HighestScore

func (b *Board) HighestScore() *TransportRequest

HighestScore determines the next most promissing transfer to attempt currently this is a very simple setup: weight increases for each successful transfer from that provider. weight decreses by 5 for each unsuccessful transfer from that provider. weight decreases by 1 for each in-progress transfer from that provider.

func (*Board) Reconcile

func (b *Board) Reconcile(r *TransportRequest, success bool)

Reconcile accounts for a pending transport request resolving, either successfully or not

type FilecoinV1RecordInterpreter

type FilecoinV1RecordInterpreter struct {
}

func (FilecoinV1RecordInterpreter) Interpret

type Policy

type Policy interface {
	Name() PolicyName
}

type PolicyName

type PolicyName string

type PolicyPreferences

type PolicyPreferences struct {
	// contains filtered or unexported fields
}

func (*PolicyPreferences) AddPolicy

func (p *PolicyPreferences) AddPolicy(weight PolicyWeight, policy Policy)

func (*PolicyPreferences) Policies

func (p *PolicyPreferences) Policies() []Policy

func (*PolicyPreferences) WeightedScore

func (p *PolicyPreferences) WeightedScore(results PolicyResults, transportMultipler PolicyWeight) PolicyScore

type PolicyResults

type PolicyResults interface {
	// must be in range from zero to 1, will get dropped otherwise
	// should return zero for policies that are unrecognized
	Score(PolicyName) PolicyScore
}

type PolicyScore

type PolicyScore float64

type PolicyWeight

type PolicyWeight float64

type PotentialRequest

type PotentialRequest struct {
	PolicyScore
	contentrouting.RoutingRecord
}

type RoutingRecordInterpreter

type RoutingRecordInterpreter interface {
	Interpret(record contentrouting.RoutingRecord, policies []Policy) (PolicyResults, error)
}

RoutingRecordInterpreter interprets records for a given multicodec range

type Scheduler

type Scheduler interface {
	// plan the fetch of a root+selector of data given a set of learned routing records.
	Schedule(ctx context.Context, root cid.Cid, selector ipld.Node, potentialTransports <-chan contentrouting.RoutingRecord) <-chan TransportPlan
	// Indicate that a transfer in the schedule has started
	Begin(r *TransportRequest)
	// Indicate that a transfer in the schedule has completed
	Reconcile(r *TransportRequest, success bool)
}

Scheduler provides an interface for deciding which potential transports to begin when.

func NewSimpleScheduler

func NewSimpleScheduler() Scheduler

NewSimpleScheduler creates an instance of a SimpleScheduler

type SimplePlanner

type SimplePlanner struct {
	// contains filtered or unexported fields
}

func NewSimplePlanner

func NewSimplePlanner(singlePlanner SinglePlanner) *SimplePlanner

func (*SimplePlanner) PlanRequests

func (p *SimplePlanner) PlanRequests(ctx context.Context, root cid.Cid, selector ipld.Node, policyPreference PolicyPreferences, routingResults <-chan contentrouting.RoutingRecord) <-chan TransportPlan

func (*SimplePlanner) RegisterRecordInterpreter

func (p *SimplePlanner) RegisterRecordInterpreter(minRange multicodec.Code, maxRange multicodec.Code, transportMultiplier PolicyWeight, interpreter RoutingRecordInterpreter) error

type SimpleScheduler

type SimpleScheduler struct {
	// contains filtered or unexported fields
}

A SimpleScheduler will attempt to generate a tansport plan based on a board tracking active requests

func (*SimpleScheduler) Begin

func (s *SimpleScheduler) Begin(r *TransportRequest)

Begin is called to tell the scheduler that a transport request has begun

func (*SimpleScheduler) Reconcile

func (s *SimpleScheduler) Reconcile(r *TransportRequest, success bool)

Reconcile is called to tell that a transport request has finished

func (*SimpleScheduler) Schedule

func (s *SimpleScheduler) Schedule(ctx context.Context, root cid.Cid, selector ipld.Node, potentialTransports <-chan contentrouting.RoutingRecord) <-chan TransportPlan

Schedule begins a schedule to get a cid+selector given a stream of potential routes. SimpleScheduler only handles one Schedule call concurrently.

type SinglePlanner

type SinglePlanner interface {
	GeneratePlan(ctx context.Context, targetRoot cid.Cid, targetSelector ipld.Node, potentialRequests <-chan PotentialRequest) <-chan TransportPlan
}

SinglePlanner takes a stream of possible transport requests we can make and generates a single transport plan from that And implementation might consider: - minimum policy score - minimum number of results to receive before executing - how many requests to make at once - how to split requests up among peers

func NewSimpleSinglePlanner

func NewSimpleSinglePlanner(minPolicyScore PolicyScore, maxWaitTime time.Duration) SinglePlanner

type TransportPlan

type TransportPlan struct {
	TransportRequests []*TransportRequest
	Error             error
}

TransportPlan indicates one or more TransportRequests we want to execute

type TransportRequest

type TransportRequest struct {
	Codec           multicodec.Code
	Root            ipld.Link
	Selector        ipld.Node
	RoutingProvider interface{}
	RoutingPayload  interface{}
}

TransportRequest describes a single request over a single transport

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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