func (c *Component) ClusterAuthUnaryHook() hooks.UnaryHandlerMiddleware {
	return func(next grpc.UnaryHandler) grpc.UnaryHandler {
		return func(ctx context.Context, req interface{}) (interface{}, error) {
			ctx = c.cluster.WithVerifiedSource(ctx)
			return next(ctx, req)
		}
	}
}
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.
package component
import (
	"context"
	"net"
	grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
	"go.thethings.network/lorawan-stack/v3/pkg/errors"
	"go.thethings.network/lorawan-stack/v3/pkg/log"
	"go.thethings.network/lorawan-stack/v3/pkg/metrics"
	"go.thethings.network/lorawan-stack/v3/pkg/rpcclient"
	"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/hooks"
	"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/rpclog"
	"go.thethings.network/lorawan-stack/v3/pkg/rpcserver"
	"google.golang.org/grpc"
)
func (c *Component) initGRPC() {
	if c.grpcLogger == nil {
		c.grpcLogger = c.logger.WithField("namespace", "grpc")
	}
	rpclog.ReplaceGrpcLogger(c.grpcLogger)
	c.grpc = rpcserver.New(
		c.ctx,
		rpcserver.WithContextFiller(c.FillContext),
		rpcserver.WithTrustedProxies(c.config.GRPC.TrustedProxies...),
		rpcserver.WithLogIgnoreMethods(c.config.GRPC.LogIgnoreMethods),
		rpcserver.WithRateLimiter(c.RateLimiter()),
	)
}
func (c *Component) setupGRPC() (err error) {
	for _, sub := range c.grpcSubsystems {
		sub.RegisterServices(c.grpc.Server)
	}
	metrics.InitializeServerMetrics(c.grpc.Server)
	c.logger.Debug("Starting loopback connection")
	c.loopback, err = rpcserver.StartLoopback(
		c.ctx, c.grpc.Server,
		rpcclient.DefaultDialOptions(
			log.NewContext(c.ctx, log.Noop),
		)...,
	)
	if err != nil {
		return errors.New("could not start loopback connection").WithCause(err)
	}
	c.logger.Debug("Setting up gRPC gateway")
	for _, sub := range c.grpcSubsystems {
		sub.RegisterHandlers(c.grpc.ServeMux, c.loopback)
	}
	return nil
}
func (c *Component) LoopbackConn() *grpc.ClientConn {
	return c.loopback
}
func (c *Component) serveGRPC(lis net.Listener) error {
	return c.grpc.Serve(lis)
}
func (c *Component) grpcEndpoints() []Endpoint {
	return []Endpoint{
		NewTCPEndpoint(c.config.GRPC.Listen, "gRPC"),
		NewTLSEndpoint(c.config.GRPC.ListenTLS, "gRPC", WithNextProtos("h2", "http/1.1")),
	}
}
func (c *Component) listenGRPC() (err error) {
	return c.serveOnEndpoints(c.grpcEndpoints(), (*Component).serveGRPC, "grpc")
}
func (c *Component) RegisterGRPC(s rpcserver.Registerer) {
	if c.grpc == nil {
		c.initGRPC()
	}
	c.grpcSubsystems = append(c.grpcSubsystems, s)
}
func (c *Component) WithClusterAuth() grpc.CallOption {
	return c.cluster.Auth()
}