ws

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(opts HandlerOpts) (http.Handler, error)

Types

type AuthFn

type AuthFn func(http *http.Request) error

func AuthFnPKITLS

func AuthFnPKITLS(rootCAs []*x509.Certificate) (AuthFn, error)

func AuthFnSharedTLS

func AuthFnSharedTLS(cert tls.Certificate) (AuthFn, error)

type Authenticator

type Authenticator interface {
	// Authenticate takes a request, authenticates it and returns a manager that
	// will handle the request.
	// If err is of type ErrAuth, then the HTTP response is returned with
	// ErrAuth.HTTPStatus code and following JSON body:
	// { "message" : "ErrAuth.Message" }
	// If err is of any other type, the error is logged and a 500 code is
	// returned to the client.
	Authenticate(r *http.Request) (*Manager, error)
}

type Cluster

type Cluster interface {
	Get() string
}

type ConfigClient

type ConfigClient struct {
	Status relay.StatusServiceClient
	Node   admin.NodeServiceClient
	Event  relay.EventServiceClient
}

type ConfigRegisterer

type ConfigRegisterer struct{}

ConfigRegisterer is the Registerer to be added to a Negotiator object. Its only responsibility is to add a ConfigService to a peer.

func (*ConfigRegisterer) Register

func (c *ConfigRegisterer) Register(peer *wrpc.Peer, m *Manager) error

Register the "v1" config service.

type DefaultAuthenticator

type DefaultAuthenticator struct {
	Manager *Manager
	// Context is passed on the Manager.Run.
	// Use this context to shut down the manager.
	Context context.Context

	AuthFn AuthFn
}

func (*DefaultAuthenticator) Authenticate

func (d *DefaultAuthenticator) Authenticate(r *http.Request) (*Manager, error)

type DefaultCluster

type DefaultCluster struct{}

func (DefaultCluster) Get

func (d DefaultCluster) Get() string

type ErrAuth

type ErrAuth struct {
	HTTPStatus int
	Message    string
}

func (ErrAuth) Error

func (e ErrAuth) Error() string

type ErrConnClosed

type ErrConnClosed struct {
	Code int
}

func (ErrConnClosed) Error

func (e ErrConnClosed) Error() string

type Event

type Event struct {
	// EventType associated with the event.
	EventType
}

Event represents the event taking place.

func (Event) String

func (e Event) String() string

String will return the display name of the event enumeration.

type EventHandler

type EventHandler interface {
	// OnEvent executes when an event occurs from an EventStream.
	OnEvent(ctx context.Context, e Event) error
}

EventHandler interface represents an event.

type EventStream

type EventStream interface {
	// Name of the event stream.
	Name() string
	// Register will register and enable the event stream.
	// Registering a registered stream is a no-op.
	Register(ctx context.Context, cluster Cluster, handler EventHandler) error
	// Unregister will unregister and disable the event stream.
	// Un-registering an unregistered stream is a no-op.
	Unregister(ctx context.Context, cluster Cluster) error
}

EventStream interface represents the mechanism responsible for detecting and triggering events for a cluster.

type EventType

type EventType int

EventType represents the type of event.

const (
	// ReconfigureEvent is a event for indicating a payload reconfiguration should occur.
	ReconfigureEvent EventType = iota
)

type HandlerOpts

type HandlerOpts struct {
	Logger        *zap.Logger
	Authenticator Authenticator
	BaseServices  Registerer
}

type Manager

type Manager struct {
	Cluster Cluster
	// contains filtered or unexported fields
}

func NewManager

func NewManager(opts ManagerOpts) (*Manager, error)

func (*Manager) AddEventStream

func (m *Manager) AddEventStream(eventStream EventStream) error

AddEventStream registers an EventStream for streaming events to the streamer.

func (*Manager) AddPendingNode

func (m *Manager) AddPendingNode(node *Node) error

AddPendingNode registers a Node that hasn't been validated yet. In particular, wrpc nodes have to be actively listening in order to negotiate the services it will handle. In the meantime, the manager keeps them as "pending" A wrpc node isn't directly added to the `m.nodes` list. Instead, as soon as their connection is live, they're added to the `m.pendingNodes` list until it finishes some initialization.

func (*Manager) AddWebsocketNode

func (m *Manager) AddWebsocketNode(node *Node)

func (*Manager) FindNode

func (m *Manager) FindNode(remoteAddress string) *Node

FindNode returns a pointer to the node given a remote address or nil if not found.

func (*Manager) ReadConfig

func (m *Manager) ReadConfig() ManagerConfig

