pathmgr

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: 12 Imported by: 0

Documentation

Overview

Package pathmgr implements an asynchronous Path Resolver for SCION Paths.

A new resolver can be instantiated by calling `New`. There are two types of supported path queries, simple or periodic.

Simple path queries are issued via 'Query'; they return an spathmeta.AppPathSet of valid paths.

Periodic path queries are added via 'Watch', which returns a pointer to a thread-safe SyncPaths object; calling Load on the object returns the data associated with the watch, which includes the set of paths. When updating paths, the resolver will atomically change the value within the SyncPaths object. The data can be accessed by calling Load again.

An example of how this package can be used can be found in the associated infra test file.

Index

Constants

View Source
const (
	// DefaultNormalRefire is the wait time after a successful path lookup (for periodic lookups)
	DefaultNormalRefire = time.Minute
	// DefaultErorrRefire is the wait time after a failed path lookup (for periodic lookups)
	DefaultErrorRefire = time.Second
	// DefaultQueryTimeout is the time allocated for a query to SCIOND
	DefaultQueryTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

func StartPeriodic added in v0.4.0

func StartPeriodic(params PollingParameters, ch chan sciond.PathReqFlags) *periodic.Runner

Types

type DefaultPollingPolicy added in v0.4.0

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

func (*DefaultPollingPolicy) Destroy added in v0.4.0

func (pp *DefaultPollingPolicy) Destroy()

func (*DefaultPollingPolicy) PollC added in v0.4.0

func (pp *DefaultPollingPolicy) PollC() <-chan sciond.PathReqFlags

func (*DefaultPollingPolicy) PollNow added in v0.4.0

func (pp *DefaultPollingPolicy) PollNow()

func (*DefaultPollingPolicy) UpdateState added in v0.4.0

func (pp *DefaultPollingPolicy) UpdateState(availablePaths spathmeta.AppPathSet)

type Policy added in v0.4.0

type Policy interface {
	Filter(pathpol.PathSet) pathpol.PathSet
}

Policy is used to filter paths

type PollingParameters added in v0.4.0

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

type PollingPolicy added in v0.4.0

type PollingPolicy interface {
	// UpdateState reconfigures the polling policy based on availablePaths.
	UpdateState(availablePaths spathmeta.AppPathSet)
	// PollNow triggers a new query now, irrespective of other timers.
	PollNow()
	// PollC returns the channel that is written to whenever the policy
	// dictates a new poll. Ticks are dropped if the channel is full.
	PollC() <-chan sciond.PathReqFlags
	// Destroy shuts down any running goroutines.
	Destroy()
}

PollingPolicy describes how SCIOND should be polled, taking into account various aspects such as number of paths and the existence of a filtering policy. The PollingPolicy decides when SCIOND should be queried next, and which flags to be set.

func NewPollingPolicy added in v0.4.0

func NewPollingPolicy(haveFilter bool, timers Timers) PollingPolicy

type Querier added in v0.4.0

type Querier interface {
	// Query returns a set of paths between src and dst.
	Query(ctx context.Context, src, dst addr.IA, flags sciond.PathReqFlags) spathmeta.AppPathSet
}

type Resolver added in v0.4.0

type Resolver interface {
	Querier
	// QueryFilter returns a set of paths between src and dst that satisfy
	// policy. A nil policy will not delete any paths.
	QueryFilter(ctx context.Context, src, dst addr.IA, policy Policy) spathmeta.AppPathSet
	// Watch returns an object that periodically polls for paths between src
	// and dst.
	//
	// The function blocks until the first answer from SCIOND is received. The
	// amount of time is dictated by ctx. Note that the resolver might
	// asynchronously change the paths at any time. Calling Load on the
	// returned object returns a reference to a structure containing the
	// currently available paths.
	//
	// The asynchronous worker is not subject to ctx; thus, it has infinite
	// lifetime or until Destroy is called on the SyncPaths object.
	Watch(ctx context.Context, src, dst addr.IA) (*SyncPaths, error)
	// WatchFilter returns a pointer to a SyncPaths object that contains paths from
	// src to dst that adhere to the specified filter. On path changes the list is
	// refreshed automatically.
	//
	// A nil filter will not delete any paths.
	WatchFilter(ctx context.Context, src, dst addr.IA, filter Policy) (*SyncPaths, error)
	// WatchCount returns the number of active watchers.
	WatchCount() int
	// RevokeRaw informs SCIOND of a revocation.
	RevokeRaw(ctx context.Context, rawSRevInfo common.RawBytes)
	// Revoke informs SCIOND of a revocation.
	Revoke(ctx context.Context, sRevInfo *path_mgmt.SignedRevInfo)
	// Sciond returns a reference to the SCIOND connection.
	Sciond() sciond.Connector
}

func New

func New(conn sciond.Connector, timers Timers) Resolver

New creates a new path management context.

Parameter timers can be used to customize path manager behavior; if any timer is left uninitialized, it is assigned the corresponding default value (see package constants). When a query for a path older than maxAge reaches the resolver, SCIOND is used to refresh the path. New returns with an error if a connection to SCIOND could not be established.

type SyncPaths

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

SyncPaths contains a concurrency-safe reference to an spathmeta.AppPathSet that is continuously kept up to date by the path manager. Callers can safely `Load` the reference and use the paths within. At any moment, the path resolver can change the value of the reference within a SyncPaths to a different slice containing new paths. Calling code should reload the reference often to make sure the paths are fresh. Timestamp() can be called to get the time of the last write.

A SyncPaths must never be copied.

func NewSyncPaths

func NewSyncPaths() *SyncPaths

NewSyncPaths creates a new SyncPaths object and sets the timestamp to current time. A newly created SyncPaths contains a nil spathmeta.AppPathSet.

func (*SyncPaths) Destroy added in v0.4.0

func (sp *SyncPaths) Destroy()

func (*SyncPaths) Load

func (sp *SyncPaths) Load() *SyncPathsData

Load returns a SyncPathsData snapshot of the data within sp.

func (*SyncPaths) Update added in v0.4.0

func (sp *SyncPaths) Update(newAPS spathmeta.AppPathSet)

Update adds and removes paths in sp to match newAPS. If a path was added or removed, the modified timestamp is updated. The refresh timestamp is always updated. FIXME(scrye): Add SCIOND support s.t. the refresh timestamp is changed only when paths (including path metadata) change.

type SyncPathsData

type SyncPathsData struct {
	APS         spathmeta.AppPathSet
	ModifyTime  time.Time
	RefreshTime time.Time
}

SyncPathsData is the atomic value inside a SyncPaths object. It provides a snapshot of a SyncPaths object. Callers must not change APS.

type Timers

type Timers struct {
	// Wait time after a successful path lookup (for periodic lookups)
	NormalRefire time.Duration
	// Wait time after a failed (error or empty) path lookup (for periodic lookups)
	ErrorRefire time.Duration
}

Timers is used to customize the timers for a new Path Manager.

func (*Timers) GetWait added in v0.4.0

func (timers *Timers) GetWait(isError bool) time.Duration

type WatchFactory added in v0.4.0

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

WatchFactory creates and tracks path watches, i.e., path polling goroutines.

func NewWatchFactory added in v0.4.0

func NewWatchFactory(timers Timers) *WatchFactory

func (*WatchFactory) New added in v0.4.0

func (factory *WatchFactory) New(sp *SyncPaths, bq *queryConfig, pp PollingPolicy) *WatchReference

type WatchReference added in v0.4.0

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

WatchReference is a reference to an internal Watch managed by the PathManager. Call Run to start the goroutine associated with the watch, and call Destroy to stop it.

Calling Run after a reference has been destroyed will result in a no-op.

func (*WatchReference) Destroy added in v0.4.0

func (ref *WatchReference) Destroy()

func (*WatchReference) Run added in v0.4.0

func (ref *WatchReference) Run()

type WatchRunner added in v0.4.0

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

WatchRunner polls SCIOND in accordance to a polling policy, updating a concurrency-safe store of paths after every poll.

Call Stop to shut down the running goroutine. It is safe to call Stop multiple times from different goroutines.

func (*WatchRunner) Run added in v0.4.0

func (w *WatchRunner) Run()

func (*WatchRunner) Stop added in v0.4.0

func (w *WatchRunner) Stop()

Directories

Path Synopsis
Package mock_pathmgr is a generated GoMock package.
Package mock_pathmgr is a generated GoMock package.

Jump to

Keyboard shortcuts

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