peers

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package peers contains an interface for managing nodes in the mesh.

Package peers contains an interface for managing nodes in the mesh.

Index

Constants

View Source
const EdgesPrefix = storage.RegistryPrefix + "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>.

View Source
const NodesPrefix = storage.RegistryPrefix + "nodes"

NodesPrefix is where nodes are stored in the database. nodes are indexed by their ID in the format /registry/nodes/<id>.

Variables

View Source
var ErrEdgeNotFound = graph.ErrEdgeNotFound

ErrEdgeNotFound is returned when an edge is not found.

View Source
var ErrNodeNotFound = errors.New("node not found")

ErrNodeNotFound is returned when a node is not found.

View Source
var InvalidNodeIDChars = []rune{'/', '\\', ':', '*', '?', '"', '\'', '<', '>', '|', ','}

InvalidNodeIDChars are the characters that are not allowed in node IDs.

View Source
var ReservedNodeIDs = []string{"self", "local", "localhost", "leader", "voters", "observers"}

ReservedNodeIDs are reserved node IDs.

Functions

func EdgeAttrsForProto added in v0.4.1

func EdgeAttrsForProto(proto v1.ConnectProtocol) map[string]string

EdgeAttrsForProto returns the edge attributes for the given protocol.

func IsValidID

func IsValidID(id string) bool

IsValidID returns true if the given node ID is valid.

func NewGraphStore

func NewGraphStore(st storage.MeshStorage) graph.Store[string, MeshNode]

NewGraphStore creates a new GraphStore instance.

func ProtoFromEdgeAttrs added in v0.4.1

func ProtoFromEdgeAttrs(attrs map[string]string) v1.ConnectProtocol

ProtoFromEdgeAttrs returns the protocol for the given edge attributes.

Types

type FilterFunc added in v0.4.0

type FilterFunc func(MeshNode) bool

FilterFunc is a function that can be used to filter responses returned by a resolver.

type Graph

type Graph graph.Graph[string, MeshNode]

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

func NewGraph

func NewGraph(st storage.MeshStorage) Graph

NewGraph creates a new Graph instance.

type GraphStore

type GraphStore struct {
	storage.MeshStorage
	// contains filtered or unexported fields
}

GraphStore implements graph.Store[string, Node] where string is the node ID and Node is the node itself.

func (*GraphStore) AddEdge

func (g *GraphStore) AddEdge(sourceNode, targetNode string, edge graph.Edge[string]) error

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 string, 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

func (g *GraphStore) Edge(sourceNode, targetNode string) (graph.Edge[string], error)

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[string], error)

ListEdges should return all edges in the graph in a slice.

func (*GraphStore) ListVertices

func (g *GraphStore) ListVertices() ([]string, error)

ListVertices should return all vertices in the graph in a slice.

func (*GraphStore) RemoveEdge

func (g *GraphStore) RemoveEdge(sourceNode, targetNode string) 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 string) 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

func (g *GraphStore) UpdateEdge(sourceNode, targetNode string, edge graph.Edge[string]) error

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 string) (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 MeshNode added in v0.4.0

type MeshNode struct{ *v1.MeshNode }

func (*MeshNode) DNSPort added in v0.4.0

func (n *MeshNode) DNSPort() uint16

DNSPort returns the node's DNS port.

func (*MeshNode) HasFeature added in v0.4.0

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

HasFeature returns true if the node has the given feature.

func (*MeshNode) PortFor added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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) PrivateRaftAddrV4 added in v0.4.0

func (n *MeshNode) PrivateRaftAddrV4() netip.AddrPort

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

func (*MeshNode) PrivateRaftAddrV6 added in v0.4.0

func (n *MeshNode) PrivateRaftAddrV6() netip.AddrPort

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

func (*MeshNode) PrivateTURNAddrV4 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

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 added in v0.4.0

func (n *MeshNode) RPCPort() uint16

RPCPort returns the node's RPC port.

func (*MeshNode) RaftPort added in v0.4.0

func (n *MeshNode) RaftPort() uint16

RaftPort returns the node's Raft port.

func (*MeshNode) TURNPort added in v0.4.0

func (n *MeshNode) TURNPort() uint16

TURNPort returns the node's TURN port.

type Peers

type Peers interface {
	// Resolver returns a resolver backed by the storage
	// of this instance.
	Resolver() Resolver
	// Graph returns the graph of nodes.
	Graph() Graph
	// Put creates or updates a node.
	Put(ctx context.Context, n *v1.MeshNode) error
	// Get gets a node by ID.
	Get(ctx context.Context, id string) (MeshNode, error)
	// GetByPubKey gets a node by their public key.
	GetByPubKey(ctx context.Context, key crypto.PublicKey) (MeshNode, error)
	// Delete deletes a node.
	Delete(ctx context.Context, id string) error
	// List lists all nodes.
	List(ctx context.Context) ([]MeshNode, error)
	// ListIDs lists all node IDs.
	ListIDs(ctx context.Context) ([]string, error)
	// ListPublicNodes lists all public nodes.
	ListPublicNodes(ctx context.Context) ([]MeshNode, error)
	// ListByZoneID lists all nodes in a zone.
	ListByZoneID(ctx context.Context, zoneID string) ([]MeshNode, error)
	// ListByFeature lists all nodes with a given feature.
	ListByFeature(ctx context.Context, feature v1.Feature) ([]MeshNode, error)
	// AddEdge adds an edge between two nodes.
	PutEdge(ctx context.Context, edge *v1.MeshEdge) error
	// RemoveEdge removes an edge between two nodes.
	RemoveEdge(ctx context.Context, from, to string) error
	// DrawGraph draws the graph of nodes to the given Writer.
	DrawGraph(ctx context.Context, w io.Writer) error
}

Peers is the peers interface.

func New

func New(db storage.MeshStorage) Peers

New returns a new Peers interface.

type Resolver added in v0.4.0

type Resolver interface {
	// NodeIDResolver returns a resolver that resolves node addresses by node ID.
	NodeIDResolver() transport.NodeIDResolver
	// FeatureResolver returns a resolver that resolves node addresses by feature.
	FeatureResolver(filterFn ...FilterFunc) transport.FeatureResolver
}

Resolver provides facilities for creating various transport.Resolver instances.

func NewResolver added in v0.4.0

func NewResolver(st storage.MeshStorage) Resolver

NewResolver returns a new Resolver instance.

Jump to

Keyboard shortcuts

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