bridge

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 27 Imported by: 1

Documentation

Overview

Package bridge defines the bridge struct, which implements the control loop and functions of the GCS's bridge client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge added in v0.3.3

type Bridge struct {
	// Handler to invoke when messages are received.
	Handler Handler
	// EnableV4 enables the v4+ bridge and the schema v2+ interfaces.
	EnableV4 bool
	// contains filtered or unexported fields
}

Bridge defines the bridge client in the GCS. It acts in many ways analogous to go's `http` package and multiplexer.

It has two fundamentally different dispatch options:

  1. Request/Response where using the `Handler` a request of a given type will be dispatched to the apprpriate handler and an appropriate response will respond to exactly that request that caused the dispatch.
  1. `PublishNotification` where a notification that was not initiated by a request from any client can be written to the bridge at any time in any order.

func (*Bridge) AssignHandlers added in v0.3.3

func (b *Bridge) AssignHandlers(mux *Mux, gcs core.Core, host *hcsv2.Host)

AssignHandlers creates and assigns the appropriate bridge events to be listen for and intercepted on `mux` before forwarding to `gcs` for handling.

func (*Bridge) ListenAndServe added in v0.3.3

func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser) error

ListenAndServe connects to the bridge transport, listens for messages and dispatches the appropriate handlers to handle each event in an asynchronous manner.

func (*Bridge) PublishNotification added in v0.3.3

func (b *Bridge) PublishNotification(n *prot.ContainerNotification)

PublishNotification writes a specific notification to the bridge.

type Handler added in v0.3.3

type Handler interface {
	ServeMsg(*Request) (RequestResponse, error)
}

Handler responds to a bridge request.

func UnknownMessageHandler added in v0.3.9

func UnknownMessageHandler() Handler

UnknownMessageHandler creates a default HandlerFunc out of the UnknownMessage handler logic.

type HandlerFunc added in v0.3.3

type HandlerFunc func(*Request) (RequestResponse, error)

HandlerFunc is an adapter to use functions as handlers.

func (HandlerFunc) ServeMsg added in v0.3.3

func (f HandlerFunc) ServeMsg(r *Request) (RequestResponse, error)

ServeMsg calls f(w, r).

type Mux added in v0.3.3

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

Mux is a protocol multiplexer for request response pairs following the bridge protocol.

func NewBridgeMux added in v0.3.3

func NewBridgeMux() *Mux

NewBridgeMux creates a default bridge multiplexer.

func (*Mux) Handle added in v0.3.3

func (mux *Mux) Handle(id prot.MessageIdentifier, ver prot.ProtocolVersion, handler Handler)

Handle registers the handler for the given message id and protocol version.

func (*Mux) HandleFunc added in v0.3.3

func (mux *Mux) HandleFunc(id prot.MessageIdentifier, ver prot.ProtocolVersion, handler func(*Request) (RequestResponse, error))

HandleFunc registers the handler function for the given message id and protocol version.

func (*Mux) Handler added in v0.3.3

func (mux *Mux) Handler(r *Request) Handler

Handler returns the handler to use for the given request type.

func (*Mux) ServeMsg added in v0.3.3

func (mux *Mux) ServeMsg(r *Request) (RequestResponse, error)

ServeMsg dispatches the request to the handler whose type matches the request type.

type Request added in v0.3.3

type Request struct {
	// Context is the request context received from the bridge.
	Context context.Context
	// Header is the wire format message header that preceeded the message for
	// this request.
	Header *prot.MessageHeader
	// ContainerID is the id of the container that this message cooresponds to.
	ContainerID string
	// ActivityID is the id of the specific activity for this request.
	ActivityID string
	// Message is the portion of the request that follows the `Header`. This is
	// a json encoded string that MUST contain `prot.MessageBase`.
	Message []byte
	// Version is the version of the protocol that `Header` and `Message` were
	// sent in.
	Version prot.ProtocolVersion
}

Request is the bridge request that has been sent.

type RequestResponse added in v0.4.0

type RequestResponse interface {
	Base() *prot.MessageResponseBase
}

RequestResponse is the base response for any bridge message request.

func UnknownMessage added in v0.3.9

func UnknownMessage(r *Request) (RequestResponse, error)

UnknownMessage represents the default handler logic for an unmatched request type sent from the bridge.

Jump to

Keyboard shortcuts

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