beacon

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

Documentation

Index

Constants

View Source
const (
	// ErrReadingRows is the error message in case we fail to read more from
	// the database.
	ErrReadingRows common.ErrMsg = "Failed to read rows"
	// ErrParse is the error message in case the parsing a db entry fails.
	ErrParse common.ErrMsg = "Failed to parse entry"
)
View Source
const (
	// DefaultBestSetSize is the default BestSetSize value.
	DefaultBestSetSize = 5
	// DefaultCandidateSetSize is the default CandidateSetSize value.
	DefaultCandidateSetSize = 100
	// DefaultMaxHopsLength is the default MaxHopsLength value.
	DefaultMaxHopsLength = 10
	// DefaultMaxExpTime is the default MaxExpTime value.
	DefaultMaxExpTime = spath.DefaultHopFExpiry
)

Variables

This section is empty.

Functions

func FilterLoop

func FilterLoop(beacon Beacon, next addr.IA, allowIsdLoop bool) error

FilterLoop returns an error if the beacon contains an AS or ISD loop. If ISD loops are allowed, an error is returned only on AS loops.

Types

type Beacon

type Beacon struct {
	// Segment is the path segment.
	Segment *seg.PathSegment
	// InIfId is the interface the beacon is received on.
	InIfId common.IFIDType
}

Beacon consists of the path segment and the interface it was received on.

func (Beacon) Diversity

func (b Beacon) Diversity(other Beacon) int

Diversity returns the link diversity between this and the other beacon. The link diversity indicates the number of links in this beacon that do not appear in the other beacon. If the other beacon has no segment set, 0 is returned. Note: Diversity is asymmetric.

type BeaconOrErr

type BeaconOrErr struct {
	Beacon Beacon
	Err    error
}

BeaconOrErr contains a read-only beacon or an error.

type CorePolicies

type CorePolicies struct {
	// Prop is the propagation policy.
	Prop Policy
	// CoreReg is the core segment policy.
	CoreReg Policy
}

CorePolicies keeps track of all policies for a core beacon store.

func (*CorePolicies) Filter

func (p *CorePolicies) Filter(beacon Beacon) error

Filter applies all filters and returns an error if all of them filter the beacon. If at least one does not filter, no error is returned.

func (*CorePolicies) InitDefaults

func (p *CorePolicies) InitDefaults()

InitDefaults sets the defaults for all policies.

func (*CorePolicies) Usage

func (p *CorePolicies) Usage(beacon Beacon) Usage

Usage returns the allowed usage of the beacon based on all available policies. For missing policies, the usage is not permitted.

func (*CorePolicies) Validate

func (p *CorePolicies) Validate() error

Validate checks that each policy is of the correct type.

type CoreStore

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

CoreStore provides abstracted access to the beacon database in a core AS. The store helps inserting beacons and revocations, and selects the best beacons for given purposes based on the configured policies. It should not be used in a non-core AS.

func NewCoreBeaconStore

func NewCoreBeaconStore(policies CorePolicies, db DB) (*CoreStore, error)

NewCoreBeaconStore creates a new beacon store for a non-core AS.

func (*CoreStore) BeaconsToPropagate

func (s *CoreStore) BeaconsToPropagate(ctx context.Context) (<-chan BeaconOrErr, error)

BeaconsToPropagate returns a channel that provides all beacons to propagate at the time of the call. The selection is based on the configured propagation policy.

func (*CoreStore) Close

func (s *CoreStore) Close() error

Close closes the store and the underlying database connection.

func (*CoreStore) DeleteExpiredBeacons

func (s *CoreStore) DeleteExpiredBeacons(ctx context.Context) (int, error)

DeleteExpiredBeacons deletes expired Beacons from the store.

func (*CoreStore) DeleteExpiredRevocations

func (s *CoreStore) DeleteExpiredRevocations(ctx context.Context) (int, error)

DeleteExpiredRevocations deletes expired Revocations from the store.

func (*CoreStore) DeleteRevocation

func (s *CoreStore) DeleteRevocation(ctx context.Context, ia addr.IA, ifid common.IFIDType) error

DeleteRevocation deletes the revocation from the BeaconDB.

func (*CoreStore) InsertBeacon

func (s *CoreStore) InsertBeacon(ctx context.Context, beacon Beacon) (InsertStats, error)

