segfetcher

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package segfetcher contains all the logic that is needed to fetch segments, verify and store segments in an efficient manner. It is designed to be pluggable into sciond and PS.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadDst = errors.New("bad destination AS")
)

Pather errors.

View Source
var ErrInvalidRequest = serrors.New("invalid request")

ErrInvalidRequest indicates an invalid request.

View Source
var ErrNotReachable = serrors.New("remote not reachable")

ErrNotReachable indicates that the destination is not reachable from this process.

Functions

func ErrToMetricsLabel

func ErrToMetricsLabel(err error) string

ErrToMetricsLabel classifies the error from the segfetcher into metrics labels.

func NewFetcherMetrics added in v0.6.0

func NewFetcherMetrics(ns string) metrics.Fetcher

NewFetcherMetrics exposes the metrics constructor.

XXX(roosd): This should be translated to the new metrics approach.

Types

type DefaultRequester

type DefaultRequester struct {
	RPC         RPC
	DstProvider DstProvider
	// TimeoutFactor is the percentage of the total timeout available for a segment request
	// that is allocated to the next try.
	TimeoutFactor float64
	MaxTries      int
}

DefaultRequester requests all segments that can be requested from a request set.

func (*DefaultRequester) Request

func (r *DefaultRequester) Request(ctx context.Context, reqs Requests) <-chan ReplyOrErr

Request all requests in the request set

type DefaultResolver

type DefaultResolver struct {
	DB        pathdb.Read
	RevCache  revcache.RevCache
	LocalInfo LocalInfo
}

DefaultResolver is the default resolver implementation.

func NewResolver

func NewResolver(DB pathdb.Read, revCache revcache.RevCache, localInfo LocalInfo) *DefaultResolver

NewResolver creates a new resolver with the given DB.

func (*DefaultResolver) Resolve

func (r *DefaultResolver) Resolve(ctx context.Context,
	reqs Requests, refresh bool) (Segments, Requests, error)

Resolve resolves requests. It loads the segments that are locally available from the DB and returns the set of requests that have to be requested at a remote server.

type DstProvider

type DstProvider interface {
	Dst(context.Context, Request) (net.Addr, error)
}

DstProvider provides the destination for a segment lookup including the path.

type Fetcher

type Fetcher struct {
	Resolver     Resolver
	Requester    Requester
	ReplyHandler ReplyHandler
	PathDB       pathdb.PathDB
	// QueryInterval specifies after how much time segments should be
	// refetched at the remote server.
	QueryInterval time.Duration
	Metrics       metrics.Fetcher
}

Fetcher fetches, verifies and stores segments for a path segment request.

func (*Fetcher) Fetch added in v0.6.0

func (f *Fetcher) Fetch(ctx context.Context, reqs Requests, refresh bool) (Segments, error)

Fetch loads the requested segments from the path DB or requests them from a remote path server.

func (*Fetcher) Request added in v0.6.0

func (f *Fetcher) Request(ctx context.Context, reqs Requests) (Segments, error)

type LocalInfo added in v0.5.0

type LocalInfo interface {
	// IsSegLocal returns whether the requested segment is always locally stored.
	IsSegLocal(req Request) bool
}

LocalInfo provides information about which segments are always locally stored.

type MultiSegmentSplitter added in v0.5.0

type MultiSegmentSplitter struct {
	LocalIA   addr.IA
	Core      bool
	Inspector trust.Inspector
}

MultiSegmentSplitter splits requests consisting of one or multiple segments. The AS inspector is used to check whether an IA is core or not.

func (*MultiSegmentSplitter) Split added in v0.5.0

func (s *MultiSegmentSplitter) Split(ctx context.Context, dst addr.IA) (Requests, error)

Split splits a path request from the local AS to dst into a set of segment requests.

type Pather added in v0.5.0

type Pather struct {
	TopoProvider topology.Provider
	RevCache     revcache.RevCache
	Fetcher      *Fetcher
	Splitter     Splitter
}

Pather is used to construct paths from the path database. If necessary, paths are fetched over the network.

func (*Pather) GetPaths added in v0.5.0

func (p *Pather) GetPaths(ctx context.Context, dst addr.IA,
	refresh bool) ([]snet.Path, error)

GetPaths returns all non-revoked and non-expired paths to the destination. The paths are sorted from best to worst according to the weighting in path combinator. In case the destination AS is the same as the local AS, a slice containing an empty path is returned.

type RPC added in v0.6.0

type RPC interface {
	Segments(ctx context.Context, req Request, dst net.Addr) ([]*seg.Meta, error)
}

RPC is used to fetch segments from a remote.

type ReplyHandler

type ReplyHandler interface {
	Handle(ctx context.Context, recs seghandler.Segments,
		server net.Addr) *seghandler.ProcessedResult
}

ReplyHandler handles replies.

type ReplyOrErr

type ReplyOrErr struct {
	Req      Request
	Segments []*seg.Meta
	Peer     net.Addr
	Err      error
}

ReplyOrErr is a seg reply or an error for the given request.

type Request

type Request struct {
	Src     addr.IA
	Dst     addr.IA
	SegType seg.Type
}

Request represents a path or segment request.

func (Request) Equal added in v0.6.0

func (r Request) Equal(other Request) bool

Equal returns whether the two request refer to the same src/dst/type.

func (Request) IsZero

func (r Request) IsZero() bool

IsZero returns whether the request is empty.

type Requester

type Requester interface {
	Request(ctx context.Context, req Requests) <-chan ReplyOrErr
}

Requester requests segments.

type Requests

type Requests []Request

Requests is a list of requests and provides some convenience methods on top of it.

func (Requests) DstIAs

func (r Requests) DstIAs() []addr.IA

DstIAs returns all unique destinations in the request list.

func (Requests) IsEmpty

func (r Requests) IsEmpty() bool

IsEmpty returns whether the list of requests is empty.

func (Requests) SrcIAs

func (r Requests) SrcIAs() []addr.IA

SrcIAs returns all unique sources in the request list.

type Resolver

type Resolver interface {
	// Resolve resolves requests. It loads the segments that are locally available
	// from the DB and returns the set of requests that have to be requested at a
	// remote server.
	Resolve(ctx context.Context, reqs Requests, refresh bool) (Segments, Requests, error)
}

Resolver resolves segments that are locally cached.

type Segments

type Segments []*seg.Meta

func (Segments) Segs added in v0.6.0

func (s Segments) Segs() []*seg.PathSegment

type Splitter

type Splitter interface {
	// Split splits a path request from the local AS to dst into a set of segment requests.
	Split(ctx context.Context, dst addr.IA) (Requests, error)
}

Splitter splits a path request into set of segment requests.

Directories

Path Synopsis
internal
Package mock_segfetcher is a generated GoMock package.
Package mock_segfetcher is a generated GoMock package.

Jump to

Keyboard shortcuts

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