aegis

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 26 Imported by: 0

README

aegis

CI Status codecov Go Report Card CodeQL Go Reference License Go Version Release

Service mesh for Go microservices — mTLS everywhere, zero configuration. Nodes discover each other, authenticate via certificates, and call domain services without managing PKI infrastructure.

Zero-Trust by Default

node, _ := aegis.NewNodeBuilder().
    WithID("api-1").
    WithName("API Server").
    WithAddress("localhost:8443").
    WithServices(aegis.ServiceInfo{Name: "identity", Version: "v1"}).
    WithCertDir("./certs").
    Build()

node.StartServer()
// Certificates generated automatically. All connections use mTLS.
// Other nodes can now discover this service and call it securely.

Install

go get github.com/zoobzio/aegis

Requires Go 1.24+.

Quick Start

A provider node exposes a service. A consumer node discovers and calls it.

package main

import (
    "context"
    "log"

    "github.com/zoobzio/aegis"
    identity "github.com/zoobzio/aegis/proto/identity"
    "google.golang.org/grpc"
)

func main() {
    // Provider: morpheus serves identity
    morpheus, _ := aegis.NewNodeBuilder().
        WithID("morpheus-1").
        WithName("Morpheus").
        WithAddress("localhost:8443").
        WithServices(aegis.ServiceInfo{Name: "identity", Version: "v1"}).
        WithServiceRegistration(func(s *grpc.Server) {
            identity.RegisterIdentityServiceServer(s, &myIdentityServer{})
        }).
        WithCertDir("./certs").
        Build()

    morpheus.StartServer()
    defer morpheus.Shutdown()

    // Consumer: vicky calls identity service
    vicky, _ := aegis.NewNodeBuilder().
        WithID("vicky-1").
        WithName("Vicky").
        WithAddress("localhost:9443").
        WithCertDir("./certs").
        Build()

    pool := aegis.NewServiceClientPool(vicky)
    defer pool.Close()

    client := aegis.NewServiceClient(pool, "identity", "v1", identity.NewIdentityServiceClient)

    // Get a connection (round-robin across providers)
    ctx := context.Background()
    identityClient, _ := client.Get(ctx)
    resp, _ := identityClient.ValidateSession(ctx, &identity.ValidateSessionRequest{
        Token: "user-session-token",
    })

    log.Printf("Session valid: %v, user: %s", resp.Valid, resp.UserId)
}

Capabilities

Capability Description Docs
Node identity Build nodes with ID, name, type, address node_builder.go
Automatic mTLS Certificates generated on first run, loaded thereafter tls.go
Service registry Declare services, discover providers across mesh service.go
Topology sync Nodes share topology; version-based merge topology.go
Health checks Extensible health checker interface health.go
Service client Connection pooling, round-robin load balancing client.go
Caller identity Extract calling node from mTLS context context.go

Why aegis?

  • Automatic mTLS — Nodes generate and exchange certificates on startup. No PKI infrastructure to manage.
  • Service discovery built-in — Declare services, query providers, topology syncs across the mesh.
  • One import — Node, peer connections, health checks, and gRPC server in a single package.
  • Caller identity on every requestCallerFromContext(ctx) extracts the calling node from mTLS certificates.
  • Round-robin client pooling — Service clients load-balance across providers automatically.

The Ecosystem

aegis is the transport layer. Domain services build on top:

Package Role
capitan Event coordination within a process
herald Bridge capitan events to message brokers (future: aegis provider)
morpheus Identity service — implements IdentityService
vicky Storage service — consumes identity via mesh

Documentation

Learn

Guides

Reference

  • API — Function signatures
  • Types — Type definitions
  • pkg.go.dev — Generated documentation

Contributing

Contributions welcome — see CONTRIBUTING.md for guidelines.

License

MIT License — see LICENSE.

Documentation

Index

Constants

View Source
const (
	MeshService_Ping_FullMethodName         = "/aegis.MeshService/Ping"
	MeshService_GetHealth_FullMethodName    = "/aegis.MeshService/GetHealth"
	MeshService_GetNodeInfo_FullMethodName  = "/aegis.MeshService/GetNodeInfo"
	MeshService_SyncTopology_FullMethodName = "/aegis.MeshService/SyncTopology"
	MeshService_GetTopology_FullMethodName  = "/aegis.MeshService/GetTopology"
)

Variables

View Source
var (
	// ErrNoProviders is returned when no providers are found for a service.
	ErrNoProviders = errors.New("no providers available for service")
	// ErrNoTLSConfig is returned when the node has no TLS configuration.
	ErrNoTLSConfig = errors.New("node has no TLS configuration")
)
View Source
var (
	// ErrNoPeerInfo is returned when no peer info is found in context.
	ErrNoPeerInfo = errors.New("no peer info in context")
	// ErrNoTLSInfo is returned when the peer has no TLS info.
	ErrNoTLSInfo = errors.New("no TLS info in peer")
	// ErrNoCertificate is returned when no client certificate is present.
	ErrNoCertificate = errors.New("no client certificate")
)
View Source
var MeshService_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "aegis.MeshService",
	HandlerType: (*MeshServiceServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Ping",
			Handler:    _MeshService_Ping_Handler,
		},
		{
			MethodName: "GetHealth",
			Handler:    _MeshService_GetHealth_Handler,
		},
		{
			MethodName: "GetNodeInfo",
			Handler:    _MeshService_GetNodeInfo_Handler,
		},
		{
			MethodName: "SyncTopology",
			Handler:    _MeshService_SyncTopology_Handler,
		},
		{
			MethodName: "GetTopology",
			Handler:    _MeshService_GetTopology_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "mesh.proto",
}

