types

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 1 Imported by: 72

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")
	// ErrorStatusBadArgument means the arguments for a hostcall are invalid.
	ErrorStatusBadArgument = errors.New("error status returned by host: bad argument")
	// ErrorStatusEmpty means the target queue of DequeueSharedQueue call is empty.
	ErrorStatusEmpty = errors.New("error status returned by host: empty")
	// ErrorStatusCasMismatch means the CAS value provided to the SetSharedData
	// does not match the current value. It indicates that other Wasm VMs
	// have already set a value for the same key, and the current CAS
	// for the key gets incremented.
	// Having retry logic in the face of this error is recommended.
	ErrorStatusCasMismatch = errors.New("error status returned by host: cas mismatch")
	// ErrorInternalFailure indicates an internal failure in hosts.
	// When this error occurs, there's nothing we could do in the Wasm VM.
	// Abort or panic after this error is recommended.
	ErrorInternalFailure = errors.New("error status returned by host: internal failure")
	// ErrorUnimplemented indicates the API is not implemented in the host yet.
	ErrorUnimplemented = errors.New("error status returned by host: unimplemented")
)

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 the 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

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 the 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)

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 the 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

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 the 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

type HttpContext added in v0.3.0

type HttpContext interface {
	// OnHttpRequestHeaders is called when request headers arrive.
	// Return types.ActionPause if you want to stop sending headers to the upstream.
	OnHttpRequestHeaders(numHeaders int, endOfStream bool) Action

	// OnHttpRequestBody is called when a request body *frame* arrives.
	// Note that this is potentially 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 the upstream.
	// Even after returning types.ActionPause, this will be called when an unseen frame arrives.
	OnHttpRequestBody(bodySize int, endOfStream bool) Action

	// OnHttpRequestTrailers is called when request trailers arrive.
	// Return types.ActionPause if you want to stop sending trailers to the upstream.
	OnHttpRequestTrailers(numTrailers int) Action

	// OnHttpResponseHeaders is called when response headers arrive.
	// 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 potentially 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 the downtream.
	// Even after returning types.ActionPause, this will be called when an unseen frame arrives.
	OnHttpResponseBody(bodySize int, endOfStream bool) Action

	// OnHttpResponseTrailers is called when response trailers arrive.
	// Return types.ActionPause if you want to stop sending trailers to the downstream.
	OnHttpResponseTrailers(numTrailers int) Action

	// OnHttpStreamDone is called before the host deletes this context.
	// You can retrieve the HTTP request/response information (such as headers, etc.) during this call.
	// This can be used to implement logging features.
	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 type of status returned by OnPluginStart

const (
	// OnPluginStartStatusOK indicates that PluginContext.OnPluginStart succeeded.
	OnPluginStartStatusOK OnPluginStartStatus = true
	// OnPluginStartStatusFailed indicates that PluginContext.OnPluginStart failed.
	// Further processing for this plugin context never happens.
	OnPluginStartStatusFailed OnPluginStartStatus = false
)

type OnVMStartStatus added in v0.1.0

type OnVMStartStatus bool

OnVMStartStatus is the type of status returned by OnVMStart

const (
	// OnVMStartStatusOK indicates that VMContext.OnVMStartStatus succeeded.
	OnVMStartStatusOK OnVMStartStatus = true
	// OnVMStartStatusFailed indicates that VMContext.OnVMStartStatus failed.
	// 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 unknown
	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 for 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 the host configuration.
	OnPluginStart(pluginConfigurationSize int) OnPluginStartStatus

	// OnPluginDone is called right before the plugin contexts are deleted by hosts.
	// Return false to indicate plugin is in a pending state and there's more work left.
	// In that case you must call PluginDone() function once the work is completed to indicate that
	// hosts can kill this context.
	OnPluginDone() bool

	// OnQueueReady is called when the queue is ready after calling the RegisterQueue hostcall.
	// Note that the queue might be dequeued by another VM running in another thread, so it's
	// possible queue will be empty during the 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 to do asynchronous tasks in parallel to the stream processing.
	OnTick()

	// NewTcpContext is used for creating TcpContext for each Tcp stream.
	// Return nil to indicate this PluginContext is not for TcpContext.
	NewTcpContext(contextID uint32) TcpContext

	// NewHttpContext is used for creating HttpContext for each Http stream.
	// Return nil to indicate this PluginContext is not for HttpContext.
	NewHttpContext(contextID uint32) HttpContext
}

PluginContext corresponds to different plugin configurations (config.configuration). Each configuration is typically given at the HTTP/TCP filter in a listener in the hosts. PluginContext is responsible for creating the "filter instances" for each TCP/HTTP stream on the listener.

type TcpContext added in v0.3.0

type TcpContext interface {
	// OnNewConnection is called when the Tcp connection is established between downstream and upstream.
	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 retrieve the stream information (such as remote addresses, etc.) during this call.
	// This can be used to implement logging features.
	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 in the host configuration.
	// This is mainly used for doing Wasm VM-wide initialization.
	OnVMStart(vmConfigurationSize int) OnVMStartStatus

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

VMContext corresponds to a Wasm VM machine and its configuration. It's the entrypoint for extending the network proxy. Its lifetime matches the Wasm Virtual Machines on the host.

Jump to

Keyboard shortcuts

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