InsertBeacon adds a verified beacon to the store. Beacon that contains revoked interfaces is inserted and does not cause an error. If the beacon does not match any policy, it is not inserted, but does not cause an error.

func (*CoreStore) InsertRevocations

func (s *CoreStore) InsertRevocations(ctx context.Context,
	revocations ...*path_mgmt.SignedRevInfo) error

InsertRevocations inserts the revocation into the BeaconDB. The provided revocation must be verified by the caller.

func (*CoreStore) MaxExpTime

func (s *CoreStore) MaxExpTime(policyType PolicyType) spath.ExpTimeType

MaxExpTime returns the segment maximum expiration time for the given policy.

func (*CoreStore) PreFilter

func (s *CoreStore) PreFilter(beacon Beacon) error

PreFilter indicates whether the beacon will be filtered on insert by returning an error with the reason. This allows the caller to drop ignored beacons.

func (*CoreStore) SegmentsToRegister

func (s *CoreStore) SegmentsToRegister(ctx context.Context, segType proto.PathSegType) (
	<-chan BeaconOrErr, error)

SegmentsToRegister returns a channel that provides all beacons to register at the time of the call. The selections is based on the configured policy for the requested segment type.

func (*CoreStore) UpdatePolicy

func (s *CoreStore) UpdatePolicy(ctx context.Context, policy Policy) error

UpdatePolicy updates the policy. Beacons that are filtered by all policies after the update are removed.

type DB

type DB interface {
	DBReadWrite
	BeginTransaction(ctx context.Context, opts *sql.TxOptions) (Transaction, error)
	db.LimitSetter
	io.Closer
}

DB defines the interface that all beacon DB backends have to implement.

type DBRead

type DBRead interface {
	// CandidateBeacons returns up to setSize beacons that are allowed for the
	// given usage. The result channel either carries beacons or errors. The
	// beacons in the channel are ordered by segment length from shortest to
	// longest. The channel must be drained, since the db might spawn go routines
	// to fill the channel.
	CandidateBeacons(ctx context.Context, setSize int, usage Usage, src addr.IA) (
		<-chan BeaconOrErr, error)
	// BeaconSources returns all source ISD-AS of the beacons in the database.
	BeaconSources(ctx context.Context) ([]addr.IA, error)
	// AllRevocations returns all revocations in the database as a channel. The
	// result channel either carries revocations or errors. The error can
	// either be ErrReadingRows or ErrParse. After a ErrReadingRows occurs the
	// channel is closed and the result might be incomplete. The channel must
	// be drained, since the implementation might spawn go routines to fill the
	// channel.
	AllRevocations(ctx context.Context) (<-chan RevocationOrErr, error)
}

DBRead defines all read operations of the beacon DB.

type DBReadWrite

type DBReadWrite interface {
	DBRead
	DBWrite
}

DBReadWrite defines all read an write operations of the beacon DB.

type DBWrite

type DBWrite interface {
	InsertBeacon(ctx context.Context, beacon Beacon, usage Usage) (InsertStats, error)
	DeleteExpiredBeacons(ctx context.Context, now time.Time) (int, error)
	DeleteRevokedBeacons(ctx context.Context, now time.Time) (int, error)
	InsertRevocation(ctx context.Context, revocation *path_mgmt.SignedRevInfo) error
	DeleteRevocation(ctx context.Context, ia addr.IA, ifid common.IFIDType) error
	DeleteExpiredRevocations(ctx context.Context, now time.Time) (int, error)
}

DBWrite defines all write operations of the beacon DB.

type Filter

type Filter struct {
	// MaxHopsLength is the maximum number of hops a segment can have.
	MaxHopsLength int `yaml:"MaxHopsLength"`
	// ASBlackList contains all ASes that may not appear in a segment.
	AsBlackList []addr.AS `yaml:"AsBlackList"`
	// IsdBlackList contains all ISD that may not appear in a segment.
	IsdBlackList []addr.ISD `yaml:"IsdBlackList"`
	// AllowIsdLoop indicates whether ISD loops should not be filtered.
	AllowIsdLoop *bool `yaml:"AllowIsdLoop"`
}

Filter filters beacons.

func (Filter) Apply

func (f Filter) Apply(beacon Beacon) error

Apply returns an error if the beacon is filtered.

func (*Filter) InitDefaults

func (f *Filter) InitDefaults()

InitDefaults initializes the default values for unset fields.

