services

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Overview

Package services contains the gRPC server for inter-node communication.

Index

Constants

View Source
const (
	ListenAddressEnvVar = "SERVICES_LISTEN_ADDRESS"
	CertFileEnvVar      = "SERVICES_TLS_CERT_FILE"
	KeyFileEnvVar       = "SERVICES_TLS_KEY_FILE"
	InsecureEnvVar      = "SERVICES_INSECURE"

	DefaultGRPCPort = 8443
)
View Source
const (
	LeaderProxyDisabledEnvVar  = "SERVICES_API_DISABLE_LEADER_PROXY"
	MeshEnabledEnvVar          = "SERVICES_API_MESH"
	AdminEnabledEnvVar         = "SERVICES_API_ADMIN"
	PeerDiscoveryEnabledEnvVar = "SERVICES_API_PEER_DISCOVERY"
	WebRTCEnabledEnvVar        = "SERVICES_API_WEBRTC"
	WebRTCSTUNServersEnvVar    = "SERVICES_API_STUN_SERVERS"
)
View Source
const (
	MeshDNSEnabledEnvVar             = "SERVICES_MESHDNS_ENABLED"
	MeshDNSListenUDPEnvVar           = "SERVICES_MESHDNS_LISTEN_UDP"
	MeshDNSListenTCPEnvVar           = "SERVICES_MESHDNS_LISTEN_TCP"
	MeshDNSTSIGKeyEnvVar             = "SERVICES_MESHDNS_TSIG_KEY"
	MeshDNSReusePortEnvVar           = "SERVICES_MESHDNS_REUSE_PORT"
	MeshDNSCompressionEnvVar         = "SERVICES_MESHDNS_COMPRESSION"
	MeshDNSRequestTimeoutEnvVar      = "SERVICES_MESHDNS_REQUEST_TIMEOUT"
	MeshDNSForwardersEnvVar          = "SERVICES_MESHDNS_FORWARDERS"
	MeshDNSSubscribeForwardersEnvVar = "SERVICES_MESHDNS_SUBSCRIBE_FORWARDERS"
	MeshDNSDisableForwardingEnvVar   = "SERVICES_MESHDNS_DISABLE_FORWARDING"
	MeshDNSCacheSizeEnvVar           = "SERVICES_MESHDNS_CACHE_SIZE"
)
View Source
const (
	MetricsEnabledEnvVar       = "SERVICES_METRICS_ENABLED"
	MetricsListenAddressEnvVar = "SERVICES_METRICS_LISTEN_ADDRESS"
	MetricsPathEnvVar          = "SERVICES_METRICS_PATH"
)
View Source
const (
	TURNEnabledEnvVar             = "SERVICES_TURN_ENABLED"
	TURNServerEndpointEnvVar      = "SERVICES_TURN_ENDPOINT"
	TURNServerPublicIPEnvVar      = "SERVICES_TURN_PUBLIC_IP"
	TURNServerListenAddressEnvVar = "SERVICES_TURN_LISTEN_ADDRESS"
	TURNServerPortEnvVar          = "SERVICES_TURN_SERVER_PORT"
	TURNServerRealmEnvVar         = "SERVICES_TURN_SERVER_REALM"
	TURNSTUNPortRangeEnvVar       = "SERVICES_TURN_STUN_PORT_RANGE"
	TURNCampfireEnabledEnvVar     = "SERVICES_TURN_CAMPFIRE_ENABLED"
)

Variables

This section is empty.

Functions

func InterceptorLogger

func InterceptorLogger() logging.Logger

InterceptorLogger returns a logging.Logger that logs to the given slog.Logger.

Types

type APIOptions