func (*Manager) UpdateConfig

func (m *Manager) UpdateConfig(c ManagerConfig)

type ManagerConfig

type ManagerConfig struct {
	DataPlaneRequisites []*grpcKongUtil.DataPlanePrerequisite
}

type ManagerOpts

type ManagerOpts struct {
	Ctx     context.Context
	Client  ConfigClient
	Cluster Cluster
	Logger  *zap.Logger
	Config  ManagerConfig

	DPConfigLoader         config.Loader
	DPVersionCompatibility config.VersionCompatibility
}

type NegotiationRegisterer

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

NegotiationRegisterer holds a map of services, each with a list of known versions and respective registerers.

func NewNegotiationRegisterer

func NewNegotiationRegisterer(logger *zap.Logger) (*NegotiationRegisterer, error)

func (*NegotiationRegisterer) AddService

func (n *NegotiationRegisterer) AddService(
	serviceName, version, message string,
	register Registerer,
) error

AddService associates a service name and version with a registerer object and a descriptive message. To be used during startup to define which services are available on a server.

func (*NegotiationRegisterer) Register

func (n *NegotiationRegisterer) Register(peer *wrpc.Peer, m *Manager) error

Register adds the version negotiation service to the peer.

type Node

type Node struct {
	ID       string
	Version  string
	Hostname string

	Logger *zap.Logger
	// contains filtered or unexported fields
}

func NewNode

func NewNode(opts nodeOpts) (*Node, error)

NewNode creates a new Node object with the given options after verifying them for consistency.

func (*Node) Close

func (n *Node) Close() error

Close ends the Node's lifetime and of its connection.

func (*Node) GetPluginList

func (n *Node) GetPluginList() ([]string, error)

GetPluginList receives the list of plugins the DP sends right after connection on the old WebSocket protocol.

func (*Node) RemoteAddr

func (n *Node) RemoteAddr() net.Addr

RemoteAddr returns the network address of the client.

type NodeList

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

func (*NodeList) Add

func (l *NodeList) Add(node *Node) error

func (*NodeList) All

func (l *NodeList) All() []*Node

func (*NodeList) FindNode

func (l *NodeList) FindNode(remoteAddress string) *Node

FindNode returns the node at the provided address, if any.

func (*NodeList) Remove

func (l *NodeList) Remove(node *Node) error

type Payload

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

func NewPayload

func NewPayload(opts PayloadOpts) (*Payload, error)

func (*Payload) ChangesFor

func (p *Payload) ChangesFor(hash, version string) (config.TrackedChanges, error)

func (*Payload) Payload

func (p *Payload) Payload(_ context.Context, version string) (config.Content, error)

func (*Payload) UpdateBinary

func (p *Payload) UpdateBinary(_ context.Context, c config.Content) error

type PayloadOpts

type PayloadOpts struct {
	VersionCompatibilityProcessor config.VersionCompatibility
	Logger                        *zap.Logger
}

type Registerer

type Registerer interface {
	// Register should be called when the negotiator chooses
	// a specific service.
	Register(peer *wrpc.Peer, m *Manager) error
}

Registerer is the object that handles registering a service to a wrpc.Peer A concrete implementation of this interface should hold any extra information the service will need to instantiate the service object, except from the Manager, which is provided on the Register method call.

type RelayEventStreamer

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

RelayEventStreamer represents the handling and notification for streamed events with the relay service.

func NewRelayEventStreamer

func NewRelayEventStreamer(opts RelayEventStreamerOpts) (*RelayEventStreamer, error)

NewRelayEventStreamer will create a new relay event streamer for communication of relay events.

func (*RelayEventStreamer) Name

func (r *RelayEventStreamer) Name() string

Name is the name of the relay event streamer.

func (*RelayEventStreamer) Register

func (r *RelayEventStreamer) Register(ctx context.Context, cluster Cluster, handler EventHandler) error

Register enables the relay event streamer and registers the handler. Calling enable when the stream is already registered is a no-op.

func (*RelayEventStreamer) Unregister

func (r *RelayEventStreamer) Unregister(ctx context.Context, _ Cluster) error

Unregister disables the relay event streamer and un-registers the event handler. Calling unregister when stream is already unregistered is a no-op.

type RelayEventStreamerOpts

type RelayEventStreamerOpts struct {
	// EventServiceClient from which to fetch the events.
	EventServiceClient relay.EventServiceClient
	// Logger is the defined logger for the relay event streamer.
	Logger *zap.Logger
}

RelayEventStreamerOpts represents the options to create a new instance of a RelayStreamEvent object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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