leaderproxy

package
v0.13.8 Latest Latest
Warning

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

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

Documentation

Overview

Package leaderproxy provides a gRPC interceptor that proxies requests to the leader node.

Index

Constants

View Source
const (
	// PreferLeaderMeta is the metadata key for the Prefer-Leader header.
	PreferLeaderMeta = "x-webmesh-prefer-leader"
	// ProxiedFromMeta is the metadata key for the Proxied-From header.
	ProxiedFromMeta = "x-webmesh-proxied-from"
	// ProxiedForMeta is the metadata key for the Proxied-For header.
	ProxiedForMeta = "x-webmesh-proxied-for"
)

Variables

View Source
var MethodPolicyMap = map[string]MethodPolicy{

	v1.Membership_Join_FullMethodName:                RequireLeader,
	v1.Membership_Update_FullMethodName:              RequireLeader,
	v1.Membership_Leave_FullMethodName:               RequireLeader,
	v1.Membership_Apply_FullMethodName:               RequireLeader,
	v1.Membership_SubscribePeers_FullMethodName:      AllowNonLeader,
	v1.Membership_GetCurrentConsensus_FullMethodName: AllowNonLeader,

	v1.Node_GetStatus_FullMethodName:            RequireLocal,
	v1.Node_NegotiateDataChannel_FullMethodName: RequireLocal,

	v1.StorageQueryService_Query_FullMethodName:     AllowNonLeader,
	v1.StorageQueryService_Publish_FullMethodName:   AllowNonLeader,
	v1.StorageQueryService_Subscribe_FullMethodName: RequireLocal,

	v1.Mesh_GetNode_FullMethodName:      AllowNonLeader,
	v1.Mesh_ListNodes_FullMethodName:    AllowNonLeader,
	v1.Mesh_GetMeshGraph_FullMethodName: AllowNonLeader,

	v1.WebRTC_StartDataChannel_FullMethodName: AllowNonLeader,

	v1.Admin_PutRole_FullMethodName:    RequireLeader,
	v1.Admin_DeleteRole_FullMethodName: RequireLeader,
	v1.Admin_GetRole_FullMethodName:    AllowNonLeader,
	v1.Admin_ListRoles_FullMethodName:  AllowNonLeader,

	v1.Admin_PutRoleBinding_FullMethodName:    RequireLeader,
	v1.Admin_DeleteRoleBinding_FullMethodName: RequireLeader,
	v1.Admin_GetRoleBinding_FullMethodName:    AllowNonLeader,
	v1.Admin_ListRoleBindings_FullMethodName:  AllowNonLeader,

	v1.Admin_PutGroup_FullMethodName:    RequireLeader,
	v1.Admin_DeleteGroup_FullMethodName: RequireLeader,
	v1.Admin_GetGroup_FullMethodName:    AllowNonLeader,
	v1.Admin_ListGroups_FullMethodName:  AllowNonLeader,

	v1.Admin_PutNetworkACL_FullMethodName:    RequireLeader,
	v1.Admin_DeleteNetworkACL_FullMethodName: RequireLeader,
	v1.Admin_GetNetworkACL_FullMethodName:    AllowNonLeader,
	v1.Admin_ListNetworkACLs_FullMethodName:  AllowNonLeader,

	v1.Admin_PutRoute_FullMethodName:    RequireLeader,
	v1.Admin_DeleteRoute_FullMethodName: RequireLeader,
	v1.Admin_GetRoute_FullMethodName:    AllowNonLeader,
	v1.Admin_ListRoutes_FullMethodName:  AllowNonLeader,

	v1.Admin_PutEdge_FullMethodName:    RequireLeader,
	v1.Admin_DeleteEdge_FullMethodName: RequireLeader,
	v1.Admin_GetEdge_FullMethodName:    AllowNonLeader,
	v1.Admin_ListEdges_FullMethodName:  AllowNonLeader,
}

MethodPolicyMap is a map of method names to their MethodPolicy.

Functions

func HasPreferLeaderMeta

func HasPreferLeaderMeta(ctx context.Context) bool

HasPreferLeaderMeta returns true if the context has the Prefer-Leader header set to true.

func ProxiedFor

func ProxiedFor(ctx context.Context) (string, bool)

ProxiedFor returns the node ID of the node that the request was proxied for. If the request was not proxied then false is returned.

func ProxiedFrom

func ProxiedFrom(ctx context.Context) (string, bool)

ProxiedFrom returns the node ID of the node that proxied the request. If the request was not proxied then false is returned.

func RouteRequiresInNetworkSource added in v0.3.0

func RouteRequiresInNetworkSource(route string) bool

RouteRequiresInNetworkSource returns true if the given route requires that the request is routed from a peer in the network.

Types

type Dialer added in v0.3.0

type Dialer interface {
	transport.LeaderDialer
	transport.NodeDialer
}

Dialer is the interface required for the leader proxy interceptor.

type Interceptor

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

Interceptor is the leaderproxy interceptor.

func New

func New(nodeID types.NodeID, consensus storage.Consensus, dialer Dialer, network context.Network) *Interceptor

New returns a new leader proxy interceptor.

func (*Interceptor) StreamInterceptor

func (i *Interceptor) StreamInterceptor() grpc.StreamServerInterceptor

StreamInterceptor returns a gRPC stream interceptor that proxies requests to the leader node.

func (*Interceptor) UnaryInterceptor

func (i *Interceptor) UnaryInterceptor() grpc.UnaryServerInterceptor

UnaryInterceptor returns a gRPC unary interceptor that proxies requests to the leader node.

type MethodPolicy

type MethodPolicy int

MethodPolicy defines the policy for routing requests to the leader.

const (
	// RequireLeader requires that the request is routed to the leader.
	RequireLeader MethodPolicy = iota
	// AllowNonLeader allows the request to be routed to a non-leader.
	AllowNonLeader
	// RequireLocal requires that the request is routed to the local node.
	RequireLocal
)

Jump to

Keyboard shortcuts

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