type APIOptions struct {
	// DisableLeaderProxy is true if the leader proxy should be disabled.
	DisableLeaderProxy bool `json:"disable-leader-proxy,omitempty" yaml:"disable-leader-proxy,omitempty" toml:"disable-leader-proxy,omitempty"`
	// Mesh is true if the mesh API should be registered.
	Mesh bool `json:"mesh,omitempty" yaml:"mesh,omitempty" toml:"mesh,omitempty"`
	// Admin is true if the admin API should be registered.
	Admin bool `json:"admin,omitempty" yaml:"admin,omitempty" toml:"admin,omitempty"`
	// PeerDiscovery is true if the peer discovery API should be registered.
	PeerDiscovery bool `json:"peer-discovery,omitempty" yaml:"peer-discovery,omitempty" toml:"peer-discovery,omitempty"`
	// WebRTC is true if the WebRTC API should be registered.
	WebRTC bool `json:"webrtc,omitempty" yaml:"webrtc,omitempty" toml:"webrtc,omitempty"`
	// STUNServers is a comma separated list of STUN servers to use if the WebRTC API is enabled.
	STUNServers string `json:"stun-servers,omitempty" yaml:"stun-servers,omitempty" toml:"stun-servers,omitempty"`
}

APIOptions are the options for which APIs to register and expose.

func NewAPIOptions

func NewAPIOptions() *APIOptions

NewAPIOptions creates a new APIOptions with default values.

func (*APIOptions) BindFlags

func (o *APIOptions) BindFlags(fs *flag.FlagSet, prefix ...string)

BindFlags binds the flags. The options are returned

func (*APIOptions) Validate

func (o *APIOptions) Validate() error

Validate validates the options.

type MeshDNSOptions

type MeshDNSOptions struct {
	// Enabled enables mesh DNS.
	Enabled bool `yaml:"enabled,omitempty" json:"enabled,omitempty" toml:"enabled,omitempty"`
	// ListenUDP is the UDP address to listen on.
	ListenUDP string `yaml:"listen-udp,omitempty" json:"listen-udp,omitempty" toml:"listen-udp,omitempty"`
	// ListenTCP is the address to listen on for TCP DNS requests.
	ListenTCP string `json:"listen-tcp,omitempty" yaml:"listen-tcp,omitempty" toml:"listen-tcp,omitempty"`
	// ReusePort sets the number of listeners to start on each port.
	// This is only supported on Linux.
	ReusePort int `json:"reuse-port,omitempty" yaml:"reuse-port,omitempty" toml:"reuse-port,omitempty"`
	// EnableCompression is true if DNS compression should be enabled.
	EnableCompression bool `json:"compression,omitempty" yaml:"compression,omitempty" toml:"compression,omitempty"`
	// RequestTimeout is the timeout for DNS requests.
	RequestTimeout time.Duration `json:"request-timeout,omitempty" yaml:"request-timeout,omitempty" toml:"request-timeout,omitempty"`
	// Forwarders are the DNS forwarders to use. If empty, the system DNS servers will be used.
	Forwarders []string `json:"forwarders,omitempty" yaml:"forwarders,omitempty" toml:"forwarders,omitempty"`
	// SubscribeForwarders will subscribe to new nodes that are able to forward requests for other meshes.
	// These forwarders will be placed at the bottom of the forwarders list.
	SubscribeForwarders bool `json:"subscribe-forwarders,omitempty" yaml:"subscribe-forwarders,omitempty" toml:"subscribe-forwarders,omitempty"`
	// DisableForwarding disables forwarding requests entirely.
	DisableForwarding bool `json:"disable-forwarding,omitempty" yaml:"disable-forwarding,omitempty" toml:"disable-forwarding,omitempty"`
	// CacheSize is the size of the remote DNS cache.
	CacheSize int `json:"cache-size,omitempty" yaml:"cache-size,omitempty" toml:"cache-size,omitempty"`
}

MeshDNSOptions are the mesh DNS options.

func NewMeshDNSOptions

func NewMeshDNSOptions() *MeshDNSOptions

NewMeshDNSOptions creates a new set of mesh DNS options.

func (*MeshDNSOptions) BindFlags

func (o *MeshDNSOptions) BindFlags(fs *flag.FlagSet, prefix ...string)

