fact

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2020 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const SignedGroupMaxSafeInnerLength = UDPMaxSafePayload - sgvFactOverhead - sgvOverhead

SignedGroupMaxSafeInnerLength is the maximum safe length for `InnerBytes` above which fragmentation or packet drops may happen. This is computed based on the max safe UDP payload for IPv6, minus the fact & crypto overheads.

View Source
const UDPMaxSafePayload = 1212

UDPMaxSafePayload is the maximum payload size of a UDP packet we can safely send. we only need to worry about IPv6 for this

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute byte

Attribute is a byte identifying what aspect of a Subject a Fact describes

const (
	AttributeUnknown       Attribute = 0
	AttributeAlive         Attribute = '!'
	AttributeEndpointV4    Attribute = 'e'
	AttributeEndpointV6    Attribute = 'E'
	AttributeAllowedCidrV4 Attribute = 'a'
	AttributeAllowedCidrV6 Attribute = 'A'
	// A signed group is a bit different from other facts
	// in this case, the subject is actually the source,
	// and the value is a signed aggregate of other facts.
	AttributeSignedGroup Attribute = 'S'
)

fact types, denoted as attributes of a subject

type EmptyValue deprecated

type EmptyValue struct{}

EmptyValue is used to represent facts of AttributeUnknown with a zero length value, which indicate just that a remote peer is alive and talking to us

Deprecated: prior uses of this should often use UUIDValue instead

func (EmptyValue) DecodeFrom added in v0.6.0

func (v EmptyValue) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

func (EmptyValue) MarshalBinary added in v0.6.0

func (v EmptyValue) MarshalBinary() ([]byte, error)

MarshalBinary always returns an empty slice for EmptyValue

func (EmptyValue) String

func (v EmptyValue) String() string

type Fact

type Fact struct {
	encoding.BinaryMarshaler
	util.Decodable

	Attribute Attribute
	Expires   time.Time
	Subject   Subject
	Value     Value
}

Fact represents a single piece of information about a subject, with an associated expiration time

func MergeList

func MergeList(facts []*Fact) []*Fact

MergeList merges duplicate facts in a slice, keeping the latest Expires value

func SortedCopy

func SortedCopy(facts []*Fact) []*Fact

SortedCopy makes a copy of the list and then sorts it "naturally"

func (*Fact) DecodeFrom added in v0.6.0

func (f *Fact) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

func (*Fact) FancyString added in v0.3.0

func (f *Fact) FancyString(subjectFormatter func(s Subject) string) string

FancyString formats the fact as a string using a custom helper to format the subject, most commonly to replace peer keys with names

func (*Fact) MarshalBinary added in v0.6.0

func (f *Fact) MarshalBinary() ([]byte, error)

MarshalBinary serializes a Fact to its on-wire format

func (*Fact) String

func (f *Fact) String() string

type GroupAccumulator added in v0.2.0

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

GroupAccumulator is a helper to aggregate individual facts into (signed) groups of a max size

func NewAccumulator added in v0.2.0

func NewAccumulator(maxGroupLen int) *GroupAccumulator

NewAccumulator initializes a new GroupAccumulator with a given max inner size per group.

func (*GroupAccumulator) AddFact added in v0.2.0

func (ga *GroupAccumulator) AddFact(f *Fact) error

AddFact appends the given fact into the accumulator

func (*GroupAccumulator) AddFactIfRoom added in v0.2.1

func (ga *GroupAccumulator) AddFactIfRoom(f *Fact) (added bool, err error)

AddFactIfRoom conditionally adds the fact if and only if it won't result in creating a new group

func (*GroupAccumulator) MakeSignedGroups added in v0.2.0

func (ga *GroupAccumulator) MakeSignedGroups(
	s *signing.Signer,
	recipient *wgtypes.Key,
) ([]Fact, error)

MakeSignedGroups converts all the accumulated facts into SignedGroups of no more than the specified max inner size.

type IPNetValue

type IPNetValue struct {
	net.IPNet
}

IPNetValue represents some IP+Mask as an Attribute of a Subject

func (*IPNetValue) DecodeFrom added in v0.6.0

func (ipn *IPNetValue) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

func (IPNetValue) MarshalBinary added in v0.6.0

func (ipn IPNetValue) MarshalBinary() ([]byte, error)

MarshalBinary gives the binary representation of the ip and cidr prefix

func (*IPNetValue) UnmarshalBinary added in v0.6.0

func (ipn *IPNetValue) UnmarshalBinary(data []byte) error

UnmarshalBinary implements BinaryUnmarshaler

type IPPortValue

type IPPortValue struct {
	IP   net.IP
	Port int
}

IPPortValue represents an IP:port pair as an Attribute of a Subject

func (*IPPortValue) DecodeFrom added in v0.6.0

func (ipp *IPPortValue) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

func (*IPPortValue) MarshalBinary added in v0.6.0

func (ipp *IPPortValue) MarshalBinary() ([]byte, error)

MarshalBinary returns the normalized binary representation

func (*IPPortValue) String

func (ipp *IPPortValue) String() string

func (*IPPortValue) UnmarshalBinary added in v0.6.0

func (ipp *IPPortValue) UnmarshalBinary(data []byte) error

UnmarshalBinary implements BinaryUnmarshaler

type Key

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

Key is a comparable version of the subject, attribute, and value of a Fact

func KeyOf

func KeyOf(fact *Fact) Key

KeyOf returns the FactKey for a Fact

type PeerSubject

type PeerSubject struct {
	wgtypes.Key
}

PeerSubject is a subject that is a peer identified via its public key

func (*PeerSubject) DecodeFrom added in v0.6.0

func (s *PeerSubject) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

func (*PeerSubject) MarshalBinary added in v0.6.0

func (s *PeerSubject) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler

func (*PeerSubject) UnmarshalBinary added in v0.6.0

func (s *PeerSubject) UnmarshalBinary(data []byte) error

UnmarshalBinary implements BinaryUnmarshaler

type SignedGroupValue added in v0.2.0

type SignedGroupValue struct {
	Nonce      [chacha20poly1305.NonceSizeX]byte
	Tag        [poly1305.TagSize]byte
	InnerBytes []byte
}

SignedGroupValue represents a signed chunk of other fact data. Note that this structure does _not_ include parsing those inner bytes!

func (*SignedGroupValue) DecodeFrom added in v0.6.0

func (sgv *SignedGroupValue) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

func (*SignedGroupValue) MarshalBinary added in v0.6.0

func (sgv *SignedGroupValue) MarshalBinary() ([]byte, error)

MarshalBinary gives the on-wire form of the value

func (*SignedGroupValue) ParseInner added in v0.2.0

func (sgv *SignedGroupValue) ParseInner() (ret []*Fact, err error)

ParseInner parses the inner bytes of a SignedGroupValue into facts. Validating the signature must be done separately, and should be done before calling this method.

func (*SignedGroupValue) String added in v0.2.0

func (sgv *SignedGroupValue) String() string

type Subject

type Subject interface {
	fmt.Stringer
	encoding.BinaryMarshaler
	util.Decodable
}

Subject is the subject of a Fact

type UUIDValue added in v0.4.0

type UUIDValue struct {
	uuid.UUID
}

UUIDValue represents a UUID, often used as a random marker or tag

func (*UUIDValue) DecodeFrom added in v0.6.0

func (u *UUIDValue) DecodeFrom(lengthHint int, reader io.Reader) error

DecodeFrom implements Decodable

type Value

type Value interface {
	fmt.Stringer
	encoding.BinaryMarshaler
	util.Decodable
}

Value represents the value of a Fact

Jump to

Keyboard shortcuts

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