type HPGroup

type HPGroup struct {
	GroupCfgPath string `yaml:"CfgFilePath"`
	Group        hiddenpath.Group
}

HPGroup holds a hidden path group

type HPPolicies

type HPPolicies struct {
	DefaultAction   string                       `yaml:"DefaultAction"`
	HiddenAndPublic bool                         `yaml:"HiddenAndPublic"`
	Policies        map[common.IFIDType]HPPolicy `yaml:"Policies"`
}

HPPolicies holds all the hidden path registration policies for a BS

type HPPolicy

type HPPolicy struct {
	Public RegPolicy                        `yaml:"PS"`
	Hidden map[hiddenpath.GroupId]RegPolicy `yaml:"HPS"`
}

HPPolicy holds the public and hidden registration policies for an interface

type HPRegistration

type HPRegistration struct {
	HPPolicies HPPolicies                      `yaml:"SegmentRegistration"`
	HPGroups   map[hiddenpath.GroupId]*HPGroup `yaml:"HPGroups"`
}

HPRegistration holds all the information required for hidden path segment registrations

func LoadHPRegFromYaml

func LoadHPRegFromYaml(path string) (*HPRegistration, error)

LoadHPRegFromYaml loads the HPRegistration from a yaml file and performs validation. Hidden path groups pointed to by config file paths are loaded.

func ParseHPRegYaml

func ParseHPRegYaml(b common.RawBytes) (*HPRegistration, error)

ParseHPRegYaml parses the registration policies in yaml format and performs validation. Hidden path groups pointed to by config file paths are loaded.

func (*HPRegistration) Validate

func (hp *HPRegistration) Validate() error

Validate verifies that for all hidden path policies the referenced Group exists and checks if all GroupId keys match the initialized HPGroup

type InsertStats

type InsertStats struct {
	Inserted, Updated, Filtered int
}

InsertStats provides statistics about an insertion.

type MetricsDB

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

MetricsDB is a wrapper around the beacon db that exports metrics.

func DBWithMetrics

func DBWithMetrics(dbName string, db DB) *MetricsDB

DBWithMetrics wraps the given db into a db that exports metrics.

func (MetricsDB) AllRevocations

func (e MetricsDB) AllRevocations(ctx context.Context) (<-chan RevocationOrErr, error)

func (MetricsDB) BeaconSources

func (e MetricsDB) BeaconSources(ctx context.Context) ([]addr.IA, error)

func (*MetricsDB) BeginTransaction

func (db *MetricsDB) BeginTransaction(ctx context.Context,
	opts *sql.TxOptions) (Transaction, error)

func (MetricsDB) CandidateBeacons

func (e MetricsDB) CandidateBeacons(ctx context.Context, setSize int, usage Usage,
	src addr.IA) (<-chan BeaconOrErr, error)

func (*MetricsDB) Close

func (db *MetricsDB) Close() error

func (MetricsDB) DeleteExpiredBeacons

func (e MetricsDB) DeleteExpiredBeacons(ctx context.Context, now time.Time) (int, error)

func (MetricsDB) DeleteExpiredRevocations

func (e MetricsDB) DeleteExpiredRevocations(ctx context.Context, now time.Time) (int, error)

func (MetricsDB) DeleteRevocation

func (e MetricsDB) DeleteRevocation(ctx context.Context, ia addr.IA, ifid common.IFIDType) error

func (MetricsDB) DeleteRevokedBeacons

func (e MetricsDB) DeleteRevokedBeacons(ctx context.Context, now time.Time) (int, error)

func (MetricsDB) InsertBeacon

func (e MetricsDB) InsertBeacon(ctx context.Context, beacon Beacon,
	usage Usage) (InsertStats, error)

func (MetricsDB) InsertRevocation

func (e MetricsDB) InsertRevocation(ctx context.Context,
	revocation *path_mgmt.SignedRevInfo) error

func (*MetricsDB) SetMaxIdleConns

func (db *MetricsDB) SetMaxIdleConns(maxIdleConns int)

func (*MetricsDB) SetMaxOpenConns

func (db *MetricsDB) SetMaxOpenConns(maxOpenConns int)

type MetricsTransaction

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

MetricsTransaction is a wrapper around a beacon db transaction that exports metrics.

func (MetricsTransaction) AllRevocations