MeshService_ServiceDesc is the grpc.ServiceDesc for MeshService service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func GenerateCertificateRequest

func GenerateCertificateRequest(_ string, _ string) ([]byte, error)

GenerateCertificateRequest generates a CSR for external CA signing.

func LoadCABundle

func LoadCABundle(source CertificateSource, fileOrEnvVar string) (*x509.CertPool, error)

LoadCABundle loads a CA bundle from file or environment

func ParseCertificateChain

func ParseCertificateChain(pemData []byte) ([]*x509.Certificate, error)

ParseCertificateChain parses a PEM certificate chain

func RegisterMeshServiceServer

func RegisterMeshServiceServer(s grpc.ServiceRegistrar, srv MeshServiceServer)

Types

type Caller

type Caller struct {
	NodeID      string
	Certificate *x509.Certificate
}

Caller represents the identity of a calling node.

func CallerFromContext

func CallerFromContext(ctx context.Context) (*Caller, error)

CallerFromContext extracts the caller's identity from the gRPC context. The caller's node ID is extracted from the client certificate's Common Name.

func MustCallerFromContext

func MustCallerFromContext(ctx context.Context) *Caller

MustCallerFromContext extracts the caller's identity, panicking on error. Use only when mTLS is guaranteed (e.g., after middleware validation).

type CertificateSource

type CertificateSource string

CertificateSource defines how certificates are loaded

const (
	// CertSourceFile loads certificates from files
	CertSourceFile CertificateSource = "file"
	// CertSourceEnv loads certificates from environment variables
	CertSourceEnv CertificateSource = "env"
	// CertSourceVault loads certificates from HashiCorp Vault (future)
	CertSourceVault CertificateSource = "vault"
)

type FunctionHealthChecker

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

FunctionHealthChecker performs health checks using a custom function.

func NewFunctionHealthChecker

func NewFunctionHealthChecker(name string, checkFn func(ctx context.Context) error) *FunctionHealthChecker

NewFunctionHealthChecker creates a new function-based health checker.

func (*FunctionHealthChecker) Check

func (*FunctionHealthChecker) Name

func (f *FunctionHealthChecker) Name() string

type GetTopologyRequest

type GetTopologyRequest struct {
	SenderId string `protobuf:"bytes,1,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"`
	// contains filtered or unexported fields
}

func (*GetTopologyRequest) Descriptor deprecated

