beacon

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 27 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// DefaultBestSetSize is the default BestSetSize value.
	DefaultBestSetSize = 20
	// DefaultCandidateSetSize is the default CandidateSetSize value.
	DefaultCandidateSetSize = 100
	// DefaultMaxHopsLength is the default MaxHopsLength value.
	DefaultMaxHopsLength = 10
	// DefaultMaxExpTime is the default MaxExpTime value.
	DefaultMaxExpTime = uint8(63)
)
View Source
const DefaultGroup string = "default"

DefaultGroup defines the default beacon group. This means that if a policy does not define any registration policies, all the beacons should be put into this group.

This should also correspond to the ID of the default plugin.

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.

func PackBeacon

func PackBeacon(ps *seg.PathSegment) ([]byte, error)

PackBeacon packs a beacon.

func UnpackBeacon

func UnpackBeacon(raw []byte) (*seg.PathSegment, error)

UnpackBeacon unpacks a beacon.

Types

type Beacon

type Beacon struct {
	// Segment is the path segment.
	Segment *seg.PathSegment
	// InIfID is the interface the beacon is received on.
	InIfID uint16
}

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.

func (Beacon) String

func (b Beacon) String() string

type ChainProvider added in v0.12.0

type ChainProvider interface {
	GetChains(context.Context, trust.ChainQuery, ...trust.Option) ([][]*x509.Certificate, 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 to insert 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, opts ...StoreOption) (*CoreStore, error)

NewCoreBeaconStore creates a new beacon store for a core AS.

func (*CoreStore) BeaconsToPropagate

func (s *CoreStore) BeaconsToPropagate(ctx context.Context) ([]Beacon, error)

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

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) MaxExpTime

func (s *CoreStore) MaxExpTime(policyType PolicyType) uint8

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 seg.Type,
) ([]Beacon, []RegistrationPolicy, error)

SegmentsToRegister returns the beacons to register at the time of the call. The selection 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 {
	// CandidateBeacons returns up to `setSize` beacons that are allowed for the
	// given usage. The beacons in the slice are ordered by segment length from
	// shortest to longest.
	CandidateBeacons(
		ctx context.Context,
		setSize int,
		usage Usage,
		src addr.IA,
	) ([]Beacon, error)
	// BeaconSources returns all source ISD-AS of the beacons in the database.
	BeaconSources(ctx context.Context) ([]addr.IA, error)
	// InsertBeacon inserts a beacon with its allowed usage into the database.
	InsertBeacon(ctx context.Context, beacon Beacon, usage Usage) (InsertStats, error)
}

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

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 GroupedBeacons added in v0.14.0

type GroupedBeacons map[string][]Beacon

GroupedBeacons is a map where the key is the registration policy name and the value is a slice of beacons that should be handled by that registration policy.

type InsertStats

type InsertStats struct {
	Inserted, Updated, Filtered int
}

InsertStats provides statistics about an insertion.

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 *uint8 `yaml:"MaxExpTime"`
	// Filter is the filter applied to segments.
	Filter Filter `yaml:"Filter"`
	// Type is the policy type.
	Type PolicyType `yaml:"Type"`
	// RegistrationPolicies contains the registration policies for this policy.
	RegistrationPolicies []RegistrationPolicy `yaml:"RegistrationPolicies"`
}

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(r io.Reader, 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.

func (*Policy) Validate added in v0.14.0

func (p *Policy) Validate() error

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"
)

func (PolicyType) RegPolicyType added in v0.14.0

func (p PolicyType) RegPolicyType() (RegPolicyType, bool)

RegPolicyType converts a PolicyType to a RegPolicyType if it is a registration policy type. The second return value indicates whether the conversion was successful.

type RegPolicyType added in v0.14.0

type RegPolicyType string

RegPolicyType is the registration policy type, which is a subset of PolicyType.