func (e MetricsTransaction) AllRevocations(ctx context.Context) (<-chan RevocationOrErr, error)

func (MetricsTransaction) BeaconSources

func (e MetricsTransaction) BeaconSources(ctx context.Context) ([]addr.IA, error)

func (MetricsTransaction) CandidateBeacons

func (e MetricsTransaction) CandidateBeacons(ctx context.Context, setSize int, usage Usage,
	src addr.IA) (<-chan BeaconOrErr, error)

func (*MetricsTransaction) Commit

func (tx *MetricsTransaction) Commit() error

func (MetricsTransaction) DeleteExpiredBeacons

func (e MetricsTransaction) DeleteExpiredBeacons(ctx context.Context, now time.Time) (int, error)

func (MetricsTransaction) DeleteExpiredRevocations

func (e MetricsTransaction) DeleteExpiredRevocations(ctx context.Context, now time.Time) (int, error)

func (MetricsTransaction) DeleteRevocation

func (e MetricsTransaction) DeleteRevocation(ctx context.Context, ia addr.IA, ifid common.IFIDType) error

func (MetricsTransaction) DeleteRevokedBeacons

func (e MetricsTransaction) DeleteRevokedBeacons(ctx context.Context, now time.Time) (int, error)

func (MetricsTransaction) InsertBeacon

func (e MetricsTransaction) InsertBeacon(ctx context.Context, beacon Beacon,
	usage Usage) (InsertStats, error)

func (MetricsTransaction) InsertRevocation

func (e MetricsTransaction) InsertRevocation(ctx context.Context,
	revocation *path_mgmt.SignedRevInfo) error

func (*MetricsTransaction) Rollback

func (tx *MetricsTransaction) Rollback() error

type Policies

type Policies struct {
	// Prop is the propagation policy.
	Prop Policy
	// UpReg is the up segment policy.
	UpReg Policy
	// DownReg is the down segment policy.
	DownReg Policy
}

Policies keeps track of all policies for a non-core beacon store.

func (*Policies) Filter

func (p *Policies) Filter(beacon Beacon) error

Filter applies all filters and returns an error if all of them filter the beacon. If at least one does not filter, no error is returned.

func (*Policies) InitDefaults

func (p *Policies) InitDefaults()

InitDefaults sets the defaults for all policies.

func (*Policies) Usage

func (p *Policies) Usage(beacon Beacon) Usage

Usage returns the allowed usage of the beacon based on all available policies. For missing policies, the usage is not permitted.

func (*Policies) Validate

func (p *Policies) Validate() error

Validate checks that each policy is of the correct type.

type Policy

type Policy struct {
	// BestSetSize is the number of segments to propagate or register.
	BestSetSize int `yaml:"BestSetSize"`
	// CandidateSetSize is the number of segments to consider for
	// selection.
	CandidateSetSize int `yaml:"CandidateSetSize"`
	// MaxExpTime indicates the maximum value for the expiration time when
	// extending the segment.
	MaxExpTime *spath.ExpTimeType `yaml:"MaxExpTime"`
	// Filter is the filter applied to segments.
	Filter Filter `yaml:"Filter"`
	// Type is the policy type.
	Type PolicyType `yaml:"Type"`
}

Policy contains the policy parameters when handling beacons.

func LoadPolicyFromYaml

func LoadPolicyFromYaml(path string, t PolicyType) (*Policy, error)

LoadPolicyFromYaml loads the policy from a yaml file and initializes the default values.

func ParsePolicyYaml

func ParsePolicyYaml(b common.RawBytes, t PolicyType) (*Policy, error)

ParsePolicyYaml parses the policy in yaml format and initializes the default values.

func (*Policy) InitDefaults

func (p *Policy) InitDefaults()

InitDefaults initializes the default values for unset fields.

type PolicyType

type PolicyType string

PolicyType is the policy type.

const (
	// PropPolicy is the propagation policy.
	PropPolicy PolicyType = "Propagation"
	// UpRegPolicy is the registration policy for up segments.
	UpRegPolicy PolicyType = "UpSegmentRegistration"
	// DownRegPolicy is the registration policy for down segments.
	DownRegPolicy PolicyType = "DownSegmentRegistration"
	// CoreRegPolicy is the registration policy for core segments.
	CoreRegPolicy PolicyType = "CoreSegmentRegistration"
)

type RegPolicy

