Documentation ¶
Overview ¶
Package cluster defines an interface for clustering network components and provides a simple implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CustomNew func(ctx context.Context, config *Config, options ...Option) (Cluster, error)
CustomNew allows you to replace the clustering implementation. New will call CustomNew if not nil.
var HookName = "cluster-hook"
HookName is the name of the hook used to verify the identity of incoming calls within a cluster.
Functions ¶
This section is empty.
Types ¶
type Cluster ¶
type Cluster interface { // Join the cluster. Join() error // Leave the cluster. Leave() error // GetPeers returns peers with the given role. GetPeers(ctx context.Context, role ttnpb.ClusterRole) ([]Peer, error) // GetPeer returns a peer with the given role, and a responsibility for the // given identifiers. If the identifiers are nil, this function returns a random // peer from the list that would be returned by GetPeers. GetPeer(ctx context.Context, role ttnpb.ClusterRole, ids EntityIdentifiers) (Peer, error) // GetPeerConn returns the gRPC client connection of a peer, if the peer is available as // as per GetPeer. GetPeerConn(ctx context.Context, role ttnpb.ClusterRole, ids EntityIdentifiers) (*grpc.ClientConn, error) // ClaimIDs can be used to indicate that the current peer takes // responsibility for entities identified by ids. // Claiming an already claimed ID will transfer the claim (without notifying // the previous holder). Releasing a non-claimed ID is a no-op. An error may // only be returned if the claim/unclaim couldn't be communicated with the cluster. ClaimIDs(ctx context.Context, ids EntityIdentifiers) error // UnclaimIDs can be used to indicate that the current peer // releases responsibility for entities identified by ids. // The specified context ctx may already be done before calling this function. UnclaimIDs(ctx context.Context, ids EntityIdentifiers) error // TLS returns whether the cluster uses TLS for cluster connections. TLS() bool // Auth returns a gRPC CallOption that can be used to identify the component within the cluster. Auth() grpc.CallOption // WithVerifiedSource verifies if the caller providing this context is a component from the cluster, and returns a // new context with that information. WithVerifiedSource(context.Context) context.Context }
Cluster interface that is implemented by all different clustering implementations.
func New ¶
New instantiates a new clustering implementation. The basic clustering implementation allows for a cluster setup with a single-instance deployment of each component (GS/NS/AS/JS). Network operators can use their own clustering logic, which can be activated by setting the CustomNew variable.
type Config ¶
type Config struct { Join []string `name:"join" description:"Addresses of cluster peers to join"` Name string `name:"name" description:"Name of the current cluster peer (default: $HOSTNAME)"` Address string `name:"address" description:"Address to use for cluster communication"` IdentityServer string `name:"identity-server" description:"Address for the Identity Server"` GatewayServer string `name:"gateway-server" description:"Address for the Gateway Server"` NetworkServer string `name:"network-server" description:"Address for the Network Server"` ApplicationServer string `name:"application-server" description:"Address for the Application Server"` JoinServer string `name:"join-server" description:"Address for the Join Server"` CryptoServer string `name:"crypto-server" description:"Address for the Crypto Server"` PacketBrokerAgent string `name:"packet-broker-agent" description:"Address of the Packet Broker Agent"` DeviceRepository string `name:"device-repository" description:"Address for the Device Repository"` GatewayConfigurationServer string `name:"gateway-configuration-server" description:"Address for the Gateway Configuration Server"` //nolint:lll DeviceClaimingServer string `name:"device-claiming-server" description:"Address for the Device Claiming Server"` //nolint:lll TLS bool `name:"tls" description:"Do cluster gRPC over TLS"` TLSServerName string `name:"tls-server-name" description:"Server name to use in TLS handshake to cluster peers"` //nolint:lll Keys []string `` //nolint:lll /* 146-byte string literal not displayed */ }
Config represents clustering configuration.
type EntityIdentifiers ¶ added in v3.12.2
type EntityIdentifiers interface { // GetEntityIdentifiers wraps the identifiers in a *ttnpb.EntityIdentifiers. // This must return a nil *ttnpb.EntityIdentifiers for nil identifiers (it must not panic). GetEntityIdentifiers() *ttnpb.EntityIdentifiers }
EntityIdentifiers are types from which we can get *ttnpb.EntityIdentifiers.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option to apply at cluster initialization.
func WithConn ¶
func WithConn(conn *grpc.ClientConn) Option
WithConn bypasses the standard mechanism for connecting to the "self" peer.
func WithDialOptions ¶ added in v3.12.2
func WithDialOptions(f func(ctx context.Context) []grpc.DialOption) Option
WithDialOptions sets the default dial options for connections to cluster peers.
func WithServices ¶
func WithServices(services ...interface{ Roles() []ttnpb.ClusterRole }) Option
WithServices registers the given services on the "self" peer.
func WithTLSConfig ¶
WithTLSConfig sets the TLS config to use in cluster connections.
type Peer ¶
type Peer interface { // Name of the peer Name() string // gRPC ClientConn to the peer (if available) Conn() (*grpc.ClientConn, error) // Roles announced by the peer Roles() []ttnpb.ClusterRole // HasRole returns true iff the peer has the given role HasRole(ttnpb.ClusterRole) bool // Tags announced by the peer Tags() map[string]string }
Peer interface