Documentation ¶
Overview ¶
Package graph implements a graph data structure for the mesh network.
Index ¶
- Variables
- func NewTestGraph() (Graph, *GraphStore, error)
- type AdjacencyMap
- type Edge
- type EdgeMap
- type Graph
- type GraphStore
- func (g *GraphStore) AddEdge(sourceNode, targetNode NodeID, edge graph.Edge[NodeID]) error
- func (g *GraphStore) AddVertex(nodeID NodeID, node MeshNode, props graph.VertexProperties) error
- func (g *GraphStore) Edge(sourceNode, targetNode NodeID) (graph.Edge[NodeID], error)
- func (g *GraphStore) ListEdges() ([]graph.Edge[NodeID], error)
- func (g *GraphStore) ListVertices() ([]NodeID, error)
- func (g *GraphStore) RemoveEdge(sourceNode, targetNode NodeID) error
- func (g *GraphStore) RemoveVertex(nodeID NodeID) error
- func (g *GraphStore) UpdateEdge(sourceNode, targetNode NodeID, edge graph.Edge[NodeID]) error
- func (g *GraphStore) Vertex(nodeID NodeID) (node MeshNode, props graph.VertexProperties, err error)
- func (g *GraphStore) VertexCount() (int, error)
- type MeshEdge
- func (e MeshEdge) AsGraphEdge() graph.Edge[NodeID]
- func (e MeshEdge) EdgeProperties() graph.EdgeProperties
- func (e MeshEdge) MarshalJSON() ([]byte, error)
- func (e MeshEdge) PutInto(g Graph) error
- func (e MeshEdge) SourceID() NodeID
- func (e MeshEdge) TargetID() NodeID
- func (e MeshEdge) ToEdge() Edge
- func (e *MeshEdge) UnmarshalJSON(data []byte) error
- type MeshNode
- func (n MeshNode) DNSPort() uint16
- func (n MeshNode) HasFeature(feature v1.Feature) bool
- func (n MeshNode) MarshalJSON() ([]byte, error)
- func (n MeshNode) NodeID() NodeID
- func (n MeshNode) PortFor(feature v1.Feature) uint16
- func (n MeshNode) PrivateAddrV4() netip.Prefix
- func (n MeshNode) PrivateAddrV6() netip.Prefix
- func (n MeshNode) PrivateDNSAddrV4() netip.AddrPort
- func (n MeshNode) PrivateDNSAddrV6() netip.AddrPort
- func (n MeshNode) PrivateRPCAddrV4() netip.AddrPort
- func (n MeshNode) PrivateRPCAddrV6() netip.AddrPort
- func (n MeshNode) PrivateStorageAddrV4() netip.AddrPort
- func (n MeshNode) PrivateStorageAddrV6() netip.AddrPort
- func (n MeshNode) PrivateTURNAddrV4() netip.AddrPort
- func (n MeshNode) PrivateTURNAddrV6() netip.AddrPort
- func (n MeshNode) PublicDNSAddr() netip.AddrPort
- func (n MeshNode) PublicRPCAddr() netip.AddrPort
- func (n MeshNode) RPCPort() uint16
- func (n MeshNode) StoragePort() uint16
- func (n MeshNode) TURNPort() uint16
- func (n *MeshNode) UnmarshalJSON(data []byte) error
- type NodeID
- type Store
Constants ¶
This section is empty.
Variables ¶
var EdgesPrefix = storage.RegistryPrefix.ForString("edges")
EdgesPrefix is where edges are stored in the database. edges are indexed by their source and target node IDs in the format /registry/edges/<source>/<target>.
var ErrEdgeNotFound = graph.ErrEdgeNotFound
ErrEdgeNotFound is returned when an edge is not found.
var ErrEmptyNodeID = errors.New("node ID must not be empty")
ErrEmptyNodeID is returned when a node ID is empty.
var ErrInvalidNodeID = errors.New("node ID is invalid")
ErrInvalidNodeID is returned when a node ID is invalid.
var NodesPrefix = storage.RegistryPrefix.ForString("nodes")
NodesPrefix is where nodes are stored in the database. nodes are indexed by their ID in the format /registry/nodes/<id>.
Functions ¶
func NewTestGraph ¶
func NewTestGraph() (Graph, *GraphStore, error)
NewTestGraph is an alias for creating a new graph with in-memory storage. It also returns the underlying storage instance.
Types ¶
type AdjacencyMap ¶
AdjacencyMap is a map of node names to a map of node names to edges.
func BuildAdjacencyMap ¶
func BuildAdjacencyMap(g Graph) (AdjacencyMap, error)
BuildAdjacencyMap returns the 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 ¶
Edge is the graph.Edge implementation for the mesh network.
func (Edge) ToMeshEdge ¶
ToMeshEdge converts an Edge to a MeshEdge.
type Graph ¶
Graph is the graph.Graph implementation for the mesh network.
func NewGraphWithStore ¶ added in v0.8.1
func NewGraphWithStore(st storage.MeshStorage, store Store) Graph
NewGraphWithStore creates a new Graph instance with the given store.
type GraphStore ¶
type GraphStore struct { storage.MeshStorage // contains filtered or unexported fields }
GraphStore implements the Store.
func (*GraphStore) AddEdge ¶
AddEdge should add an edge between the vertices with the given source and target hashes.
If either vertex doesn't exit, ErrVertexNotFound should be returned for the respective vertex. If the edge already exists, ErrEdgeAlreadyExists should be returned.
func (*GraphStore) AddVertex ¶
func (g *GraphStore) AddVertex(nodeID NodeID, node MeshNode, props graph.VertexProperties) error
AddVertex should add the given vertex with the given hash value and vertex properties to the graph. If the vertex already exists, it is up to you whether ErrVertexAlreadyExists or no error should be returned.
func (*GraphStore) Edge ¶
Edge should return the edge joining the vertices with the given hash values. It should exclusively look for an edge between the source and the target vertex, not vice versa. The graph implementation does this for undirected graphs itself.
Note that unlike Graph.Edge, this function is supposed to return an Edge[K], i.e. an edge that only contains the vertex hashes instead of the vertices themselves.
If the edge doesn't exist, ErrEdgeNotFound should be returned.
func (*GraphStore) ListEdges ¶
func (g *GraphStore) ListEdges() ([]graph.Edge[NodeID], error)
ListEdges should return all edges in the graph in a slice.
func (*GraphStore) ListVertices ¶
func (g *GraphStore) ListVertices() ([]NodeID, error)
ListVertices should return all vertices in the graph in a slice.
func (*GraphStore) RemoveEdge ¶
func (g *GraphStore) RemoveEdge(sourceNode, targetNode NodeID) error
RemoveEdge should remove the edge between the vertices with the given source and target hashes.
If either vertex doesn't exist, it is up to you whether ErrVertexNotFound or no error should be returned. If the edge doesn't exist, it is up to you whether ErrEdgeNotFound or no error should be returned.
func (*GraphStore) RemoveVertex ¶
func (g *GraphStore) RemoveVertex(nodeID NodeID) error
RemoveVertex should remove the vertex with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned. If the vertex has edges to other vertices, ErrVertexHasEdges should be returned.
func (*GraphStore) UpdateEdge ¶
UpdateEdge should update the edge between the given vertices with the data of the given Edge instance. If the edge doesn't exist, ErrEdgeNotFound should be returned.
func (*GraphStore) Vertex ¶
func (g *GraphStore) Vertex(nodeID NodeID) (node MeshNode, props graph.VertexProperties, err error)
Vertex should return the vertex and vertex properties with the given hash value. If the vertex doesn't exist, ErrVertexNotFound should be returned.
func (*GraphStore) VertexCount ¶
func (g *GraphStore) VertexCount() (int, error)
VertexCount should return the number of vertices in the graph. This should be equal to the length of the slice returned by ListVertices.
type MeshEdge ¶
MeshEdge wraps a mesh edge.
func (MeshEdge) AsGraphEdge ¶
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 ¶
MarshalJSON marshals a MeshEdge to JSON.
func (*MeshEdge) UnmarshalJSON ¶
UnmarshalJSON unmarshals a MeshEdge from JSON.
type MeshNode ¶
MeshNode wraps a mesh node.
func (MeshNode) HasFeature ¶
HasFeature returns true if the node has the given feature.
func (MeshNode) MarshalJSON ¶
MarshalJSON marshals the node to JSON.
func (MeshNode) PortFor ¶
PortFor returns the port for the given feature, or 0 if the feature is not available on this node.
func (MeshNode) PrivateAddrV4 ¶
PrivateAddrV4 returns the node's private IPv4 address. Be sure to check if the returned Addr IsValid.
func (MeshNode) PrivateAddrV6 ¶
PrivateAddrV6 returns the node's private IPv6 address. Be sure to check if the returned Addr IsValid.
func (MeshNode) PrivateDNSAddrV4 ¶
PrivateDNSAddrV4 returns the private IPv4 address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateDNSAddrV6 ¶
PrivateDNSAddrV6 returns the private IPv6 address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateRPCAddrV4 ¶
PrivateRPCAddrV4 returns the private IPv4 address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateRPCAddrV6 ¶
PrivateRPCAddrV6 returns the private IPv6 address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateStorageAddrV4 ¶
PrivateStorageAddrV4 returns the private IPv4 address for the node's raft listener. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateStorageAddrV6 ¶
PrivateStorageAddrV6 returns the private IPv6 address for the node's raft listener. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateTURNAddrV4 ¶
PrivateTURNAddrV4 returns the private IPv4 address for the node's TURN server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PrivateTURNAddrV6 ¶
PrivateTURNAddrV6 returns the private IPv6 address for the node's TURN server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PublicDNSAddr ¶
PublicDNSAddr returns the public address for the node's DNS server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) PublicRPCAddr ¶
PublicRPCAddr returns the public address for the node's RPC server. Be sure to check if the returned AddrPort IsValid.
func (MeshNode) StoragePort ¶
StoragePort returns the node's Storage port.
func (*MeshNode) UnmarshalJSON ¶
UnmarshalJSON unmarshals the node from JSON.