segfetcher

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 20 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 ErrInvalidRequest = serrors.New("invalid request")

ErrInvalidRequest indicates an invalid request.

Functions

func DeleteNextQueryEntries

func DeleteNextQueryEntries(ctx context.Context, tx pathdb.Transaction,
	results query.Results) error

DeleteNextQueryEntries deletes all NextQuery entries that are described by the given query result set.

func ErrToMetricsLabel

func ErrToMetricsLabel(err error) string

ErrToMetricsLabel classifies the error from the segfetcher into metrics labels.

Types

type DefaultRequester

type DefaultRequester struct {
	API         RequestAPI
	DstProvider DstProvider
}

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

func (*DefaultRequester) Request

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

Request all requests in the request set that are in fetch state.

type DefaultResolver

type DefaultResolver struct {
	DB         pathdb.Read
	RevCache   revcache.RevCache
	IgnoreRevs bool
}

DefaultResolver is the default resolver implementation.

func NewResolver

func NewResolver(DB pathdb.Read, revCache revcache.RevCache, ignoreRevs bool) *DefaultResolver

NewResolver creates a new resolver with the given DB. The DB might be customized. E.g. a PS could inject a wrapper around GetNextQuery so that it always returns that the cache is up to date for segments that should be available local.

func (*DefaultResolver) Resolve

func (r *DefaultResolver) Resolve(ctx context.Context, segs Segments,
	req RequestSet) (Segments, RequestSet, error)

Resolve resolves a request set. It returns the segments that are locally stored and 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.

type Fetcher

type Fetcher struct {
	Validator             Validator
	Splitter              Splitter
	Resolver              Resolver
	Requester             Requester
	ReplyHandler          ReplyHandler
	PathDB                pathdb.PathDB
	QueryInterval         time.Duration
	NextQueryCleaner      NextQueryCleaner
	CryptoLookupAtLocalCS bool
	// contains filtered or unexported fields
}

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

func (*Fetcher) FetchSegs

func (f *Fetcher) FetchSegs(ctx context.Context, req Request) (Segments, error)

FetchSegs fetches the required segments to build a path between src and dst of the request. First the request is validated and then depending on the cache the segments are fetched from the remote server.

type FetcherConfig

type FetcherConfig struct {
	// QueryInterval specifies after how much time segments should be
	// refetched at the remote server.
	QueryInterval time.Duration
	// LocalIA is the IA this process is in.
	LocalIA addr.IA
	// VerificationFactory is the verification factory to use.
	VerificationFactory infra.VerificationFactory
	// ASInspector is the as inspector to use.
	ASInspector infra.ASInspector
	// PathDB is the path db to use.
	PathDB pathdb.PathDB
	// RevCache is the revocation cache to use.
	RevCache revcache.RevCache
	// RequestAPI is the request api to use.
	RequestAPI RequestAPI
	// DstProvider provides destinations to fetch segments from
	DstProvider DstProvider
	// Validator is used to validate requests.
	Validator Validator
	// Splitter is used to split requests.
	Splitter Splitter
	// SciondMode enables sciond mode, this means it uses the local CS to fetch
	// crypto material and considers revocations in the path lookup.
	SciondMode bool
	// The namespace used for metrics.
	MetricsNamespace string
}

FetcherConfig is the configuration for the fetcher.

func (FetcherConfig) New

func (cfg FetcherConfig) New() *Fetcher

New creates a new fetcher from the configuration.

type NextQueryCleaner

type NextQueryCleaner struct {
	PathDB pathdb.PathDB
}

NextQueryCleaner can be used to delete next query entries from a pathdb.

func (*NextQueryCleaner) ResetQueryCache

func (c *NextQueryCleaner) ResetQueryCache(ctx context.Context, revInfo *path_mgmt.RevInfo) error

ResetQueryCache deletes all NextQuery entries for segments that contain the revoked interface.

type ReplyHandler

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

ReplyHandler handles replies.

type ReplyOrErr

type ReplyOrErr struct {
	Req   Request
	Reply *path_mgmt.SegReply
	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
	State RequestState
}

Request represents a path or segment request.

func (Request) EqualAddr

func (r Request) EqualAddr(other Request) bool

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

func (Request) IsZero

func (r Request) IsZero() bool

IsZero returns whether the request is empty.

func (Request) ToSegReq

func (r Request) ToSegReq() *path_mgmt.SegReq

ToSegReq returns the request as a path_mgmt segment request.

type RequestAPI

type RequestAPI interface {
	GetSegs(ctx context.Context, msg *path_mgmt.SegReq, a net.Addr,
		id uint64) (*path_mgmt.SegReply, error)
}

RequestAPI is the API to get segments from the network.

type RequestSet

type RequestSet struct {
	Up    Request
	Cores Requests
	Down  Request
}

RequestSet is a set of requests.

func (RequestSet) IsLoaded

func (r RequestSet) IsLoaded() bool

IsLoaded returns true if all non-zero requests in the set are in state loaded.

type RequestState

type RequestState int

RequestState is the state the request is in.

const (
	// Unresolved means the request is not yet resolved.
	Unresolved RequestState = iota
	// Fetch means the request needs to be fetched.
	Fetch
	// Cached means the request should be cached locally and can be loaded from
	// DB.
	Cached
	// Fetched means the request has been fetched and should be in the DB.
	Fetched
	// Loaded means the request has been loaded from the DB.
	Loaded
)

type Requester

type Requester interface {
	Request(ctx context.Context, req RequestSet) <-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) AllLoaded

func (r Requests) AllLoaded() bool

AllLoaded returns whether all entries in request have state loaded.

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 a request set. It returns the segments that are locally
	// stored and the set of requests that have to be requested at a remote server.
	Resolve(ctx context.Context, segs Segments, req RequestSet) (Segments, RequestSet, error)
}

Resolver resolves segments that are locally cached.

type Segments

type Segments struct {
	Up   seg.Segments
	Core seg.Segments
	Down seg.Segments
}

Segments is a set of up, core, and down segments.

func (*Segments) Add

func (s *Segments) Add(other Segments)

Add adds the other segments to the current segments.

type Splitter

type Splitter interface {
	// Split splits the request into a request set. Assumes that the request
	// has been validated for the local IA.
	Split(ctx context.Context, r Request) (RequestSet, error)
}

Splitter splits a single request into a request set.

type Validator

type Validator interface {
	// Validate should return an error if the given request is not valid.
	Validate(ctx context.Context, r Request) error
}

Validator validates a request.

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