types

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: Apache-2.0 Imports: 17 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// GroupReference is the prefix of a node name that indicates it is a group reference.
	GroupReference = "group:"
)

Variables

View Source
var ReservedPrefixes = []Prefix{
	RegistryPrefix,
	ConsensusPrefix,
}

ReservedPrefixes is a list of all reserved prefixes.

Functions

func DrawPeerGraph

func DrawPeerGraph(ctx context.Context, g PeerGraph, w io.Writer) error

DrawPeerGraph draws a PeerGraph to the given writer in DOT format.

func EvalRole

func EvalRole(role *v1.Role, action *v1.RBACAction) bool

EvalRole evaluates an action against a single role.

func EvalRule

func EvalRule(rule *v1.Rule, action *v1.RBACAction) bool

EvalRule evaluates an action against a single rule.

func FeaturePortEqual

func FeaturePortEqual(a, b *v1.FeaturePort) bool

FeaturePortEqual compares two feature ports for equality.

func FeaturePortsEqual

func FeaturePortsEqual(a, b []*v1.FeaturePort) bool

FeaturePortsEqual compares two feature ports for equality.

func IsReservedPrefix

func IsReservedPrefix(key []byte) bool

IsReservedPrefix returns true if the given key is reserved.

func MeshNodesEqual

func MeshNodesEqual(a, b *v1.MeshNode) bool

MeshNodesEqual compares two mesh nodes for equality.

func ToPrefixes

func ToPrefixes(ss []string) []netip.Prefix

ToPrefixes converts a list of CIDRs to a list of Prefixes. It silently ignores invalid CIDRs.

func ValidateACL

func ValidateACL(acl *v1.NetworkACL) error

ValidateACL validates a NetworkACL.

func ValidateRoute

func ValidateRoute(route *v1.Route) error

ValidateRoute validates a Route.

func WireGuardPeerEqual

func WireGuardPeerEqual(a, b *v1.WireGuardPeer) bool

WireGuardPeerEqual compares two WireGuard peers for equality.

func WireGuardPeersEqual

func WireGuardPeersEqual(a, b []*v1.WireGuardPeer) bool

WireGuardPeersEqual recurses the WireGuard peers and compares them for equality. Both lists are sorted by ID first.

Types

type AdjacencyMap

type AdjacencyMap map[NodeID]EdgeMap

AdjacencyMap is a map of node names to a map of node names to edges.

func NewAdjacencyMap

func NewAdjacencyMap(g PeerGraph) (AdjacencyMap, error)

NewAdjacencyMap returns a new adjacency map for the graph.

func (AdjacencyMap) DeepEqual

func (a AdjacencyMap) DeepEqual(b AdjacencyMap) bool

DeepEqual returns true if the given AdjacencyMap is equal to this AdjacencyMap.

type Edge

type Edge graph.Edge[NodeID]

Edge is the graph.Edge implementation for the mesh network.

func (Edge) DeepEqual

func (e Edge) DeepEqual(other Edge) bool

DeepEqual returns true if the given Edge is equal to this Edge.

func (Edge) ToMeshEdge

func (e Edge) ToMeshEdge(source, target NodeID) MeshEdge

ToMeshEdge converts an Edge to a MeshEdge.

type EdgeMap

type EdgeMap map[NodeID]Edge

EdgeMap is a map of node names to edges.

func (EdgeMap) DeepEqual

func (e EdgeMap) DeepEqual(other EdgeMap) bool

DeepEqual returns true if the given EdgeMap is equal to this EdgeMap.

type MeshEdge

type MeshEdge struct{ *v1.MeshEdge }

MeshEdge wraps a mesh edge.

func (MeshEdge) AsGraphEdge

func (e MeshEdge) AsGraphEdge() graph.Edge[NodeID]

AsGraphEdge converts a MeshEdge to a graph.Edge.

func (MeshEdge) EdgeProperties

func (e MeshEdge) EdgeProperties() graph.EdgeProperties

EdgeProperties returns the edge's properties.