BindFlags binds the flags for the mesh DNS options.

func (*MeshDNSOptions) Validate

func (o *MeshDNSOptions) Validate() error

Validate validates the mesh DNS options.

type MetricsOptions

type MetricsOptions struct {
	// Enabled is true if metrics should be enabled.
	Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty" toml:"enabled,omitempty"`
	// MetricsListenAddress is the address to listen on for metrics.
	ListenAddress string `json:"listen-address,omitempty" yaml:"listen-address,omitempty" toml:"listen-address,omitempty"`
	// MetricsPath is the path to serve metrics on.
	Path string `json:"path,omitempty" yaml:"path,omitempty" toml:"path,omitempty"`
}

Metrics are options for exposing metrics.

func NewMetricsOptions

func NewMetricsOptions() *MetricsOptions

NewMetricsOptions creates a new MetricsOptions with default values.

func (*MetricsOptions) BindFlags

func (o *MetricsOptions) BindFlags(fs *flag.FlagSet, prefix ...string)

BindFlags binds the flags.

type Options

type Options struct {
	// ListenAddress is the address to listen on.
	ListenAddress string `json:"listen-address,omitempty" yaml:"listen-address,omitempty" toml:"listen-address,omitempty"`
	// TLSCertFile is the path to the TLS certificate file.
	TLSCertFile string `json:"tls-cert-file,omitempty" yaml:"tls-cert-file,omitempty" toml:"tls-cert-file,omitempty"`
	// TLSKeyFile is the path to the TLS key file.
	TLSKeyFile string `json:"tls-key-file,omitempty" yaml:"tls-key-file,omitempty" toml:"tls-key-file,omitempty"`
	// Insecure is true if the transport is insecure.
	Insecure bool `json:"insecure,omitempty" yaml:"insecure,omitempty" toml:"insecure,omitempty"`
	// API options
	API *APIOptions `json:"api,omitempty" yaml:"api,omitempty" toml:"api,omitempty"`
	// MeshDNS options
	MeshDNS *MeshDNSOptions `json:"mesh-dns,omitempty" yaml:"mesh-dns,omitempty" toml:"mesh-dns,omitempty"`
	// TURN options
	TURN *TURNOptions `json:"turn,omitempty" yaml:"turn,omitempty" toml:"turn,omitempty"`
	// Metrics options
	Metrics *MetricsOptions `json:"metrics,omitempty" yaml:"metrics,omitempty" toml:"metrics,omitempty"`
	// Dashboard options
	Dashboard *dashboard.Options `json:"dashboard,omitempty" yaml:"dashboard,omitempty" toml:"dashboard,omitempty"`
	// Campfire options
	Campfire *campfire.Options `json:"campfire,omitempty" yaml:"campfire,omitempty" toml:"campfire,omitempty"`
}

Options contains the configuration for the gRPC server.

func NewOptions

func NewOptions(grpcPort int) *Options

NewOptions returns new Options with sensible defaults. If grpcPort is 0 the default port is used.

func (*Options) BindFlags

func (o *Options) BindFlags(fs *flag.FlagSet, prefix ...string)

BindFlags binds the gRPC options to the given flag set.

func (*Options) ListenPort

func (o *Options) ListenPort() (int, error)

ListenPort returns the port the options are configured to listen on.

func (*Options) ServerOptions

func (o *Options) ServerOptions(store mesh.Mesh, log *slog.Logger) (srvrOptions []grpc.ServerOption, err error)

ServerOptions converts the options to gRPC server options.

func (*Options) TLSConfig

func (o *Options) TLSConfig() (*tls.Config, error)

TLSConfig returns the TLS configuration.

func (*Options) ToFeatureSet

func (o *Options) ToFeatureSet() []v1.Feature

ToFeatureSet converts the options to a feature set.

func (*Options) Validate

func (o *Options) Validate() error

Validate validates the options.

type Server

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

Server is the gRPC server.

func NewServer

func NewServer(store mesh.Mesh, o *Options) (*Server, error)

