Documentation ¶
Overview ¶
Package component contains the methods and structures common to all components.
Index ¶
- Constants
- Variables
- func DefaultStartTask(conf *TaskConfig)
- type Component
- func (c *Component) AddContextFiller(f fillcontext.Filler)
- func (c *Component) AllowInsecureForCredentials() bool
- func (c *Component) ClaimIDs(ctx context.Context, ids ttnpb.Identifiers) error
- func (c *Component) Close()
- func (c *Component) ClusterAuthStreamHook() hooks.StreamHandlerMiddleware
- func (c *Component) ClusterAuthUnaryHook() hooks.UnaryHandlerMiddleware
- func (c *Component) ClusterTLS() bool
- func (c *Component) Context() context.Context
- func (c *Component) FillContext(ctx context.Context) context.Context
- func (c *Component) FromRequestContext(ctx context.Context) context.Context
- func (c *Component) GetBaseConfig(ctx context.Context) config.ServiceBase
- func (c *Component) GetPeer(ctx context.Context, role ttnpb.ClusterRole, ids ttnpb.Identifiers) (cluster.Peer, error)
- func (c *Component) GetPeerConn(ctx context.Context, role ttnpb.ClusterRole, ids ttnpb.Identifiers) (*grpc.ClientConn, error)
- func (c *Component) GetPeers(ctx context.Context, role ttnpb.ClusterRole) ([]cluster.Peer, error)
- func (c *Component) GetTLSClientConfig(ctx context.Context, opts ...TLSConfigOption) (*tls.Config, error)
- func (c *Component) GetTLSServerConfig(ctx context.Context, opts ...TLSConfigOption) (*tls.Config, error)
- func (c *Component) HTTPClient(ctx context.Context) (*http.Client, error)
- func (c *Component) HTTPTransport(ctx context.Context) (http.RoundTripper, error)
- func (c *Component) ListenTCP(address string) (Listener, error)
- func (c *Component) ListenUDP(address string) (*net.UDPConn, error)
- func (c *Component) LogDebug() bool
- func (c *Component) Logger() log.Stack
- func (c *Component) LoopbackConn() *grpc.ClientConn
- func (c *Component) RateLimiter() ratelimit.Interface
- func (c *Component) RegisterGRPC(s rpcserver.Registerer)
- func (c *Component) RegisterInterop(s interop.Registerer)
- func (c *Component) RegisterLivenessCheck(name string, check healthcheck.Check)
- func (c *Component) RegisterReadinessCheck(name string, check healthcheck.Check)
- func (c *Component) RegisterTask(conf *TaskConfig)
- func (c *Component) RegisterWeb(s web.Registerer)
- func (c *Component) Run() error
- func (c *Component) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (c *Component) Start() (err error)
- func (c *Component) StartTask(conf *TaskConfig)
- func (c *Component) UnclaimIDs(ctx context.Context, ids ttnpb.Identifiers) error
- func (c *Component) WithClusterAuth() grpc.CallOption
- type Config
- type ConfigurationServer
- func (c *ConfigurationServer) ListFrequencyPlans(ctx context.Context, req *ttnpb.ListFrequencyPlansRequest) (*ttnpb.ListFrequencyPlansResponse, error)
- func (c *ConfigurationServer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.ClientConn)
- func (c *ConfigurationServer) RegisterServices(s *grpc.Server)
- func (c *ConfigurationServer) Roles() []ttnpb.ClusterRole
- type Endpoint
- type Listener
- type Option
- type StartTaskFunc
- type TLSConfigOption
- type TLSConfigOptionFunc
- type TaskBackoffConfig
- type TaskBackoffIntervalFunc
- type TaskConfig
- type TaskFunc
- type TaskRestart
- type TaskStarter
Constants ¶
const ( DefaultTaskBackoffResetDuration = time.Minute DefaultTaskBackoffJitter = 0.1 )
Variables ¶
var ( // DefaultTaskBackoffIntervals are the default task backoff intervals. DefaultTaskBackoffIntervals = [...]time.Duration{ 10 * time.Millisecond, 50 * time.Millisecond, 100 * time.Millisecond, time.Second, } // DefaultTaskBackoffIntervalFunc is the default TaskBackoffIntervalFunc. DefaultTaskBackoffIntervalFunc = MakeTaskBackoffIntervalFunc(false, DefaultTaskBackoffResetDuration, DefaultTaskBackoffIntervals[:]...) // DefaultTaskBackoffConfig is the default task backoff config. DefaultTaskBackoffConfig = &TaskBackoffConfig{ Jitter: DefaultTaskBackoffJitter, IntervalFunc: DefaultTaskBackoffIntervalFunc, } // DialTaskBackoffIntervals are the default task backoff intervals for tasks using Dial. DialTaskBackoffIntervals = [...]time.Duration{ 100 * time.Millisecond, time.Second, 10 * time.Second, } // DialTaskBackoffIntervalFunc is the default TaskBackoffIntervalFunc for tasks using Dial. DialTaskBackoffIntervalFunc = MakeTaskBackoffIntervalFunc(false, DefaultTaskBackoffResetDuration, DialTaskBackoffIntervals[:]...) // DialTaskBackoffConfig is the default task backoff config for tasks using Dial. DialTaskBackoffConfig = &TaskBackoffConfig{ Jitter: DefaultTaskBackoffJitter, IntervalFunc: DialTaskBackoffIntervalFunc, } )
Functions ¶
func DefaultStartTask ¶ added in v3.9.1
func DefaultStartTask(conf *TaskConfig)
Types ¶
type Component ¶
type Component struct { FrequencyPlans *frequencyplans.Store KeyVault crypto.KeyVault // contains filtered or unexported fields }
Component is a base component for The Things Network cluster
func MustNew ¶
MustNew calls New and returns a new component or panics on an error. In most cases, you should just use New.
func (*Component) AddContextFiller ¶
func (c *Component) AddContextFiller(f fillcontext.Filler)
AddContextFiller adds the specified filler.
func (*Component) AllowInsecureForCredentials ¶
AllowInsecureForCredentials returns `true` if the component was configured to allow transmission of credentials over insecure transports.
func (*Component) ClaimIDs ¶
ClaimIDs claims the identifiers in the cluster. See package ../cluster for more information.
func (*Component) ClusterAuthStreamHook ¶
func (c *Component) ClusterAuthStreamHook() hooks.StreamHandlerMiddleware
ClusterAuthStreamHook ensuring the caller of an RPC is part of the cluster. If a call can't be identified as coming from the cluster, it will be discarded.
func (*Component) ClusterAuthUnaryHook ¶
func (c *Component) ClusterAuthUnaryHook() hooks.UnaryHandlerMiddleware
ClusterAuthUnaryHook ensuring the caller of an RPC is part of the cluster. If a call can't be identified as coming from the cluster, it will be discarded.
func (*Component) ClusterTLS ¶
ClusterTLS returns whether the cluster uses TLS for cluster connections.
func (*Component) FillContext ¶
FillContext fills the context. This method should only be used for request contexts.
func (*Component) FromRequestContext ¶ added in v3.10.1
FromRequestContext returns a derived context from the component context with key values from the request context. This can be used to decouple the lifetime from the request context while keeping security information.
func (*Component) GetBaseConfig ¶
func (c *Component) GetBaseConfig(ctx context.Context) config.ServiceBase
GetBaseConfig gets the base config of the component.
func (*Component) GetPeer ¶
func (c *Component) GetPeer(ctx context.Context, role ttnpb.ClusterRole, ids ttnpb.Identifiers) (cluster.Peer, error)
GetPeer returns a cluster peer with the given role and the given tags. See package ../cluster for more information.
func (*Component) GetPeerConn ¶
func (c *Component) GetPeerConn(ctx context.Context, role ttnpb.ClusterRole, ids ttnpb.Identifiers) (*grpc.ClientConn, error)
GetPeerConn returns a gRPC client connection to the cluster peer. See package ../cluster for more information.
func (*Component) GetPeers ¶
GetPeers returns cluster peers with the given role and the given tags. See package ../cluster for more information.
func (*Component) GetTLSClientConfig ¶
func (c *Component) GetTLSClientConfig(ctx context.Context, opts ...TLSConfigOption) (*tls.Config, error)
GetTLSClientConfig gets the component's client TLS config and applies the given options.
func (*Component) GetTLSServerConfig ¶
func (c *Component) GetTLSServerConfig(ctx context.Context, opts ...TLSConfigOption) (*tls.Config, error)
GetTLSServerConfig gets the component's server TLS config and applies the given options.
func (*Component) HTTPClient ¶ added in v3.12.0
HTTPClient returns a new *http.Client with a default timeout and a configured transport.
func (*Component) HTTPTransport ¶ added in v3.12.0
HTTPTransport returns a new http.RoundTripper with TLS client configuration.
func (*Component) ListenTCP ¶
ListenTCP listens on a TCP address and allows for TCP and TLS on the same port.
func (*Component) LoopbackConn ¶
func (c *Component) LoopbackConn() *grpc.ClientConn
LoopbackConn returns the loopback gRPC connection to the component. This conn must *not* be closed.
func (*Component) RateLimiter ¶ added in v3.12.0
func (*Component) RegisterGRPC ¶
func (c *Component) RegisterGRPC(s rpcserver.Registerer)
RegisterGRPC registers a gRPC subsystem to the component.
func (*Component) RegisterInterop ¶
func (c *Component) RegisterInterop(s interop.Registerer)
RegisterInterop registers an interop subsystem to the component.
func (*Component) RegisterLivenessCheck ¶
func (c *Component) RegisterLivenessCheck(name string, check healthcheck.Check)
RegisterLivenessCheck registers a liveness check for the component.
func (*Component) RegisterReadinessCheck ¶
func (c *Component) RegisterReadinessCheck(name string, check healthcheck.Check)
RegisterReadinessCheck registers a readiness check for the component.
func (*Component) RegisterTask ¶
func (c *Component) RegisterTask(conf *TaskConfig)
RegisterTask registers a task, optionally with restart policy and backoff, to be started after the component started.
func (*Component) RegisterWeb ¶
func (c *Component) RegisterWeb(s web.Registerer)
RegisterWeb registers a web subsystem to the component.
func (*Component) Run ¶
Run starts the component, and returns when a stop signal has been received by the process.
func (*Component) ServeHTTP ¶
func (c *Component) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves an HTTP request. If the Content-Type is application/grpc, the request is routed to gRPC. Otherwise, the request is routed to the default web server.
func (*Component) StartTask ¶
func (c *Component) StartTask(conf *TaskConfig)
func (*Component) UnclaimIDs ¶
UnclaimIDs unclaims the identifiers in the cluster. See package ../cluster for more information.
func (*Component) WithClusterAuth ¶
func (c *Component) WithClusterAuth() grpc.CallOption
WithClusterAuth that can be used to identify a component within a cluster.
type Config ¶
type Config struct {
config.ServiceBase `name:",squash" yaml:",inline"`
}
Config is the type of configuration for Components
type ConfigurationServer ¶
type ConfigurationServer struct {
// contains filtered or unexported fields
}
ConfigurationServer implements the Configuration RPC service.
func NewConfigurationServer ¶
func NewConfigurationServer(c *Component) *ConfigurationServer
NewConfigurationServer returns a new ConfigurationServer on top of the given component.
func (*ConfigurationServer) ListFrequencyPlans ¶
func (c *ConfigurationServer) ListFrequencyPlans(ctx context.Context, req *ttnpb.ListFrequencyPlansRequest) (*ttnpb.ListFrequencyPlansResponse, error)
ListFrequencyPlans implements the Configuration service's ListFrequencyPlans RPC.
func (*ConfigurationServer) RegisterHandlers ¶
func (c *ConfigurationServer) RegisterHandlers(s *runtime.ServeMux, conn *grpc.ClientConn)
RegisterHandlers registers the Configuration service handler.
func (*ConfigurationServer) RegisterServices ¶
func (c *ConfigurationServer) RegisterServices(s *grpc.Server)
RegisterServices registers the Configuration service.
func (*ConfigurationServer) Roles ¶
func (c *ConfigurationServer) Roles() []ttnpb.ClusterRole
Roles implements the rpcserver.Registerer interface. It just returns nil.
type Endpoint ¶
type Endpoint interface { Address() string Protocol() string Listen(Listener) (net.Listener, error) }
Endpoint represents an endpoint that can be listened on.
func NewTCPEndpoint ¶
NewTCPEndpoint returns a new TCP endpoint.
func NewTLSEndpoint ¶
func NewTLSEndpoint(address, protocol string, configOpts ...TLSConfigOption) Endpoint
NewTLSEndpoint returns a new TLS endpoint.
type Listener ¶
type Listener interface { TLS(opts ...TLSConfigOption) (net.Listener, error) TCP() (net.Listener, error) Addr() net.Addr Close() error }
Listener that accepts multiple protocols on the same port
type Option ¶
type Option func(*Component)
Option allows extending the component when it is instantiated with New.
func WithBaseConfigGetter ¶
func WithBaseConfigGetter(f func(ctx context.Context) config.ServiceBase) Option
WithBaseConfigGetter returns an option that overrides the component's function for getting the base config. This allows overriding the configuration with information in the context.
func WithClusterNew ¶
func WithClusterNew(f func(ctx context.Context, config *cluster.Config, options ...cluster.Option) (cluster.Cluster, error)) Option
WithClusterNew returns an option that overrides the component's function for setting up the cluster. This allows extending the cluster configuration with custom logic based on information in the context.
func WithGRPCLogger ¶ added in v3.12.0
WithGRPCLogger returns an option that overrides the component's gRPC logger.
func WithTaskStarter ¶ added in v3.9.1
func WithTaskStarter(s TaskStarter) Option
WithTaskStarter returns an option that overrides the component's TaskStarter for starting tasks.
type StartTaskFunc ¶ added in v3.9.1
type StartTaskFunc func(*TaskConfig)
func (StartTaskFunc) StartTask ¶ added in v3.9.1
func (f StartTaskFunc) StartTask(conf *TaskConfig)
type TLSConfigOption ¶
type TLSConfigOption interface {
// contains filtered or unexported methods
}
TLSConfigOption provides customization for TLS configuration.
func WithNextProtos ¶
func WithNextProtos(protos ...string) TLSConfigOption
WithNextProtos appends the given protocols to NextProtos.
func WithTLSCertificates ¶
func WithTLSCertificates(certificates ...tls.Certificate) TLSConfigOption
WithTLSCertificates sets TLS certificates.
func WithTLSClientAuth ¶
func WithTLSClientAuth(auth tls.ClientAuthType, cas *x509.CertPool, verify func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error) TLSConfigOption
WithTLSClientAuth sets TLS client authentication options.
type TLSConfigOptionFunc ¶
TLSConfigOptionFunc is a TLSConfigOption.
type TaskBackoffConfig ¶ added in v3.9.1
type TaskBackoffConfig struct { Jitter float64 IntervalFunc TaskBackoffIntervalFunc }
TaskBackoffConfig represents task backoff configuration.
type TaskBackoffIntervalFunc ¶ added in v3.9.2
type TaskBackoffIntervalFunc func(ctx context.Context, executionDuration time.Duration, invocation uint, err error) time.Duration
TaskBackoffIntervalFunc is a function that decides the backoff interval based on the attempt history. invocation is a counter, which starts at 1 and is incremented after each task function invocation.
func MakeTaskBackoffIntervalFunc ¶ added in v3.9.2
func MakeTaskBackoffIntervalFunc(onFailure bool, resetDuration time.Duration, intervals ...time.Duration) TaskBackoffIntervalFunc
MakeTaskBackoffIntervalFunc returns a new TaskBackoffIntervalFunc.
type TaskConfig ¶ added in v3.9.1
type TaskConfig struct { Context context.Context ID string Func TaskFunc Done func() Restart TaskRestart Backoff *TaskBackoffConfig }
type TaskRestart ¶
type TaskRestart uint8
TaskRestart defines a task's restart policy.
const ( // TaskRestartNever denotes a restart policy that never restarts tasks after success or failure. TaskRestartNever TaskRestart = iota // TaskRestartAlways denotes a restart policy that always restarts tasks, on success and failure. TaskRestartAlways // TaskRestartOnFailure denotes a restart policy that restarts tasks on failure. TaskRestartOnFailure )
type TaskStarter ¶ added in v3.9.1
type TaskStarter interface { // StartTask starts the specified task function, optionally with restart policy and backoff. StartTask(*TaskConfig) }