func (*GetTopologyRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetTopologyRequest.ProtoReflect.Descriptor instead.

func (*GetTopologyRequest) GetSenderId

func (x *GetTopologyRequest) GetSenderId() string

func (*GetTopologyRequest) ProtoMessage

func (*GetTopologyRequest) ProtoMessage()

func (*GetTopologyRequest) ProtoReflect

func (x *GetTopologyRequest) ProtoReflect() protoreflect.Message

func (*GetTopologyRequest) Reset

func (x *GetTopologyRequest) Reset()

func (*GetTopologyRequest) String

func (x *GetTopologyRequest) String() string

type GetTopologyResponse

type GetTopologyResponse struct {
	Version int64           `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
	Nodes   []*TopologyNode `protobuf:"bytes,2,rep,name=nodes,proto3" json:"nodes,omitempty"`
	// contains filtered or unexported fields
}

func (*GetTopologyResponse) Descriptor deprecated

func (*GetTopologyResponse) Descriptor() ([]byte, []int)

Deprecated: Use GetTopologyResponse.ProtoReflect.Descriptor instead.

func (*GetTopologyResponse) GetNodes

func (x *GetTopologyResponse) GetNodes() []*TopologyNode

func (*GetTopologyResponse) GetVersion

func (x *GetTopologyResponse) GetVersion() int64

func (*GetTopologyResponse) ProtoMessage

func (*GetTopologyResponse) ProtoMessage()

func (*GetTopologyResponse) ProtoReflect

func (x *GetTopologyResponse) ProtoReflect() protoreflect.Message

func (*GetTopologyResponse) Reset

func (x *GetTopologyResponse) Reset()

func (*GetTopologyResponse) String

func (x *GetTopologyResponse) String() string

type HealthChecker

type HealthChecker interface {
	Check(ctx context.Context) error
	Name() string
}

HealthChecker defines the interface for health check implementations.

type HealthInfo

type HealthInfo struct {
	Status      HealthStatus `json:"status"`
	LastChecked time.Time    `json:"last_checked"`
	Message     string       `json:"message,omitempty"`
	Error       string       `json:"error,omitempty"`
	// contains filtered or unexported fields
}

HealthInfo contains health status information for a node.

func NewHealthInfo

func NewHealthInfo() *HealthInfo

NewHealthInfo creates a new health info with unknown status.

func (*HealthInfo) Get

func (h *HealthInfo) Get() (HealthStatus, time.Time, string, string)

func (*HealthInfo) IsHealthy

func (h *HealthInfo) IsHealthy() bool

func (*HealthInfo) String

func (h *HealthInfo) String() string

func (*HealthInfo) Update

func (h *HealthInfo) Update(status HealthStatus, message string, err error)

type HealthRequest

type HealthRequest struct {
	SenderId string `protobuf:"bytes,1,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"`
	// contains filtered or unexported fields
}

func (*HealthRequest) Descriptor deprecated

func (*HealthRequest) Descriptor() ([]byte, []int)

Deprecated: Use HealthRequest.ProtoReflect.Descriptor instead.

func (*HealthRequest) GetSenderId

func (x *HealthRequest) GetSenderId() string

func (*HealthRequest) ProtoMessage

func (*HealthRequest) ProtoMessage()

func (*HealthRequest) ProtoReflect

func (x *HealthRequest) ProtoReflect() protoreflect.Message

func (*HealthRequest) Reset

func (x *HealthRequest) Reset()

func (*HealthRequest) String

func (x *HealthRequest) String() string

type HealthResponse

type HealthResponse struct {
	NodeId      string `protobuf:"bytes,1,opt,name=node_id,json=nodeId,proto3" json:"node_id,omitempty"`
	Status      string `protobuf:"bytes,2,opt,name=status,proto3" json:"status,omitempty"`
	LastChecked int64  `protobuf:"varint,3,opt,name=last_checked,json=lastChecked,proto3" json:"last_checked,omitempty"`
	Message     string `protobuf:"bytes,4,opt,name=message,proto3" json:"message,omitempty"`
	Error       string `protobuf:"bytes,5,opt,name=error,proto3" json:"error,omitempty"`
	// contains filtered or unexported fields
}

func (*HealthResponse) Descriptor deprecated

func (*HealthResponse) Descriptor() ([]byte, []int)

Deprecated: Use HealthResponse.ProtoReflect.Descriptor instead.

func (*HealthResponse) GetError

func (x *HealthResponse) GetError() string

func (*HealthResponse) GetLastChecked

func (x *HealthResponse) GetLastChecked() int64

func (*HealthResponse) GetMessage

func (x *HealthResponse) GetMessage() string

func (*HealthResponse) GetNodeId

func (x *HealthResponse) GetNodeId() string

func (*HealthResponse) GetStatus

func (x *HealthResponse) GetStatus() string

func (*HealthResponse) ProtoMessage

func (*HealthResponse) ProtoMessage()

func (*HealthResponse) ProtoReflect

func (x *HealthResponse) ProtoReflect() protoreflect.Message

func (*HealthResponse) Reset

func (x *HealthResponse) Reset()

func (*HealthResponse) String

func (x *HealthResponse) String() string

type HealthStatus

type HealthStatus string

HealthStatus represents the health state of a node.

const (
	HealthStatusHealthy   HealthStatus = "healthy"
	HealthStatusUnhealthy HealthStatus = "unhealthy"
	HealthStatusUnknown   HealthStatus = "unknown"
)

type MeshServer

type MeshServer struct {
	UnimplementedMeshServiceServer
	// contains filtered or unexported fields
}

MeshServer handles gRPC mesh service requests.

func NewMeshServer

func NewMeshServer(node *Node) *MeshServer

NewMeshServer creates a new mesh server for the node.

func (*MeshServer) GetHealth

func (ms *MeshServer) GetHealth(ctx context.Context, req *HealthRequest) (*HealthResponse, error)

GetHealth returns the health status of this node.

func (*MeshServer) GetNodeInfo

func (ms *MeshServer) GetNodeInfo(ctx context.Context, req *NodeInfoRequest) (*NodeInfoResponse, error)

GetNodeInfo returns information about this node.

func (*MeshServer) GetTopology

func (ms *MeshServer) GetTopology(ctx context.Context, req *GetTopologyRequest) (*GetTopologyResponse, error)

GetTopology returns the current topology.

func (*MeshServer) Ping

func (ms *MeshServer) Ping(ctx context.Context, req *PingRequest) (*PingResponse, error)

Ping responds to ping requests.

func (*MeshServer) RegisterService

func (ms *MeshServer) RegisterService(r ServiceRegistrar)

RegisterService adds a service registrar to be called when the server starts.

func (*MeshServer) SetTLSConfig

func (ms *MeshServer) SetTLSConfig(tlsConfig *TLSConfig)

SetTLSConfig sets the TLS configuration for the server.

func (*MeshServer) Start

func (ms *MeshServer) Start() error

Start starts the gRPC server.

func (*MeshServer) Stop

func (ms *MeshServer) Stop()

Stop gracefully stops the gRPC server.

func (*MeshServer) SyncTopology

func (ms *MeshServer) SyncTopology(ctx context.Context, req *TopologySyncRequest) (*TopologySyncResponse, error)

SyncTopology handles topology synchronization requests.

type MeshServiceClient

type MeshServiceClient interface {
	// Core mesh primitives
	Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PingResponse, error)
	GetHealth(ctx context.Context, in *HealthRequest, opts ...grpc.CallOption) (*HealthResponse, error)
	GetNodeInfo(ctx context.Context, in *NodeInfoRequest, opts ...grpc.CallOption) (*NodeInfoResponse, error)
	// Topology operations
	SyncTopology(ctx context.Context, in *TopologySyncRequest, opts ...grpc.CallOption) (*TopologySyncResponse, error)
	GetTopology(ctx context.Context, in *GetTopologyRequest, opts ...grpc.CallOption) (*GetTopologyResponse, error)
}

MeshServiceClient is the client API for MeshService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type MeshServiceServer

type MeshServiceServer interface {
	// Core mesh primitives
	Ping(context.Context, *PingRequest) (*PingResponse, error)
	GetHealth(context.Context, *HealthRequest) (*HealthResponse, error)
	GetNodeInfo(context.Context, *NodeInfoRequest) (*NodeInfoResponse, error)
	// Topology operations
	SyncTopology(context.Context, *TopologySyncRequest) (*TopologySyncResponse, error)
	GetTopology(context.Context, *GetTopologyRequest) (*GetTopologyResponse, error)
	// contains filtered or unexported methods
}

MeshServiceServer is the server API for MeshService service. All implementations must embed UnimplementedMeshServiceServer for forward compatibility.

type Node

type Node struct {
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	Type        NodeType      `json:"type"`
	Address     string        `json:"address"`
	Services    []ServiceInfo `json:"services,omitempty"`
	Health      *HealthInfo   `json:"health"`
	PeerManager *PeerManager  `json:"-"`
	MeshServer  *MeshServer   `json:"-"`
	Topology    *Topology     `json:"-"`
	TLSConfig   *TLSConfig    `json:"-"`
}

Node represents a node in the mesh network.

func NewNode

func NewNode(id, name string, nodeType NodeType, address string) *Node

NewNode creates a new mesh node.

func NewSecureNode

func NewSecureNode(id, name string, nodeType NodeType, address, certDir string) (*Node, error)

NewSecureNode is a convenience function that creates a node with TLS enabled.

func (*Node) AddPeer

func (n *Node) AddPeer(info PeerInfo) error

AddPeer adds a peer connection.

func (*Node) CheckHealth

func (n *Node) CheckHealth(ctx context.Context, checker HealthChecker) error

CheckHealth runs a health check using the provided checker.

func (*Node) EnableTLS

func (n *Node) EnableTLS(certDir string) error

EnableTLS enables TLS for the node using the specified certificate directory.

func (*Node) GetAllPeers

func (n *Node) GetAllPeers() []*Peer

GetAllPeers returns all connected peers.

func (*Node) GetHealth

func (n *Node) GetHealth() (HealthStatus, string)

GetHealth returns the node's health status and message.

func (*Node) GetMeshNodes

func (n *Node) GetMeshNodes() []NodeInfo

GetMeshNodes returns all nodes in the topology.

func (*Node) GetPeer

func (n *Node) GetPeer(peerID string) (*Peer, bool)

GetPeer returns a peer by ID.

func (*Node) GetPeerHealth

func (n *Node) GetPeerHealth(ctx context.Context, peerID string) (*HealthResponse, error)

GetPeerHealth retrieves the health status of a peer.

func (*Node) GetPeerNodeInfo

func (n *Node) GetPeerNodeInfo(ctx context.Context, peerID string) (*NodeInfoResponse, error)

GetPeerNodeInfo retrieves node information from a peer.

func (*Node) GetTopologyVersion

func (n *Node) GetTopologyVersion() int64

GetTopologyVersion returns the current topology version.

func (*Node) IsHealthy

func (n *Node) IsHealthy() bool

IsHealthy returns whether the node is healthy.

func (*Node) MarshalJSON

func (n *Node) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Node) PingPeer

func (n *Node) PingPeer(ctx context.Context, peerID string) (*PingResponse, error)

PingPeer sends a ping to a peer.

func (*Node) RemovePeer

func (n *Node) RemovePeer(peerID string) error

RemovePeer removes a peer connection.

func (*Node) SetHealth

func (n *Node) SetHealth(status HealthStatus, message string, err error)

SetHealth updates the node's health status.

func (*Node) Shutdown

func (n *Node) Shutdown() error

Shutdown gracefully shuts down the node.

func (*Node) StartServer

func (n *Node) StartServer() error

StartServer starts the gRPC mesh server.

func (*Node) StopServer

func (n *Node) StopServer()

StopServer stops the gRPC mesh server.

func (*Node) String

func (n *Node) String() string

String returns a string representation of the node.

func (*Node) SyncTopology

func (n *Node) SyncTopology(ctx context.Context, peerID string) error

SyncTopology synchronizes topology with a specific peer.

func (*Node) SyncTopologyWithAllPeers

func (n *Node) SyncTopologyWithAllPeers(ctx context.Context) error

SyncTopologyWithAllPeers synchronizes topology with all connected peers.

func (*Node) UnmarshalJSON

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

UnmarshalJSON implements json.Unmarshaler.

func (*Node) Validate

func (n *Node) Validate() error

Validate validates the node configuration.

type NodeBuilder

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

NodeBuilder provides a fluent interface for creating nodes with required TLS.

func NewNodeBuilder

func NewNodeBuilder() *NodeBuilder

NewNodeBuilder creates a new node builder.

func (*NodeBuilder) Build

func (nb *NodeBuilder) Build() (*Node, error)

Build creates the node with TLS enabled.

func (*NodeBuilder) WithAddress

func (nb *NodeBuilder) WithAddress(address string) *NodeBuilder

WithAddress sets the node address.

func (*NodeBuilder) WithCertDir

func (nb *NodeBuilder) WithCertDir(certDir string) *NodeBuilder

WithCertDir sets the certificate directory.

func (*NodeBuilder) WithID

func (nb *NodeBuilder) WithID(id string) *NodeBuilder

WithID sets the node ID.

func (*NodeBuilder) WithName

func (nb *NodeBuilder) WithName(name string) *NodeBuilder

WithName sets the node name.

func (*NodeBuilder) WithServiceRegistration

func (nb *NodeBuilder) WithServiceRegistration(r ServiceRegistrar) *NodeBuilder

WithServiceRegistration adds a callback to register gRPC services on the server.

func (*NodeBuilder) WithServices

func (nb *NodeBuilder) WithServices(services ...ServiceInfo) *NodeBuilder

WithServices sets the services this node provides.

func (*NodeBuilder) WithTLSOptions

func (nb *NodeBuilder) WithTLSOptions(opts *TLSOptions) *NodeBuilder

WithTLSOptions sets custom TLS options.

func (*NodeBuilder) WithType

func (nb *NodeBuilder) WithType(nodeType NodeType) *NodeBuilder

WithType sets the node type.

type NodeInfo

type NodeInfo struct {
	ID        string        `json:"id"`
	Name      string        `json:"name"`
	Type      NodeType      `json:"type"`
	Address   string        `json:"address"`
	Services  []ServiceInfo `json:"services,omitempty"`
	JoinedAt  time.Time     `json:"joined_at"`
	UpdatedAt time.Time     `json:"updated_at"`
}

NodeInfo contains information about a node in the mesh topology.

type NodeInfoRequest

type NodeInfoRequest struct {
	SenderId string `protobuf:"bytes,1,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"`
	// contains filtered or unexported fields
}

func (*NodeInfoRequest) Descriptor deprecated

func (*NodeInfoRequest) Descriptor() ([]byte, []int)

Deprecated: Use NodeInfoRequest.ProtoReflect.Descriptor instead.

func (*NodeInfoRequest) GetSenderId

func (x *NodeInfoRequest) GetSenderId() string

func (*NodeInfoRequest) ProtoMessage

func (*NodeInfoRequest) ProtoMessage()

func (*NodeInfoRequest) ProtoReflect

func (x *NodeInfoRequest) ProtoReflect() protoreflect.Message

func (*NodeInfoRequest) Reset

func (x *NodeInfoRequest) Reset()

func (*NodeInfoRequest) String

func (x *NodeInfoRequest) String() string

type NodeInfoResponse

type NodeInfoResponse struct {
	Id      string          `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Name    string          `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	Type    string          `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
	Address string          `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"`
	Health  *HealthResponse `protobuf:"bytes,5,opt,name=health,proto3" json:"health,omitempty"`
	// contains filtered or unexported fields
}

func (*NodeInfoResponse) Descriptor deprecated

func (*NodeInfoResponse) Descriptor() ([]byte, []int)

Deprecated: Use NodeInfoResponse.ProtoReflect.Descriptor instead.

func (*NodeInfoResponse) GetAddress

func (x *NodeInfoResponse) GetAddress() string

func (*NodeInfoResponse) GetHealth

func (x *NodeInfoResponse) GetHealth() *HealthResponse

func (*NodeInfoResponse) GetId

func (x *NodeInfoResponse) GetId() string

func (*NodeInfoResponse) GetName

func (x *NodeInfoResponse) GetName() string

func (*NodeInfoResponse) GetType

func (x *NodeInfoResponse) GetType() string

func (*NodeInfoResponse) ProtoMessage

func (*NodeInfoResponse) ProtoMessage()

func (*NodeInfoResponse) ProtoReflect

func (x *NodeInfoResponse) ProtoReflect() protoreflect.Message

func (*NodeInfoResponse) Reset

func (x *NodeInfoResponse) Reset()

func (*NodeInfoResponse) String

func (x *NodeInfoResponse) String() string

type NodeType

type NodeType string

NodeType represents the type of node in the mesh.

const (
	// NodeTypeGeneric is the default node type.
	NodeTypeGeneric NodeType = "generic"
)

type Peer

type Peer struct {
	Info   PeerInfo
	Client MeshServiceClient
	Conn   *grpc.ClientConn
}

Peer represents a connected peer node.

type PeerInfo

type PeerInfo struct {
	ID      string   `json:"id"`
	Address string   `json:"address"`
	Type    NodeType `json:"type"`
}

PeerInfo contains information about a peer node.

type PeerManager

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

PeerManager manages connections to peer nodes.

func NewPeerManager

func NewPeerManager(nodeID string) *PeerManager

NewPeerManager creates a new peer manager.

func (*PeerManager) AddPeer

func (pm *PeerManager) AddPeer(info PeerInfo) error

AddPeer adds a new peer connection.

func (*PeerManager) Close

func (pm *PeerManager) Close() error

Close closes all peer connections.

func (*PeerManager) Count

func (pm *PeerManager) Count() int

Count returns the number of connected peers.

func (*PeerManager) GetAllPeers

func (pm *PeerManager) GetAllPeers() []*Peer

GetAllPeers returns all connected peers.

func (*PeerManager) GetPeer

func (pm *PeerManager) GetPeer(peerID string) (*Peer, bool)

GetPeer returns a peer by ID.

func (*PeerManager) GetPeerHealth

func (pm *PeerManager) GetPeerHealth(ctx context.Context, peerID string) (*HealthResponse, error)

GetPeerHealth retrieves the health status of a peer.

func (*PeerManager) GetPeerNodeInfo

func (pm *PeerManager) GetPeerNodeInfo(ctx context.Context, peerID string) (*NodeInfoResponse, error)

GetPeerNodeInfo retrieves node information from a peer.

func (*PeerManager) GetPeersByType

func (pm *PeerManager) GetPeersByType(nodeType NodeType) []*Peer

GetPeersByType returns peers of a specific type.

func (*PeerManager) IsConnected

func (pm *PeerManager) IsConnected(peerID string) bool

IsConnected checks if a peer connection is in READY state.

func (*PeerManager) PingPeer

func (pm *PeerManager) PingPeer(ctx context.Context, peerID string) (*PingResponse, error)

PingPeer sends a ping request to a peer.

func (*PeerManager) RemovePeer

func (pm *PeerManager) RemovePeer(peerID string) error

RemovePeer removes a peer connection.

func (*PeerManager) SetTLSConfig

func (pm *PeerManager) SetTLSConfig(tlsConfig *TLSConfig)

SetTLSConfig sets the TLS configuration for peer connections.

func (*PeerManager) SyncTopology

func (pm *PeerManager) SyncTopology(ctx context.Context, peerID string, version int64) (*TopologySyncResponse, error)

SyncTopology requests topology synchronization from a peer.

type PingHealthChecker

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

PingHealthChecker performs simple ping-based health checks.

func NewPingHealthChecker

func NewPingHealthChecker(name string) *PingHealthChecker

NewPingHealthChecker creates a new ping-based health checker.

func (*PingHealthChecker) Check

func (p *PingHealthChecker) Check(ctx context.Context) error

func (*PingHealthChecker) Name

func (p *PingHealthChecker) Name() string

type PingRequest

type PingRequest struct {
	SenderId  string `protobuf:"bytes,1,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"`
	Timestamp int64  `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	// contains filtered or unexported fields
}

func (*PingRequest) Descriptor deprecated

func (*PingRequest) Descriptor() ([]byte, []int)

Deprecated: Use PingRequest.ProtoReflect.Descriptor instead.

func (*PingRequest) GetSenderId

func (x *PingRequest) GetSenderId() string

func (*PingRequest) GetTimestamp

func (x *PingRequest) GetTimestamp() int64

func (*PingRequest) ProtoMessage

func (*PingRequest) ProtoMessage()

func (*PingRequest) ProtoReflect

func (x *PingRequest) ProtoReflect() protoreflect.Message

func (*PingRequest) Reset

func (x *PingRequest) Reset()

func (*PingRequest) String

func (x *PingRequest) String() string

type PingResponse

type PingResponse struct {
	ReceiverId string `protobuf:"bytes,1,opt,name=receiver_id,json=receiverId,proto3" json:"receiver_id,omitempty"`
	Timestamp  int64  `protobuf:"varint,2,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Success    bool   `protobuf:"varint,3,opt,name=success,proto3" json:"success,omitempty"`
	// contains filtered or unexported fields
}

func (*PingResponse) Descriptor deprecated

func (*PingResponse) Descriptor() ([]byte, []int)

Deprecated: Use PingResponse.ProtoReflect.Descriptor instead.

func (*PingResponse) GetReceiverId

func (x *PingResponse) GetReceiverId() string

func (*PingResponse) GetSuccess

func (x *PingResponse) GetSuccess() bool

func (*PingResponse) GetTimestamp

func (x *PingResponse) GetTimestamp() int64

func (*PingResponse) ProtoMessage

func (*PingResponse) ProtoMessage()

func (*PingResponse) ProtoReflect

func (x *PingResponse) ProtoReflect() protoreflect.Message

func (*PingResponse) Reset

func (x *PingResponse) Reset()

func (*PingResponse) String

func (x *PingResponse) String() string

type Service

type Service struct {
	Name    string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"`
	// contains filtered or unexported fields
}

func (*Service) Descriptor deprecated

func (*Service) Descriptor() ([]byte, []int)

Deprecated: Use Service.ProtoReflect.Descriptor instead.

func (*Service) GetName

func (x *Service) GetName() string

func (*Service) GetVersion

func (x *Service) GetVersion() string

func (*Service) ProtoMessage

func (*Service) ProtoMessage()

func (*Service) ProtoReflect

func (x *Service) ProtoReflect() protoreflect.Message

func (*Service) Reset

func (x *Service) Reset()

func (*Service) String

func (x *Service) String() string

type ServiceClient

type ServiceClient[T any] struct {
	// contains filtered or unexported fields
}

ServiceClient provides a typed client for a specific service.

func NewServiceClient

func NewServiceClient[T any](pool *ServiceClientPool, name, version string, newClient func(grpc.ClientConnInterface) T) *ServiceClient[T]

NewServiceClient creates a typed service client.

func (*ServiceClient[T]) Get

func (sc *ServiceClient[T]) Get(ctx context.Context) (T, error)

Get returns a client instance connected to a provider. Each call may return a client connected to a different provider (round-robin).

type ServiceClientPool

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

ServiceClientPool manages gRPC connections to service providers.

func NewServiceClientPool

func NewServiceClientPool(node *Node) *ServiceClientPool

NewServiceClientPool creates a connection pool for service clients.

func (*ServiceClientPool) Close

func (p *ServiceClientPool) Close() error

Close closes all connections in the pool.

func (*ServiceClientPool) GetConn

func (p *ServiceClientPool) GetConn(ctx context.Context, name, version string) (*grpc.ClientConn, error)

GetConn returns a connection to a provider of the specified service. Uses round-robin to distribute calls across providers.

type ServiceInfo

type ServiceInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ServiceInfo represents a service that a node provides. This is the internal representation; Service from mesh.pb.go is used for wire format.

type ServiceRegistrar

type ServiceRegistrar func(*grpc.Server)

ServiceRegistrar is called to register additional gRPC services.

type TLSConfig

type TLSConfig struct {
	Certificate tls.Certificate
	CertPool    *x509.CertPool
	ServerName  string
}

TLSConfig holds the TLS configuration for a node

func LoadOrGenerateTLS

func LoadOrGenerateTLS(nodeID string, certDir string) (*TLSConfig, error)

LoadOrGenerateTLS loads existing certificates or generates new ones

func LoadTLSConfig

func LoadTLSConfig(opts *TLSOptions) (*TLSConfig, error)

LoadTLSConfig loads TLS configuration based on options

func (*TLSConfig) GetClientTLSConfig

func (tc *TLSConfig) GetClientTLSConfig(serverName string) *tls.Config

GetClientTLSConfig returns TLS configuration for the client

func (*TLSConfig) GetServerTLSConfig

func (tc *TLSConfig) GetServerTLSConfig() *tls.Config

GetServerTLSConfig returns TLS configuration for the server

type TLSOptions

type TLSOptions struct {
	// Source determines where certificates come from
	Source CertificateSource

	// For file-based certificates
	CertFile string
	KeyFile  string
	CAFile   string

	// For environment-based certificates
	CertEnvVar string
	KeyEnvVar  string
	CAEnvVar   string

	// For Vault-based certificates (future)
	VaultPath string
	VaultRole string

	// Validation options
	VerifyChain  bool
	AllowExpired bool
	RequiredSANs []string
}

TLSOptions configures how TLS certificates are loaded

func DefaultTLSOptions

func DefaultTLSOptions(nodeID string, certDir string) *TLSOptions

DefaultTLSOptions returns secure default options

type Topology

type Topology struct {
	Nodes     map[string]NodeInfo `json:"nodes"`
	Version   int64               `json:"version"`
	UpdatedAt time.Time           `json:"updated_at"`
	// contains filtered or unexported fields
}

Topology maintains the mesh network topology.

func NewTopology

func NewTopology() *Topology

NewTopology creates a new empty topology.

func (*Topology) AddNode

func (t *Topology) AddNode(info NodeInfo) error

AddNode adds a node to the topology.

func (*Topology) Clone

func (t *Topology) Clone() *Topology

Clone creates a copy of the topology.

func (*Topology) GetAllNodes

func (t *Topology) GetAllNodes() []NodeInfo

GetAllNodes returns all nodes in the topology.

func (*Topology) GetNode

func (t *Topology) GetNode(nodeID string) (NodeInfo, bool)

GetNode returns a node by ID.

func (*Topology) GetNodesByService

func (t *Topology) GetNodesByService(name string) []NodeInfo

GetNodesByService returns all nodes that provide any version of the specified service.

func (*Topology) GetServiceProviders

func (t *Topology) GetServiceProviders(name, version string) []NodeInfo

GetServiceProviders returns all nodes that provide the specified service.

func (*Topology) GetVersion

func (t *Topology) GetVersion() int64

GetVersion returns the topology version.

func (*Topology) Merge

func (t *Topology) Merge(other *Topology) bool

Merge merges another topology if it has a higher version.

func (*Topology) NodeCount

func (t *Topology) NodeCount() int

NodeCount returns the number of nodes.

func (*Topology) RemoveNode

func (t *Topology) RemoveNode(nodeID string) error

RemoveNode removes a node from the topology.

func (*Topology) UpdateNode

func (t *Topology) UpdateNode(info NodeInfo) error

UpdateNode updates a node in the topology.

type TopologyNode

type TopologyNode struct {
	Id        string     `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Name      string     `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	Type      string     `protobuf:"bytes,3,opt,name=type,proto3" json:"type,omitempty"`
	Address   string     `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"`
	JoinedAt  int64      `protobuf:"varint,5,opt,name=joined_at,json=joinedAt,proto3" json:"joined_at,omitempty"`
	UpdatedAt int64      `protobuf:"varint,6,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
	Services  []*Service `protobuf:"bytes,7,rep,name=services,proto3" json:"services,omitempty"`
	// contains filtered or unexported fields
}

func (*TopologyNode) Descriptor deprecated

func (*TopologyNode) Descriptor() ([]byte, []int)

Deprecated: Use TopologyNode.ProtoReflect.Descriptor instead.

func (*TopologyNode) GetAddress

func (x *TopologyNode) GetAddress() string

func (*TopologyNode) GetId

func (x *TopologyNode) GetId() string

func (*TopologyNode) GetJoinedAt

func (x *TopologyNode) GetJoinedAt() int64

func (*TopologyNode) GetName

func (x *TopologyNode) GetName() string

func (*TopologyNode) GetServices

func (x *TopologyNode) GetServices() []*Service

func (*TopologyNode) GetType

func (x *TopologyNode) GetType() string

func (*TopologyNode) GetUpdatedAt

func (x *TopologyNode) GetUpdatedAt() int64

func (*TopologyNode) ProtoMessage

func (*TopologyNode) ProtoMessage()

func (*TopologyNode) ProtoReflect

func (x *TopologyNode) ProtoReflect() protoreflect.Message

func (*TopologyNode) Reset

func (x *TopologyNode) Reset()

func (*TopologyNode) String

func (x *TopologyNode) String() string

type TopologySyncRequest

type TopologySyncRequest struct {
	SenderId string `protobuf:"bytes,1,opt,name=sender_id,json=senderId,proto3" json:"sender_id,omitempty"`
	Version  int64  `protobuf:"varint,2,opt,name=version,proto3" json:"version,omitempty"`
	// contains filtered or unexported fields
}

Topology messages

func (*TopologySyncRequest) Descriptor deprecated

func (*TopologySyncRequest) Descriptor() ([]byte, []int)

Deprecated: Use TopologySyncRequest.ProtoReflect.Descriptor instead.

func (*TopologySyncRequest) GetSenderId

func (x *TopologySyncRequest) GetSenderId() string

func (*TopologySyncRequest) GetVersion

func (x *TopologySyncRequest) GetVersion() int64

func (*TopologySyncRequest) ProtoMessage

func (*TopologySyncRequest) ProtoMessage()

func (*TopologySyncRequest) ProtoReflect

func (x *TopologySyncRequest) ProtoReflect() protoreflect.Message

func (*TopologySyncRequest) Reset

func (x *TopologySyncRequest) Reset()

func (*TopologySyncRequest) String

func (x *TopologySyncRequest) String() string

type TopologySyncResponse

type TopologySyncResponse struct {
	Version   int64           `protobuf:"varint,1,opt,name=version,proto3" json:"version,omitempty"`
	Nodes     []*TopologyNode `protobuf:"bytes,2,rep,name=nodes,proto3" json:"nodes,omitempty"`
	UpdatedAt int64           `protobuf:"varint,3,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at,omitempty"`
	// contains filtered or unexported fields
}

func (*TopologySyncResponse) Descriptor deprecated

func (*TopologySyncResponse) Descriptor() ([]byte, []int)

Deprecated: Use TopologySyncResponse.ProtoReflect.Descriptor instead.

func (*TopologySyncResponse) GetNodes

func (x *TopologySyncResponse) GetNodes() []*TopologyNode

func (*TopologySyncResponse) GetUpdatedAt

func (x *TopologySyncResponse) GetUpdatedAt() int64

func (*TopologySyncResponse) GetVersion

func (x *TopologySyncResponse) GetVersion() int64

func (*TopologySyncResponse) ProtoMessage

func (*TopologySyncResponse) ProtoMessage()

func (*TopologySyncResponse) ProtoReflect

func (x *TopologySyncResponse) ProtoReflect() protoreflect.Message

func (*TopologySyncResponse) Reset

func (x *TopologySyncResponse) Reset()

func (*TopologySyncResponse) String

func (x *TopologySyncResponse) String() string

type UnimplementedMeshServiceServer

type UnimplementedMeshServiceServer struct{}

UnimplementedMeshServiceServer must be embedded to have forward compatible implementations.

NOTE: this should be embedded by value instead of pointer to avoid a nil pointer dereference when methods are called.

func (UnimplementedMeshServiceServer) GetHealth

func (UnimplementedMeshServiceServer) GetNodeInfo

func (UnimplementedMeshServiceServer) GetTopology

func (UnimplementedMeshServiceServer) Ping

func (UnimplementedMeshServiceServer) SyncTopology

type UnsafeMeshServiceServer

type UnsafeMeshServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeMeshServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to MeshServiceServer will result in compilation errors.

Directories

Path Synopsis
proto

Jump to

Keyboard shortcuts

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