func (MeshEdge) MarshalJSON

func (e MeshEdge) MarshalJSON() ([]byte, error)

MarshalJSON marshals a MeshEdge to JSON.

func (MeshEdge) PutInto

func (e MeshEdge) PutInto(ctx context.Context, g PeerGraph) error

PutInto puts the MeshEdge into the given graph.

func (MeshEdge) SourceID

func (e MeshEdge) SourceID() NodeID

SourceID returns the source node's ID.

func (MeshEdge) TargetID

func (e MeshEdge) TargetID() NodeID

TargetID returns the target node's ID.

func (MeshEdge) ToEdge

func (e MeshEdge) ToEdge() Edge

ToEdge converts a MeshEdge to an Edge.

func (*MeshEdge) UnmarshalJSON

func (e *MeshEdge) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a MeshEdge from JSON.

type MeshNode

type MeshNode struct{ *v1.MeshNode }

MeshNode wraps a mesh node.

func (MeshNode) DNSPort

func (n MeshNode) DNSPort() uint16

DNSPort returns the node's DNS port.

func (MeshNode) HasFeature

func (n MeshNode) HasFeature(feature v1.Feature) bool

HasFeature returns true if the node has the given feature.

func (MeshNode) MarshalJSON

func (n MeshNode) MarshalJSON() ([]byte, error)

MarshalJSON marshals the node to JSON.

func (MeshNode) NodeID

func (n MeshNode) NodeID() NodeID

NodeID returns the node's ID.

func (MeshNode) PortFor

func (n MeshNode) PortFor(feature v1.Feature) uint16

PortFor returns the port for the given feature, or 0 if the feature is not available on this node.

func (MeshNode) PrivateAddrV4

func (n MeshNode) PrivateAddrV4() netip.Prefix

PrivateAddrV4 returns the node's private IPv4 address. Be sure to check if the returned Addr IsValid.

func (MeshNode) PrivateAddrV6

func (n MeshNode) PrivateAddrV6() netip.Prefix

PrivateAddrV6 returns the node's private IPv6 address. Be sure to check if the returned Addr IsValid.

func (MeshNode) PrivateDNSAddrV4

func (n MeshNode) PrivateDNSAddrV4() netip.AddrPort

PrivateDNSAddrV4 returns the private IPv4 address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateDNSAddrV6

func (n MeshNode) PrivateDNSAddrV6() netip.AddrPort

PrivateDNSAddrV6 returns the private IPv6 address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateRPCAddrV4

func (n MeshNode) PrivateRPCAddrV4() netip.AddrPort

PrivateRPCAddrV4 returns the private IPv4 address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateRPCAddrV6

func (n MeshNode) PrivateRPCAddrV6() netip.AddrPort

PrivateRPCAddrV6 returns the private IPv6 address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateStorageAddrV4

func (n MeshNode) PrivateStorageAddrV4() netip.AddrPort

PrivateStorageAddrV4 returns the private IPv4 address for the node's raft listener. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateStorageAddrV6

func (n MeshNode) PrivateStorageAddrV6() netip.AddrPort

PrivateStorageAddrV6 returns the private IPv6 address for the node's raft listener. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateTURNAddrV4

func (n MeshNode) PrivateTURNAddrV4() netip.AddrPort

PrivateTURNAddrV4 returns the private IPv4 address for the node's TURN server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PrivateTURNAddrV6

func (n MeshNode) PrivateTURNAddrV6() netip.AddrPort

PrivateTURNAddrV6 returns the private IPv6 address for the node's TURN server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PublicDNSAddr

func (n MeshNode) PublicDNSAddr() netip.AddrPort

PublicDNSAddr returns the public address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) PublicRPCAddr

func (n MeshNode) PublicRPCAddr() netip.AddrPort

PublicRPCAddr returns the public address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.

func (MeshNode) RPCPort

func (n MeshNode) RPCPort() uint16

RPCPort returns the node's RPC port.

func (MeshNode) StoragePort

