Documentation ¶
Overview ¶
Package fact provides the core code for representing facts, and their serialization and deserialization.
Index ¶
- Constants
- func ScaleExpirationQuantumForTests(factor uint)
- func SliceHas(facts []*Fact, predicate func(*Fact) bool) bool
- func SliceIndexOf(facts []*Fact, predicate func(*Fact) bool) int
- type Attribute
- type EmptyValue
- type Fact
- func (f *Fact) DecodeFrom(_ int, now time.Time, reader util.ByteReader) error
- func (f *Fact) FancyString(subjectFormatter func(s Subject) string, now time.Time) string
- func (f *Fact) MarshalBinary() ([]byte, error)
- func (f *Fact) MarshalBinaryNow(now time.Time) ([]byte, error)
- func (f *Fact) String() string
- type GroupAccumulator
- type IPNetValue
- type IPPortValue
- type Key
- type MemberAttribute
- type MemberMetadata
- func (mm *MemberMetadata) DecodeFrom(_ int, reader io.Reader) error
- func (mm *MemberMetadata) ForEach(visitor func(MemberAttribute, string))
- func (mm *MemberMetadata) MarshalBinary() ([]byte, error)
- func (mm *MemberMetadata) String() string
- func (mm *MemberMetadata) With(name string, basic bool) *MemberMetadata
- type PeerSubject
- type Set
- type SignedGroupValue
- type Subject
- type UUIDValue
- type Value
Constants ¶
const MaxPayloadLen = 1024 * 1024
MaxPayloadLen is the largest payload size we will try to decode to avoid excess memory usage.
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.
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 ¶
func ScaleExpirationQuantumForTests ¶ added in v0.10.0
func ScaleExpirationQuantumForTests(factor uint)
ScaleExpirationQuantumForTests reconfigures how the fact TTL is represented on the wire to permit faster than normal tests
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' AttributeMember Attribute = 'm' AttributeMemberMetadata Attribute = 'M' // 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 ¶
type EmptyValue struct{}
EmptyValue is currently used as a placeholder in Membership facts
func (EmptyValue) DecodeFrom ¶ added in v0.6.0
func (v EmptyValue) DecodeFrom(_ int, _ 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 SortedCopy ¶
SortedCopy makes a copy of the list and then sorts it "naturally"
func (*Fact) DecodeFrom ¶ added in v0.6.0
DecodeFrom implements Decodable
func (*Fact) FancyString ¶ added in v0.3.0
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
MarshalBinary serializes a Fact to its on-wire format
func (*Fact) MarshalBinaryNow ¶ added in v0.9.0
MarshalBinaryNow is like MarshalBinary, except it uses a provided value of `now` so that the output is deterministic
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, now time.Time) *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 ¶
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 ¶
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 { // Attribute is a byte, nothing to worry about in comparisons Attribute Attribute // contains filtered or unexported fields }
Key is a comparable version of the subject, attribute, and value of a Fact
func KeysDifference ¶ added in v0.12.2
KeysDifference computes the fact keys that are different between two slices
func (*Key) FancyString ¶ added in v0.13.0
FancyString formats the fact as a string using a custom helper to format the subject, most commonly to replace peer keys with names
type MemberAttribute ¶ added in v0.11.0
type MemberAttribute byte
MemberAttribute is a single byte identifying some attribute of a member.
const ( // MemberName is the friendly / display name to use for a peer MemberName MemberAttribute = 'n' // MemberIsBasic flags if the member is a "basic" member which only runs // wireguard and not wirelink MemberIsBasic MemberAttribute = 'b' )
type MemberMetadata ¶ added in v0.11.0
type MemberMetadata struct {
// contains filtered or unexported fields
}
MemberMetadata represents a set of attributes and their values for a single peer.
func (*MemberMetadata) DecodeFrom ¶ added in v0.11.0
func (mm *MemberMetadata) DecodeFrom(_ int, reader io.Reader) error
DecodeFrom implements Decodable
func (*MemberMetadata) ForEach ¶ added in v0.11.0
func (mm *MemberMetadata) ForEach(visitor func(MemberAttribute, string))
ForEach calls visitor for each attribute in the metadata.
func (*MemberMetadata) MarshalBinary ¶ added in v0.11.0
func (mm *MemberMetadata) MarshalBinary() ([]byte, error)
MarshalBinary implements BinaryEncoder
func (*MemberMetadata) String ¶ added in v0.11.0
func (mm *MemberMetadata) String() string
func (*MemberMetadata) With ¶ added in v0.13.0
func (mm *MemberMetadata) With(name string, basic bool) *MemberMetadata
With returns a copy of the member metadata with the given info updated: name will be assigned if non-empty, basic will be assigned if true, or if not present in the initial value.
type PeerSubject ¶
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(_ int, reader io.Reader) error
DecodeFrom implements Decodable
func (*PeerSubject) IsSubject ¶ added in v0.11.3
func (s *PeerSubject) IsSubject()
IsSubject implements Subject
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 [chacha20poly1305.Overhead]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(_ 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(now time.Time) (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 // IsSubject tags Subjects as semantically different from Values IsSubject() }
Subject is the subject of a Fact