type RegPolicy struct {
	RegUp         bool         `yaml:"RegUp"`
	RegDown       bool         `yaml:"RegDown"`
	MaxExpiration util.DurWrap `yaml:"MaxExpiration"`
}

RegPolicy holds a segmentregistration policy

type RevocationOrErr

type RevocationOrErr struct {
	Rev *path_mgmt.SignedRevInfo
	Err error
}

RevocationOrErr contains a signed revocation or an error.

type Store

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

Store provides abstracted access to the beacon database in a non-core AS. The store helps inserting beacons and revocations, and selects the best beacons for given purposes based on the configured policies. It should not be used in a core AS.

func NewBeaconStore

func NewBeaconStore(policies Policies, db DB) (*Store, error)

NewBeaconStore creates a new beacon store for a non-core AS.

func (*Store) BeaconsToPropagate

func (s *Store) BeaconsToPropagate(ctx context.Context) (<-chan BeaconOrErr, error)

BeaconsToPropagate returns a channel that provides all beacons to propagate at the time of the call. The selection is based on the configured propagation policy.

func (*Store) Close

func (s *Store) Close() error

Close closes the store and the underlying database connection.

func (*Store) DeleteExpiredBeacons

func (s *Store) DeleteExpiredBeacons(ctx context.Context) (int, error)

DeleteExpiredBeacons deletes expired Beacons from the store.

func (*Store) DeleteExpiredRevocations

func (s *Store) DeleteExpiredRevocations(ctx context.Context) (int, error)

DeleteExpiredRevocations deletes expired Revocations from the store.

func (*Store) DeleteRevocation

func (s *Store) DeleteRevocation(ctx context.Context, ia addr.IA, ifid common.IFIDType) error

DeleteRevocation deletes the revocation from the BeaconDB.

func (*Store) InsertBeacon

func (s *Store) InsertBeacon(ctx context.Context, beacon Beacon) (InsertStats, error)

InsertBeacon adds a verified beacon to the store. Beacon that contains revoked interfaces is inserted and does not cause an error. If the beacon does not match any policy, it is not inserted, but does not cause an error.

func (*Store) InsertRevocations

func (s *Store) InsertRevocations(ctx context.Context,
	revocations ...*path_mgmt.SignedRevInfo) error

InsertRevocations inserts the revocation into the BeaconDB. The provided revocation must be verified by the caller.

func (*Store) MaxExpTime

func (s *Store) MaxExpTime(policyType PolicyType) spath.ExpTimeType

MaxExpTime returns the segment maximum expiration time for the given policy.

func (*Store) PreFilter

func (s *Store) PreFilter(beacon Beacon) error

PreFilter indicates whether the beacon will be filtered on insert by returning an error with the reason. This allows the caller to drop ignored beacons.

func (*Store) SegmentsToRegister

func (s *Store) SegmentsToRegister(ctx context.Context, segType proto.PathSegType) (
	<-chan BeaconOrErr, error)

SegmentsToRegister returns a channel that provides all beacons to register at the time of the call. The selections is based on the configured policy for the requested segment type.

func (*Store) UpdatePolicy

func (s *Store) UpdatePolicy(ctx context.Context, policy Policy) error

UpdatePolicy updates the policy. Beacons that are filtered by all policies after the update are removed.

type Transaction

type Transaction interface {
	DBReadWrite
	Commit() error
	Rollback() error
}

Transaction defines all operations of a transaction on the beacon DB.

type Usage

type Usage int

Usage indicates what the beacon is allowed to be used for according to the policies.

const (
	// UsageUpReg indicates the beacon is allowed to be registered as an up segment.
	UsageUpReg Usage = 0x01
	// UsageDownReg indicates the beacon is allowed to be registered as a down segment.
	UsageDownReg Usage = 0x02
	// UsageCoreReg indicates the beacon is allowed to be registered as a core segment.
	UsageCoreReg Usage = 0x04
	// UsageProp indicates the beacon is allowed to be propagated.
	UsageProp Usage = 0x08
)

func UsageFromPolicyType

func UsageFromPolicyType(policyType PolicyType) Usage

UsageFromPolicyType maps the policy type to the usage flag.

func (Usage) None

func (u Usage) None() bool

None indicates whether the beacons is not allowed to be used anywhere.

func (Usage) String

func (u Usage) String() string

Directories

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

Jump to

Keyboard shortcuts

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