pathpol

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

Documentation

Overview

Package pathpol implements path policies, documentation in doc/PathPolicy.md Currently implemented: ACL, Sequence, Extends and Options.

A policy has Filter() method that takes a slice of paths and returns a filtered slice of paths.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoDefault indicates that there is no default acl entry.
	ErrNoDefault = errors.New("ACL does not have a default")
)

Functions

This section is empty.

Types

type ACL

type ACL struct {
	Entries []*ACLEntry
}

func NewACL

func NewACL(entries ...*ACLEntry) (*ACL, error)

NewACL creates a new entry and checks for the presence of a default action

func (*ACL) Eval

func (a *ACL) Eval(paths []snet.Path) []snet.Path

Eval returns the set of paths that match the ACL.

func (*ACL) MarshalJSON

func (a *ACL) MarshalJSON() ([]byte, error)

func (*ACL) UnmarshalJSON

func (a *ACL) UnmarshalJSON(b []byte) error

type ACLAction

type ACLAction bool

ACLAction has two options: Deny and Allow

const (
	Deny  ACLAction = false
	Allow ACLAction = true
)

type ACLEntry

type ACLEntry struct {
	Action ACLAction
	Rule   *HopPredicate
}

func (*ACLEntry) LoadFromString

func (ae *ACLEntry) LoadFromString(str string) error

func (*ACLEntry) MarshalJSON

func (ae *ACLEntry) MarshalJSON() ([]byte, error)

func (*ACLEntry) String

func (ae *ACLEntry) String() string

func (*ACLEntry) UnmarshalJSON

func (ae *ACLEntry) UnmarshalJSON(b []byte) error

type ExtPolicy

type ExtPolicy struct {
	Extends []string `json:"extends,omitempty"`
	*Policy
}

ExtPolicy is an extending policy, it may have a list of policies it extends

type FilterOptions

type FilterOptions struct {
	// IgnoreSequence can be used to ignore the sequence part of policies.
	IgnoreSequence bool
}

FilterOptions contains options for filtering.

type HopPredicate

type HopPredicate struct {
	ISD   addr.ISD
	AS    addr.AS
	IfIDs []common.IFIDType
}

A HopPredicate specifies a hop in the ACL or Sequence of the path policy, see docs/PathPolicy.md.

func HopPredicateFromString

func HopPredicateFromString(str string) (*HopPredicate, error)

func NewHopPredicate

func NewHopPredicate() *HopPredicate

func (*HopPredicate) MarshalJSON

func (hp *HopPredicate) MarshalJSON() ([]byte, error)

func (HopPredicate) String

func (hp HopPredicate) String() string

func (*HopPredicate) UnmarshalJSON

func (hp *HopPredicate) UnmarshalJSON(b []byte) error

type Option

type Option struct {
	Weight int        `json:"weight"`
	Policy *ExtPolicy `json:"policy"`
}

Option contains a weight and a policy and is used as a list item in Policy.Options

type Policy

type Policy struct {
	Name     string    `json:"-"`
	ACL      *ACL      `json:"acl,omitempty"`
	Sequence *Sequence `json:"sequence,omitempty"`
	Options  []Option  `json:"options,omitempty"`
}

Policy is a compiled path policy object, all extended policies have been merged.

func NewPolicy

func NewPolicy(name string, acl *ACL, sequence *Sequence, options []Option) *Policy

NewPolicy creates a Policy and sorts its Options

func PolicyFromExtPolicy

func PolicyFromExtPolicy(extPolicy *ExtPolicy, extended []*ExtPolicy) (*Policy, error)

PolicyFromExtPolicy creates a Policy from an extending Policy and the extended policies

func (*Policy) Filter

func (p *Policy) Filter(paths []snet.Path) []snet.Path

Filter filters the paths according to the policy.

func (*Policy) FilterOpt

func (p *Policy) FilterOpt(paths []snet.Path, opts FilterOptions) []snet.Path

FilterOpt filters the path set according to the policy with the given options.

type PolicyMap

type PolicyMap map[string]*ExtPolicy

PolicyMap is a container for Policies, keyed by their unique name. PolicyMap can be used to marshal Policies to JSON. Unmarshaling back to PolicyMap is guaranteed to yield an object that is identical to the initial one.

type Sequence

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

func NewSequence

func NewSequence(s string) (*Sequence, error)

NewSequence creates a new sequence from a string

func (*Sequence) Eval

func (s *Sequence) Eval(paths []snet.Path) []snet.Path

Eval evaluates the interface sequence list and returns the set of paths that match the list

func (*Sequence) MarshalJSON

func (s *Sequence) MarshalJSON() ([]byte, error)

func (*Sequence) String added in v0.5.0

func (s *Sequence) String() string

func (*Sequence) UnmarshalJSON

func (s *Sequence) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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