const (
	// RegPolicyTypeUp is the registration policy type for up segments.
	RegPolicyTypeUp RegPolicyType = RegPolicyType(UpRegPolicy)
	// RegPolicyTypeDown is the registration policy type for down segments.
	RegPolicyTypeDown RegPolicyType = RegPolicyType(DownRegPolicy)
	// RegPolicyTypeCore is the registration policy type for core segments.
	RegPolicyTypeCore RegPolicyType = RegPolicyType(CoreRegPolicy)
)

func (RegPolicyType) PolicyType added in v0.14.0

func (p RegPolicyType) PolicyType() PolicyType

PolicyType converts a RegPolicyType to a generic PolicyType.

func (RegPolicyType) SegmentType added in v0.14.0

func (p RegPolicyType) SegmentType() segment.Type

SegmentType returns the segment type associated with this registration policy.

type RegistrationPolicy added in v0.14.0

type RegistrationPolicy struct {
	Name         string                    `yaml:"Name"`
	Description  string                    `yaml:"Description"`
	Matcher      RegistrationPolicyMatcher `yaml:"Matcher"`
	Plugin       string                    `yaml:"Plugin"`
	PluginConfig map[string]any            `yaml:"PluginConfig"`
}

RegistrationPolicy contains the parameters for a registration policy. A registration policy is used to register segments with a registrar.

func (*RegistrationPolicy) InitDefaults added in v0.14.0

func (p *RegistrationPolicy) InitDefaults()

InitDefaults initializes the default values for unset fields in the registration policy.

func (*RegistrationPolicy) Validate added in v0.14.0

func (p *RegistrationPolicy) Validate() error

type RegistrationPolicyMatcher added in v0.14.0

type RegistrationPolicyMatcher struct {
	Sequence *pathpol.Sequence `yaml:"Sequence"`
	ACL      *pathpol.ACL      `yaml:"ACL"`
}

RegistrationPolicyMatcher contains the matching criteria for a registration policy. A matcher is valid only if at least one of Sequence and ACL fields are set.

func (*RegistrationPolicyMatcher) Match added in v0.14.0

func (m *RegistrationPolicyMatcher) Match(beacon Beacon) bool

Match returns true iff the given beacon matches the registration policy matcher. Note that an empty matcher is invalid, and it always returns false.

type SelectionAlgorithm added in v0.15.0

type SelectionAlgorithm interface {
	// SelectBeacons selects the `resultSize` best beacons from the provided slice of beacons.
	SelectBeacons(ctx context.Context, beacons []Beacon, resultSize int) []Beacon
}

func DefaultSelectionAlgorithm added in v0.15.0

func DefaultSelectionAlgorithm() SelectionAlgorithm

DefaultSelectionAlgorithm implements a very simple selection algorithm that optimizes for short paths, but also tries to achieve minimal path diversity.

func NewChainsAvailableAlgo added in v0.15.0

func NewChainsAvailableAlgo(engine ChainProvider, selector SelectionAlgorithm) SelectionAlgorithm

NewChainsAvailableAlgo creates a SelectionAlgorithm that filters beacons based on the availability of their verification chains before passing them to the provided selector. This can be paired with a chain provider that only returns locally available chains to ensure that beacons are verifiable with cryptographic material available in the local trust store.

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 to insert 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, opts ...StoreOption) (*Store, error)

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

func (*Store) BeaconsToPropagate

func (s *Store) BeaconsToPropagate(ctx context.Context) ([]Beacon, error)

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

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) MaxExpTime

func (s *Store) MaxExpTime(policyType PolicyType) uint8

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 seg.Type,
) ([]Beacon, []RegistrationPolicy, error)

SegmentsToRegister returns all beacons to register at the time of the call. The selections are 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 StoreOption added in v0.12.0

type StoreOption interface {
	// contains filtered or unexported methods
}

func WithSelectionAlgorithm added in v0.15.0

func WithSelectionAlgorithm(algo SelectionAlgorithm) StoreOption

WithSelectionAlgorithm sets the selection algorithm used to select the best beacons according to the configured policies.

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 are 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