Documentation
¶
Index ¶
- Variables
- type Action
- type DefaultHttpContext
- func (*DefaultHttpContext) OnHttpRequestBody(int, bool) Action
- func (*DefaultHttpContext) OnHttpRequestHeaders(int, bool) Action
- func (*DefaultHttpContext) OnHttpRequestTrailers(int) Action
- func (*DefaultHttpContext) OnHttpResponseBody(int, bool) Action
- func (*DefaultHttpContext) OnHttpResponseHeaders(int, bool) Action
- func (*DefaultHttpContext) OnHttpResponseTrailers(int) Action
- func (*DefaultHttpContext) OnHttpStreamDone()
- type DefaultRootContext
- func (*DefaultRootContext) NewHttpContext(uint32) HttpContext
- func (*DefaultRootContext) NewTcpContext(uint32) TcpContext
- func (*DefaultRootContext) OnPluginDone() bool
- func (*DefaultRootContext) OnPluginStart(int) OnPluginStartStatus
- func (*DefaultRootContext) OnQueueReady(uint32)
- func (*DefaultRootContext) OnTick()
- func (*DefaultRootContext) OnVMStart(int) OnVMStartStatus
- type DefaultTcpContext
- func (*DefaultTcpContext) OnDownstreamClose(PeerType)
- func (*DefaultTcpContext) OnDownstreamData(int, bool) Action
- func (*DefaultTcpContext) OnNewConnection() Action
- func (*DefaultTcpContext) OnStreamDone()
- func (*DefaultTcpContext) OnUpstreamClose(PeerType)
- func (*DefaultTcpContext) OnUpstreamData(int, bool) Action
- type HttpContext
- type OnPluginStartStatus
- type OnVMStartStatus
- type PeerType
- type RootContext
- type TcpContext
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorStatusNotFound means not found for various hostcalls. ErrorStatusNotFound = errors.New("error status returned by host: not found") // ErrorStatusNotFound means the arguments for a hostcall are invalid. ErrorStatusBadArgument = errors.New("error status returned by host: bad argument") // ErrorStatusNotFound means the target queue of DequeueSharedQueue call is empty. ErrorStatusEmpty = errors.New("error status returned by host: empty") // ErrorStatusNotFound means a given CAS value for SetSharedData is mismatched // with the current value. That indicates that other Wasm VMs has already succeeded // to set a value on the same key and the current CAS for the key is incremented. // Having retry logic in the face of this error is recommended. ErrorStatusCasMismatch = errors.New("error status returned by host: cas mismatch") // ErrorStatusNotFound indicates an internal falure in hosts. // In the face of this error, there's nothing we could do in the Wasm VM. // Recommend simply abort or panic then. ErrorInternalFailure = errors.New("error status returned by host: internal failure") )
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action uint32
Action represents the action which Wasm contexts expects hosts to take.
type DefaultHttpContext ¶ added in v0.3.0
type DefaultHttpContext struct{}
DefaultHttpContext provides the no-op implementation of HttpContext interface.
func (*DefaultHttpContext) OnHttpRequestBody ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpRequestBody(int, bool) Action
func (*DefaultHttpContext) OnHttpRequestHeaders ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpRequestHeaders(int, bool) Action
impl HttpContext
func (*DefaultHttpContext) OnHttpRequestTrailers ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpRequestTrailers(int) Action
func (*DefaultHttpContext) OnHttpResponseBody ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpResponseBody(int, bool) Action
func (*DefaultHttpContext) OnHttpResponseHeaders ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpResponseHeaders(int, bool) Action
func (*DefaultHttpContext) OnHttpResponseTrailers ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpResponseTrailers(int) Action
func (*DefaultHttpContext) OnHttpStreamDone ¶ added in v0.3.0
func (*DefaultHttpContext) OnHttpStreamDone()
type DefaultRootContext ¶ added in v0.3.0
type DefaultRootContext struct{}
DefaultRootContext provides the no-op implementation of RootContext interface.
func (*DefaultRootContext) NewHttpContext ¶ added in v0.3.0
func (*DefaultRootContext) NewHttpContext(uint32) HttpContext
func (*DefaultRootContext) NewTcpContext ¶ added in v0.3.0
func (*DefaultRootContext) NewTcpContext(uint32) TcpContext
func (*DefaultRootContext) OnPluginDone ¶ added in v0.3.0
func (*DefaultRootContext) OnPluginDone() bool
func (*DefaultRootContext) OnPluginStart ¶ added in v0.3.0
func (*DefaultRootContext) OnPluginStart(int) OnPluginStartStatus
func (*DefaultRootContext) OnQueueReady ¶ added in v0.3.0
func (*DefaultRootContext) OnQueueReady(uint32)
impl RootContext
func (*DefaultRootContext) OnTick ¶ added in v0.3.0
func (*DefaultRootContext) OnTick()
func (*DefaultRootContext) OnVMStart ¶ added in v0.3.0
func (*DefaultRootContext) OnVMStart(int) OnVMStartStatus
type DefaultTcpContext ¶ added in v0.3.0
type DefaultTcpContext struct{}
DefaultTcpContext provides the no-op implementation of TcpContext interface.
func (*DefaultTcpContext) OnDownstreamClose ¶ added in v0.3.0
func (*DefaultTcpContext) OnDownstreamClose(PeerType)
func (*DefaultTcpContext) OnDownstreamData ¶ added in v0.3.0
func (*DefaultTcpContext) OnDownstreamData(int, bool) Action
impl TcpContext
func (*DefaultTcpContext) OnNewConnection ¶ added in v0.3.0
func (*DefaultTcpContext) OnNewConnection() Action
func (*DefaultTcpContext) OnStreamDone ¶ added in v0.3.0
func (*DefaultTcpContext) OnStreamDone()
func (*DefaultTcpContext) OnUpstreamClose ¶ added in v0.3.0
func (*DefaultTcpContext) OnUpstreamClose(PeerType)
func (*DefaultTcpContext) OnUpstreamData ¶ added in v0.3.0
func (*DefaultTcpContext) OnUpstreamData(int, bool) Action
type HttpContext ¶ added in v0.3.0
type HttpContext interface { // OnHttpRequestHeaders is called when request headers arrives. // Return types.ActionPause if you want to stop sending headers to upstream. OnHttpRequestHeaders(numHeaders int, endOfStream bool) Action // OnHttpRequestBody is called when a request body *frame* arrives. // Note that this is possibly called multiple times until we see end_of_stream = true. // Return types.ActionPause if you want to buffer the body and stop sending body to upstream. // Even after returning types.ActionPause, this will be called when a unseen frame arrives. OnHttpRequestBody(bodySize int, endOfStream bool) Action // OnHttpRequestTrailers is called when request trailers arrives. // Return types.ActionPause if you want to stop sending trailers to upstream. OnHttpRequestTrailers(numTrailers int) Action // OnHttpResponseHeaders is called when response headers arrives. // Return types.ActionPause if you want to stop sending headers to downstream. OnHttpResponseHeaders(numHeaders int, endOfStream bool) Action // OnHttpResponseBody is called when a response body *frame* arrives. // Note that this is possibly called multiple times until we see end_of_stream = true. // Return types.ActionPause if you want to buffer the body and stop sending body to downtream. // Even after returning types.ActionPause, this will be called when a unseen frame arrives. OnHttpResponseBody(bodySize int, endOfStream bool) Action // OnHttpResponseTrailers is called when response trailers arrives. // Return types.ActionPause if you want to stop sending trailers to downstream. OnHttpResponseTrailers(numTrailers int) Action // OnHttpStreamDone is called before the host deletes this context. // You can retreive the HTTP request/response information (such headers, etc.) during this calls. // This can be used for implementing logging feature. OnHttpStreamDone() }
HttpContext corresponds to each Http stream and is created by RootContext via NewHttpContext.
type OnPluginStartStatus ¶ added in v0.1.0
type OnPluginStartStatus bool
OnPluginStartStatus is the tyep of status returned by OnPluginStart
const ( // OnPluginStartStatusOK indicates that RootContext.OnPluginStart succeeded. OnPluginStartStatusOK OnPluginStartStatus = true // OnPluginStartStatusFailed indicates that RootContext.OnPluginStart failed. // The further processing for that root context never happens. OnPluginStartStatusFailed OnPluginStartStatus = false )
type OnVMStartStatus ¶ added in v0.1.0
type OnVMStartStatus bool
OnVMStartStatus is the tyep of status returned by OnVMStart
const ( // OnVMStartStatusOK indicates that RootContext.OnVMStartStatus succeeded. OnVMStartStatusOK OnVMStartStatus = true // OnVMStartStatusFailed indicates that RootContext.OnVMStartStatus failed. // The further processing for that root context never happens, including OnPluginStart. OnVMStartStatusFailed OnVMStartStatus = false )
type RootContext ¶ added in v0.3.0
type RootContext interface { // OnVMStart is called after the VM is created and main function is called. // During this call, GetVmConfiguration hostcall is available and can be used to // retrieve the configuration set at vm_config.configuration. // // Note that **only one root cnotext is called on this function**. // That is because there's Wasm VM: RootContext = 1: N correspondence, and // the firstly created root context of these root contexts will be treated // as a *VM context* on which OnVMStart is invoked by host. // In other words, vm_config.configuration is only available for only one root context // which is created first. OnVMStart(vmConfigurationSize int) OnVMStartStatus // OnPluginStart is called on all root contexts (after OnVmStart if this is the VM context). // During this call, hostcalls.getPluginConfiguration is available and can be used to // retrieve the configuration set at config.configuration in envoy.yaml OnPluginStart(pluginConfigurationSize int) OnPluginStartStatus // onPluginDone is called right before root contexts are deleted by hosts. // Return false to indicate it's in a pending state to do some more work left. // In that case, must call PluginDone() host call after the work is done to indicate that // hosts can kill this contexts. OnPluginDone() bool // OnQueueReady is called when the queue is ready after calling RegisterQueue hostcall. // Note that the queue is dequeued by another VM running in another thread, so possibly // the queue is empty during OnQueueReady even if it is not dequeued by this VM. OnQueueReady(queueID uint32) // OnTick is called when SetTickPeriodMilliSeconds hostcall is called by this root context. // This can be used for doing some asynchronous tasks in parallel to stream processing. OnTick() // The following functions are used for creating contexts on streams, // and developers *must* implement either of them corresponding to // extension points. For example, if you configure this root context is running // at Http filters, then NewHttpContext must be implemented. Same goes for // Tcp filters. // // NewTcpContext is used for creating TcpContext for each Tcp streams. NewTcpContext(contextID uint32) TcpContext // NewHttpContext is used for creating HttpContext for each Http streams. NewHttpContext(contextID uint32) HttpContext }
There are three types of "contexts" you are supposed to implement for writing Proxy-Wasm plugins with this SDK. They are called RootContext, TcpContext and HttpContext, and their relationship can be described as the following diagram:
╱ TcpContext = handling each Tcp stream ╱ ╱ 1: N RootContext ╲ 1: N ╲ ╲ Http = handling each Http stream
In other words, RootContex is the parent of others, and responsible for creating Tcp and Http contexts corresponding to each streams if it is configured for running as a Http/Tcp stream plugin. Given that, RootContext is the primary interface everyone has to implement.
RootContext corresponds to each different plugin configurations (config.configuration), and the root context created first is specially treated as a VM context, which can handle vm_config.configuration during OnVMStart call to do VM-wise initialization.
type TcpContext ¶ added in v0.3.0
type TcpContext interface { // OnNewConnection is called when the Tcp connection is established between Down and Upstreams. OnNewConnection() Action // OnDownstreamData is called when a data frame arrives from the downstream connection. OnDownstreamData(dataSize int, endOfStream bool) Action // OnDownstreamClose is called when the downstream connection is closed. OnDownstreamClose(peerType PeerType) /// OnUpstreamData is called when a data frame arrives from the upstream connection. OnUpstreamData(dataSize int, endOfStream bool) Action // OnUpstreamClose is called when the upstream connection is closed. OnUpstreamClose(peerType PeerType) // OnStreamDone is called before the host deletes this context. // You can retreive the stream information (such as remote addesses, etc.) during this calls // This can be used for implementing logging feature. OnStreamDone() }
TcpContext corresponds to each Tcp stream and is created by RootContext via NewTcpContext.