NewServer returns a new Server.

func (*Server) Check

Check implements grpc.health.v1.HealthServer.

func (*Server) GetServiceInfo

func (s *Server) GetServiceInfo() map[string]grpc.ServiceInfo

GetServiceInfo implements reflection.ServiceInfoProvider.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the gRPC server and optional metrics server then blocks until the gRPC server exits.

func (*Server) RegisterService

func (s *Server) RegisterService(desc *grpc.ServiceDesc, impl any)

RegisterService implements grpc.RegistrarService.

func (*Server) Stop

func (s *Server) Stop()

Stop stops the gRPC server gracefully. You cannot use the server again after calling Stop.

func (*Server) Watch

Watch implements grpc.health.v1.HealthServer.

type TURNOptions

type TURNOptions struct {
	// Enabled enables the TURN server.
	Enabled bool `json:"enabled,omitempty" yaml:"enabled,omitempty" toml:"enabled,omitempty"`
	// Endpoint is the endpoint to advertise for the TURN server. If empty, the public IP and listen port is used.
	Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty" toml:"endpoint,omitempty"`
	// PublicIP is the address advertised for STUN requests.
	PublicIP string `json:"public-ip,omitempty" yaml:"public-ip,omitempty" toml:"public-ip,omitempty"`
	// ListenAddress is the address to listen on for TURN connections.
	ListenAddress string `json:"listen-address,omitempty" yaml:"listen-address,omitempty" toml:"listen-address,omitempty"`
	// ListenPort is the port to listen on for TURN connections.
	ListenPort int `json:"listen-port,omitempty" yaml:"listen-port,omitempty" toml:"listen-port,omitempty"`
	// ServerRealm is the realm used for TURN server authentication.
	ServerRealm string `json:"realm,omitempty" yaml:"realm,omitempty" toml:"realm,omitempty"`
	// STUNPortRange is the port range to use for STUN.
	STUNPortRange string `json:"stun-port-range,omitempty" yaml:"stun-port-range,omitempty" toml:"stun-port-range,omitempty"`
	// CampfireEnabled enables handling campfire packets on the TURN server.
	CampfireEnabled bool `json:"campfire-enabled,omitempty" yaml:"campfire-enabled,omitempty" toml:"campfire-enabled,omitempty"`
}

TURNOptions are the TURN Server options.

func NewTURNOptions

func NewTURNOptions() *TURNOptions

NewTURNOptions creates a new TURNOptions with default values.

func (*TURNOptions) BindFlags

func (o *TURNOptions) BindFlags(fs *flag.FlagSet, prefix ...string)

BindFlags binds the flags.

func (*TURNOptions) Validate

func (o *TURNOptions) Validate() error

Validate validates the options.

Directories

Path Synopsis
Package admin provides the admin gRPC server.
Package admin provides the admin gRPC server.
Package campfire provides the campfire service to webmesh clients.
Package campfire provides the campfire service to webmesh clients.
Package dashboard contains a service that serves a web dashboard.
Package dashboard contains a service that serves a web dashboard.
Package leaderproxy provides a gRPC interceptor that proxies requests to the leader node.
Package leaderproxy provides a gRPC interceptor that proxies requests to the leader node.
Package meshapi contains the webmesh Mesh API service.
Package meshapi contains the webmesh Mesh API service.
Package meshdns contains the Mesh DNS server.
Package meshdns contains the Mesh DNS server.
Package node contains the webmesh node service.
Package node contains the webmesh node service.
Package peerdiscovery contains the webmesh PeerDiscovery API service.
Package peerdiscovery contains the webmesh PeerDiscovery API service.
Package rbac contains utilities for evaluating requests against roles.
Package rbac contains utilities for evaluating requests against roles.
Package turn contains the STUN/TURN server.
Package turn contains the STUN/TURN server.
Package webrtc contains the webmesh WebRTC service.
Package webrtc contains the webmesh WebRTC service.

Jump to

Keyboard shortcuts

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