func (n MeshNode) StoragePort() uint16

StoragePort returns the node's Storage port.

func (MeshNode) TURNPort

func (n MeshNode) TURNPort() uint16

TURNPort returns the node's TURN port.

func (*MeshNode) UnmarshalJSON

func (n *MeshNode) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals the node from JSON.

type NetworkACL

type NetworkACL struct{ *v1.NetworkACL }

NetworkACL is a Network ACL.

func (NetworkACL) DestinationPrefixes

func (a NetworkACL) DestinationPrefixes() []netip.Prefix

DestinationPrefixes returns the destination prefixes for the ACL. Invalid prefixes will be ignored.

func (NetworkACL) Equals

func (a NetworkACL) Equals(other NetworkACL) bool

Equals returns whether the ACLs are equal.

func (NetworkACL) MarshalJSON

func (a NetworkACL) MarshalJSON() ([]byte, error)

Marshal marshals the ACL to protobuf json.

func (NetworkACL) Matches

func (acl NetworkACL) Matches(ctx context.Context, action NetworkAction) bool

Matches checks if an action matches this ACL.

func (NetworkACL) Proto

func (a NetworkACL) Proto() *v1.NetworkACL

Proto returns the protobuf representation of the ACL.

func (NetworkACL) SourcePrefixes

func (a NetworkACL) SourcePrefixes() []netip.Prefix

SourcePrefixes returns the source prefixes for the ACL. Invalid prefixes will be ignored.

func (*NetworkACL) UnmarshalJSON

func (a *NetworkACL) UnmarshalJSON(data []byte) error

Unmarshal unmarshals the ACL from a protobuf.

type NetworkACLs

type NetworkACLs []NetworkACL

ACLs is a list of Network ACLs. It contains methods for evaluating actions against contained permissions. It also allows for sorting by priority.

func (NetworkACLs) Accept

func (a NetworkACLs) Accept(ctx context.Context, action NetworkAction) bool

Accept evaluates an action against the ACLs in the list. It assumes the ACLs are sorted by priority. The first ACL that matches the action will be used. If no ACL matches, the action is denied.

func (NetworkACLs) AllowNodesToCommunicate

func (a NetworkACLs) AllowNodesToCommunicate(ctx context.Context, nodeA, nodeB MeshNode) bool

AllowNodesToCommunicate checks if the given nodes are allowed to communicate.

func (NetworkACLs) Len

func (a NetworkACLs) Len() int

Len returns the length of the ACLs list.

func (NetworkACLs) Less

func (a NetworkACLs) Less(i, j int) bool

Less returns whether the ACL at index i should be sorted before the ACL at index j.

func (NetworkACLs) Proto

func (a NetworkACLs) Proto() []*v1.NetworkACL

Proto returns the protobuf representation of the ACLs.

func (NetworkACLs) Sort

func (a NetworkACLs) Sort(direction SortDirection)

Sort sorts the ACLs by priority.

func (NetworkACLs) Swap

func (a NetworkACLs) Swap(i, j int)

Swap swaps the ACLs at the given indices.

type NetworkAction

type NetworkAction struct {
	*v1.NetworkAction
}

NetworkAction wraps a NetworkAction.

func (*NetworkAction) DestinationPrefix

func (a *NetworkAction) DestinationPrefix() netip.Prefix

DestinationPrefix returns the destination prefix for the action if it is valid.

func (*NetworkAction) Proto

func (a *NetworkAction) Proto() *v1.NetworkAction

Proto returns the protobuf representation of the action.

func (*NetworkAction) SourcePrefix

func (a *NetworkAction) SourcePrefix() netip.Prefix

SourcePrefix returns the source prefix for the action if it is valid.

type NodeID

type NodeID string

NodeID is the type of a node ID.

func (NodeID) Bytes

func (id NodeID) Bytes() []byte

Bytes returns the byte representation of the node ID.

func (NodeID) IsEmpty

func (id NodeID) IsEmpty() bool

