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.
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 }
func (b *Bridge) AssignHandlers(mux *Mux, 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 (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 (b *Bridge) PublishNotification(n *prot.ContainerNotification)
PublishNotification writes a specific notification to the bridge.
Handler responds to a bridge request.
type Handler interface { ServeMsg(*Request) (RequestResponse, error) }
func UnknownMessageHandler() Handler
UnknownMessageHandler creates a default HandlerFunc out of the UnknownMessage handler logic.
HandlerFunc is an adapter to use functions as handlers.
type HandlerFunc func(*Request) (RequestResponse, error)
func (f HandlerFunc) ServeMsg(r *Request) (RequestResponse, error)
ServeMsg calls f(w, r).
Mux is a protocol multiplexer for request response pairs following the bridge protocol.
type Mux struct {
// contains filtered or unexported fields
}
func NewBridgeMux() *Mux
NewBridgeMux creates a default bridge multiplexer.
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 *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 *Mux) Handler(r *Request) Handler
Handler returns the handler to use for the given request type.
func (mux *Mux) ServeMsg(r *Request) (RequestResponse, error)
ServeMsg dispatches the request to the handler whose type matches the request type.
Request is the bridge request that has been sent.
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 }
RequestResponse is the base response for any bridge message request.
type RequestResponse interface { Base() *prot.MessageResponseBase }
func UnknownMessage(r *Request) (RequestResponse, error)
UnknownMessage represents the default handler logic for an unmatched request type sent from the bridge.