package bridge
import "github.com/Microsoft/hcsshim/internal/guest/bridge"
Package bridge defines the bridge struct, which implements the control loop and functions of the GCS's bridge client.
Index ¶
- type Bridge
- func (b *Bridge) AssignHandlers(mux *Mux, host *hcsv2.Host)
- func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser) error
- func (b *Bridge) PublishNotification(n *prot.ContainerNotification)
- type Handler
- type HandlerFunc
- type Mux
- func NewBridgeMux() *Mux
- func (mux *Mux) Handle(id prot.MessageIdentifier, ver prot.ProtocolVersion, handler Handler)
- func (mux *Mux) HandleFunc(id prot.MessageIdentifier, ver prot.ProtocolVersion, handler func(*Request) (RequestResponse, error))
- func (mux *Mux) Handler(r *Request) Handler
- func (mux *Mux) ServeMsg(r *Request) (RequestResponse, error)
- type Request
- type RequestResponse
Types ¶
type Bridge ¶
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:
Request/Response where using the `Handler` a request of a given type will be dispatched to the appropriate handler and an appropriate response will respond to exactly that request that caused the dispatch.
`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 ¶
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 ¶
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 ¶
func (b *Bridge) PublishNotification(n *prot.ContainerNotification)
PublishNotification writes a specific notification to the bridge.
type Handler ¶
type Handler interface { ServeMsg(*Request) (RequestResponse, error) }
Handler responds to a bridge request.
func UnknownMessageHandler ¶
func UnknownMessageHandler() Handler
UnknownMessageHandler creates a default HandlerFunc out of the UnknownMessage handler logic.
type HandlerFunc ¶
type HandlerFunc func(*Request) (RequestResponse, error)
HandlerFunc is an adapter to use functions as handlers.
func (HandlerFunc) ServeMsg ¶
func (f HandlerFunc) ServeMsg(r *Request) (RequestResponse, error)
ServeMsg calls f(w, r).
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux is a protocol multiplexer for request response pairs following the bridge protocol.
func NewBridgeMux ¶
func NewBridgeMux() *Mux
NewBridgeMux creates a default bridge multiplexer.
func (*Mux) Handle ¶
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 ¶
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 ¶
Handler returns the handler to use for the given request type.
func (*Mux) ServeMsg ¶
func (mux *Mux) ServeMsg(r *Request) (RequestResponse, error)
ServeMsg dispatches the request to the handler whose type matches the request type.
type Request ¶
type Request struct { // Context is the request context received from the bridge. Context context.Context // Header is the wire format message header that preceded the message for // this request. Header *prot.MessageHeader // ContainerID is the id of the container that this message corresponds 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 ¶
type RequestResponse interface { Base() *prot.MessageResponseBase }
RequestResponse is the base response for any bridge message request.
func UnknownMessage ¶
func UnknownMessage(r *Request) (RequestResponse, error)
UnknownMessage represents the default handler logic for an unmatched request type sent from the bridge.
Source Files ¶
- Version
- v0.12.9 (latest)
- Published
- Oct 30, 2024
- Platform
- linux/amd64
- Imports
- 27 packages
- Last checked
- 14 hours ago –
Tools for package owners.