types

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2021 License: Apache-2.0 Imports: 1 Imported by: 82

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

const (
	// ActionContinue means that the host continues the processing.
	ActionContinue Action = 0
	// ActionPause means that the host pauses the processing.
	ActionPause Action = 1
)

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 DefaultPluginContext added in v0.13.0

type DefaultPluginContext struct{}

DefaultPluginContext provides the no-op implementation of PluginContext interface.

func (*DefaultPluginContext) NewHttpContext added in v0.13.0

func (*DefaultPluginContext) NewHttpContext(uint32) HttpContext

func (*DefaultPluginContext) NewTcpContext added in v0.13.0

func (*DefaultPluginContext) NewTcpContext(uint32) TcpContext

func (*DefaultPluginContext) OnPluginDone added in v0.13.0

func (*DefaultPluginContext) OnPluginDone() bool

func (*DefaultPluginContext) OnPluginStart added in v0.13.0

func (*DefaultPluginContext) OnQueueReady added in v0.13.0

func (*DefaultPluginContext) OnQueueReady(uint32)

impl PluginContext

func (*DefaultPluginContext) OnTick added in v0.13.0

func (*DefaultPluginContext) OnTick()

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 DefaultVMContext added in v0.13.0

type DefaultVMContext struct{}

DefaultVMContext provides the no-op implementation of VMContext interface.

func (*DefaultVMContext) NewPluginContext added in v0.13.0

func (*DefaultVMContext) NewPluginContext(contextID uint32) PluginContext

func (*DefaultVMContext) OnVMStart added in v0.13.0

func (*DefaultVMContext) OnVMStart(vmConfigurationSize int) OnVMStartStatus

impl VMContext

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 PluginContext 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 PluginContext.OnPluginStart succeeded.
	OnPluginStartStatusOK OnPluginStartStatus = true
	// OnPluginStartStatusFailed indicates that PluginContext.OnPluginStart failed.
	// The further processing for that plugin 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 VMContext.OnVMStartStatus succeeded.
	OnVMStartStatusOK OnVMStartStatus = true
	// OnVMStartStatusFailed indicates that VMContext.OnVMStartStatus failed.
	// The further processing for this VM never happens, and hosts would
	// delete this VM.
	OnVMStartStatusFailed OnVMStartStatus = false
)

type PeerType

type PeerType uint32

PeerType represents the type of a peer of a connection.

const (
	// PeerTypeUnknown means the type of a peer is unknwo
	PeerTypeUnknown PeerType = 0
	// PeerTypeLocal means the type of a peer is local (i.e. proxy)
	PeerTypeLocal PeerType = 1
	// PeerTypeRemote means the type of a peer is remote (i.e. remote client)
	PeerTypeRemote PeerType = 2
)

type PluginContext added in v0.13.0

type PluginContext interface {
	// OnPluginStart is called on all plugin contexts (after OnVmStart if this is the VM context).
	// During this call, 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 plugin 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 plugin 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 plugin 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.
	// Return nil to indicate this PluginContext is not for TcpContext.
	NewTcpContext(contextID uint32) TcpContext
	// NewHttpContext is used for creating HttpContext for each Http streams.
	// Return nil to indicate this PluginContext is not for HttpContext.
	NewHttpContext(contextID uint32) HttpContext
}

PluginContext corresponds to each different plugin configurations (config.configuration). Each configuration is usually given at each http/tcp filter in a listener in the hosts, so PluginContext is responsible for creating "filter instances" for each Tcp/Http streams on the listener.

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 PluginContext via NewTcpContext.

type VMContext added in v0.13.0

type VMContext 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.
	// This is mainly used for doing Wasm VM-wise initialization.
	OnVMStart(vmConfigurationSize int) OnVMStartStatus

	// NewPluginContext is used for creating PluginContext for each plugin configurations.
	NewPluginContext(contextID uint32) PluginContext
}

There are four types of these intefaces which you are supposed to implement in order to extend your network proxies. They are VMContext, PluginContext, TcpContext and HttpContext, and their relationship can be described as the following diagram:

                        Wasm Virtual Machine(VM)
                   (corresponds to VM configuration)
┌────────────────────────────────────────────────────────────────────────────┐
│                                                      TcpContext            │
│                                                  ╱ (Each Tcp stream)       │
│                                                 ╱                          │
│                      1: N                      ╱ 1: N                      │
│       VMContext  ──────────  PluginContext                                 │
│  (VM configuration)     (Plugin configuration) ╲ 1: N                      │
│                                                 ╲                          │
│                                                  ╲   HttpContext           │
│                                                   (Each Http stream)       │
└────────────────────────────────────────────────────────────────────────────┘

To summarize,

1) VMContext corresponds to each Wasm Virtual Machine, and only one VMContext exists in each VM. Note that in Envoy, Wasm VMs are created per "vm_config" field in envoy.yaml. For example having different "vm_config.configuration" fields results in multiple VMs being created and each of them corresponds to each "vm_config.configuration".

2) VMContext is parent of PluginContext, and is responsible for creating arbitrary number of PluginContexts.

3) PluginContext corresponds to each plugin configurations in the host. In Envoy, each plugin configuration is given at HttpFilter or NetworkFilter on listeners. That said, a plugin context corresponds to a Http or Network filter on a litener and is in charge of creating "filter instances" for each Http or Tcp streams. And these "filter instances" are HttpContexts or TcpContexts.

4) PluginContext is parent of TcpContext and HttpContexts, and is responsible for creating arbitrary number of these contexts.

5) TcpContext is responsible for handling each Tcp stream events.

6) HttpContext is responsible for handling each Http stream events.

VMContext corresponds to each Wasm VM machine and its configuration. Thefore, this is the entrypoint for extending your network proxy. Its lifetime is exactly the same as Wasm Virtual Machines on the host.

Jump to

Keyboard shortcuts

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