IsEmpty returns true if the node ID is empty.

func (NodeID) String

func (id NodeID) String() string

String returns the string representation of the node ID.

type PeerGraph

type PeerGraph graph.Graph[NodeID, MeshNode]

PeerGraph is the graph.Graph implementation for the mesh network.

func NewGraphWithStore

func NewGraphWithStore(store PeerGraphStore) PeerGraph

NewGraphWithStore creates a new Graph instance with the given graph storage implementation.

type PeerGraphStore

type PeerGraphStore graph.Store[NodeID, MeshNode]

PeerGraphStore is the graph.Store implementation for the mesh network.

type Prefix

type Prefix []byte

Prefix is a prefix in the storage.

var (
	// RegistryPrefix is the prefix for all data stored in the mesh registry.
	RegistryPrefix Prefix = []byte("/registry")

	// ConsensusPrefix is the prefix for all data stored related to consensus.
	ConsensusPrefix Prefix = []byte("/raft")
)

func (Prefix) Contains

func (p Prefix) Contains(key []byte) bool

Contains returns true if the given key is contained in the prefix.

func (Prefix) For

func (p Prefix) For(key []byte) Prefix

For is a helper method for creating a key for the prefix.

func (Prefix) ForString

func (p Prefix) ForString(key string) Prefix

ForString is a helper method for creating a key for the prefix.

func (Prefix) String

func (p Prefix) String() string

String returns the string representation of the prefix.

func (Prefix) TrimFrom

func (p Prefix) TrimFrom(key []byte) []byte

TrimFrom returns the key without the prefix.

type RolesList

type RolesList []*v1.Role

RolesList is a list of roles. It contains methods for evaluating actions against contained permissions.

func (RolesList) Eval

func (l RolesList) Eval(action *v1.RBACAction) bool

Eval evaluates an action against the roles in the list.

type Route

type Route struct {
	*v1.Route
}

Route wraps a Route.

func (*Route) DestinationPrefixes

func (r *Route) DestinationPrefixes() []netip.Prefix

DestinationPrefixes returns the destination prefixes for the route.

func (*Route) Equals

func (r *Route) Equals(other *Route) bool

Equals returns whether the routes are equal.

func (Route) MarshalJSON

func (r Route) MarshalJSON() ([]byte, error)

Marshal marshals the route to protobuf json.

func (*Route) Proto

func (r *Route) Proto() *v1.Route

Proto returns the protobuf representation of the route.

func (*Route) UnmarshalJSON

func (r *Route) UnmarshalJSON(data []byte) error

Unmarshal unmarshals the route from a protobuf.

type Routes

type Routes []Route

Routes is a list of routes.

func (Routes) Len

func (a Routes) Len() int

Len returns the length of the Routes list.

func (Routes) Less

func (a Routes) Less(i, j int) bool

Less returns whether the name of the route at index i is less than the name of the route at index j.

func (Routes) Proto

func (a Routes) Proto() []*v1.Route

Proto returns the protobuf representation of the Routes.

func (Routes) Sort

func (a Routes) Sort()

Sort sorts the routes by name.

func (Routes) Swap

func (a Routes) Swap(i, j int)

Swap swaps the routes at indexes i and j.

type SortDirection

type SortDirection int

SortDirection is the direction to sort ACLs.

const (
	// SortDescending sorts ACLs in descending order.
	SortDescending SortDirection = iota
	// SortAscending sorts ACLs in ascending order.
	SortAscending
)

type SortedWireGuardPeers

type SortedWireGuardPeers []*v1.WireGuardPeer

SortedWireGuardPeers implements a sort.Interface for []*v1.WireGuardPeer.

func (SortedWireGuardPeers) Len

func (s SortedWireGuardPeers) Len() int

func (SortedWireGuardPeers) Less

func (s SortedWireGuardPeers) Less(i, j int) bool

func (SortedWireGuardPeers) Swap

func (s SortedWireGuardPeers) Swap(i, j int)

Jump to

Keyboard shortcuts

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