Documentation ¶
Index ¶
- Constants
- Variables
- func DecodeHeader(bytes []byte, h Header) (err error)
- func DecodeMap(buf []byte) map[string]string
- func EncodeHeader(buf Buffer, h Header)
- func EncodeMap(pairs map[string]string) []byte
- func EncodePropertyPath(path []string) []byte
- func GetEncodeHeaderLength(h Header) int
- func Mapping(httpStatusCode int32) uint32
- func SetNewFilterContext(f func(rootContextID, contextID uint32) FilterContext)
- func SetNewProtocolContext(f func(rootContextID, contextID uint32) ProtocolContext)
- func SetNewRootContext(f func(contextID uint32) RootContext)
- func SetNewStreamContext(f func(rootContextID, contextID uint32) StreamContext)
- func SetTickPeriodMilliSeconds(millSec uint32) error
- func VMStateGetActiveContextID() uint32
- func VMStateReset()
- type Buffer
- type Codec
- type Command
- type CommonHeader
- func (h *CommonHeader) Add(key string, value string)
- func (h *CommonHeader) Clone() *CommonHeader
- func (h *CommonHeader) Del(key string)
- func (h *CommonHeader) Get(key string) (value string, ok bool)
- func (h *CommonHeader) Range(f func(key, value string) bool)
- func (h *CommonHeader) Set(key string, value string)
- func (h *CommonHeader) Size() int
- func (h *CommonHeader) String() string
- func (h *CommonHeader) ToMap() map[string]string
- type ConfigMap
- type DefaultFilterContext
- func (c *DefaultFilterContext) OnDownStreamReceived(headers Header, data Buffer, trailers Header) types.Action
- func (*DefaultFilterContext) OnFilterStreamDone()
- func (*DefaultFilterContext) OnLog()
- func (c *DefaultFilterContext) OnUpstreamReceived(headers Header, data Buffer, trailers Header) types.Action
- type DefaultOptions
- type DefaultProtocolContext
- func (*DefaultProtocolContext) Codec() Codec
- func (*DefaultProtocolContext) Hijacker() Hijacker
- func (*DefaultProtocolContext) KeepAlive() KeepAlive
- func (*DefaultProtocolContext) Name() string
- func (*DefaultProtocolContext) OnLog()
- func (*DefaultProtocolContext) OnProtocolDone()
- func (*DefaultProtocolContext) Options() Options
- type DefaultRootContext
- type DefaultStreamContext
- func (*DefaultStreamContext) OnDownstreamClose(peerType types.PeerType)
- func (*DefaultStreamContext) OnDownstreamData(buffer Buffer, endOfStream bool) types.Action
- func (*DefaultStreamContext) OnLog()
- func (*DefaultStreamContext) OnNewConnection() types.Action
- func (*DefaultStreamContext) OnStreamDone()
- func (*DefaultStreamContext) OnUpstreamClose(peerType types.PeerType)
- func (*DefaultStreamContext) OnUpstreamData(buffer Buffer, endOfStream bool) types.Action
- type FilterContext
- type Header
- type Hijacker
- type HostEmulator
- type HttpCalloutAttribute
- type HttpCalloutCallBack
- type HttpCalloutResponse
- type KeepAlive
- type LocalHttpResponse
- type Logger
- type Node
- type Option
- func (o *Option) WithNewHttpContext(f func(uint32, uint32) FilterContext) *Option
- func (o *Option) WithNewProtocolContext(f func(uint32, uint32) ProtocolContext) *Option
- func (o *Option) WithNewRootContext(f func(uint32) RootContext) *Option
- func (o *Option) WithNewStreamContext(f func(uint32, uint32) StreamContext) *Option
- func (o *Option) WithPluginConfiguration(data ConfigMap) *Option
- func (o *Option) WithVMConfiguration(data ConfigMap) *Option
- type Options
- type Order
- type Protocol
- type ProtocolContext
- type Request
- type Response
- type RootContext
- type StreamContext
Constants ¶
const ( CopyRawBytesFlag byte = 1 // 0000_0001 HeartBeatFlag byte = 1 << 5 // 0010_0000 RpcRequestFlag byte = 1 << 6 // 0100_0000 RpcOnewayFlag byte = 1<<6 | 1<<7 // 1100_0000 )
const ( ResponseStatusSuccess uint16 = 0 // 0x00 response status ResponseStatusError uint16 = 1 // 0x01 ResponseStatusServerException uint16 = 2 // 0x02 ResponseStatusUnknown uint16 = 3 // 0x03 ResponseStatusServerThreadPoolBusy uint16 = 4 // 0x04 ResponseStatusErrorComm uint16 = 5 // 0x05 ResponseStatusNoProcessor uint16 = 6 // 0x06 ResponseStatusTimeout uint16 = 7 // 0x07 ResponseStatusClientSendError uint16 = 8 // 0x08 ResponseStatusCodecException uint16 = 9 // 0x09 ResponseStatusConnectionClosed uint16 = 16 // 0x10 ResponseStatusServerSerialException uint16 = 17 // 0x11 ResponseStatusServerDeserializeException uint16 = 18 // 0x12 CodecExceptionCode = 0 UnknownCode = 2 DeserializeExceptionCode = 3 SuccessCode = 200 PermissionDeniedCode = 403 InternalErrorCode = 500 NoHealthUpstreamCode = 502 UpstreamOverFlowCode = 503 TimeoutExceptionCode = 504 LimitExceededCode = 509 )
const (
RootContextID uint32 = 1 // TODO: support multiple rootContext
)
Variables ¶
var BufferTooLarge = errors.New("wasm plugin Buffer: too large")
var IndexOutOfBound = errors.New("wasm plugin Buffer: index out of bound")
Functions ¶
func DecodeHeader ¶
func EncodeHeader ¶
func EncodeMap ¶
EncodeMap encode map to bytes encoded bytes format: pairs number + all key/value length + all key/value bytes
eg: {"key1": "value1", "hello": "world"} 2(pairs number) + 4(key1 length) + 6(value1 length) => { "key1": "value1" } length
- 5(hello length) + 5(world length) => { "hello": "world" } length
- key1 bytes + nil byte + value1 bytes + nil byte => { "key1": "value1" } bytes
- hello bytes + nil byte + world bytes + nil byte => { "hello": "world" } bytes
func EncodePropertyPath ¶
func GetEncodeHeaderLength ¶
func SetNewFilterContext ¶
func SetNewFilterContext(f func(rootContextID, contextID uint32) FilterContext)
func SetNewProtocolContext ¶
func SetNewProtocolContext(f func(rootContextID, contextID uint32) ProtocolContext)
func SetNewRootContext ¶
func SetNewRootContext(f func(contextID uint32) RootContext)
func SetNewStreamContext ¶
func SetNewStreamContext(f func(rootContextID, contextID uint32) StreamContext)
func VMStateGetActiveContextID ¶
func VMStateGetActiveContextID() uint32
func VMStateReset ¶
func VMStateReset()
Types ¶
type Buffer ¶
type Buffer interface { Bytes() []byte Len() int Cap() int Pos() int Move(int) Grow(n int) Reset() Peek(n int) []byte Drain(len int) Mark() ResetMark() ByteOrder(order Order) Buffer WriteByte(value byte) error WriteUint16(value uint16) error WriteUint32(value uint32) error WriteUint(value uint) error WriteUint64(value uint64) error WriteInt16(value int16) error WriteInt32(value int32) error WriteInt(value int) error WriteInt64(value int64) error PutByte(index int, value byte) error PutUint16(index int, value uint16) error PutUint32(index int, value uint32) error PutUint(index int, value uint) error PutUint64(index int, value uint64) error PutInt16(index int, value int16) error PutInt32(index int, value int32) error PutInt(index int, value int) error PutInt64(index int, value int64) error Write(p []byte) (n int, err error) WriteString(s string) (n int, err error) ReadByte() (byte, error) ReadUint16() (uint16, error) ReadUint32() (uint32, error) ReadUint() (uint, error) ReadUint64() (uint64, error) ReadInt16() (int16, error) ReadInt32() (int32, error) ReadInt() (int, error) ReadInt64() (int64, error) GetByte(index int) (byte, error) GetUint16(index int) (uint16, error) GetUint32(index int) (uint32, error) GetUint(index int) (uint, error) GetUint64(index int) (uint64, error) GetInt16(index int) (int16, error) GetInt32(index int) (int32, error) GetInt(index int) (int, error) GetInt64(index int) (int64, error) }
func AllocateBuffer ¶
func AllocateBuffer() Buffer
func WrapBuffer ¶
type Command ¶
type Command interface { // Header get the data exchange header, maybe return nil. GetHeader() Header // GetData return the full message buffer, the protocol header is not included GetData() Buffer // SetData update the full message buffer, the protocol header is not included SetData(data Buffer) // IsHeartbeat check if the request is a heartbeat request IsHeartbeat() bool // CommandId get command id CommandId() uint64 // SetCommandId update command id // In upstream, because of connection multiplexing, // the id of downstream needs to be replaced with id of upstream // blog: https://mosn.io/blog/posts/multi-protocol-deep-dive/#%E5%8D%8F%E8%AE%AE%E6%89%A9%E5%B1%95%E6%A1%86%E6%9E%B6 SetCommandId(id uint64) }
Command base request or response command
type CommonHeader ¶
type CommonHeader struct { Changed bool // contains filtered or unexported fields }
func (*CommonHeader) Add ¶
func (h *CommonHeader) Add(key string, value string)
Add value for given key. Multiple headers with the same key may be added with this function. Use Set for setting a single header for the given key.
func (*CommonHeader) Clone ¶
func (h *CommonHeader) Clone() *CommonHeader
func (*CommonHeader) Get ¶
func (h *CommonHeader) Get(key string) (value string, ok bool)
Get value of key
func (*CommonHeader) Range ¶
func (h *CommonHeader) Range(f func(key, value string) bool)
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
func (*CommonHeader) Set ¶
func (h *CommonHeader) Set(key string, value string)
Set key-value pair in header map, the previous pair will be replaced if exists
func (*CommonHeader) Size ¶
func (h *CommonHeader) Size() int
func (*CommonHeader) String ¶
func (h *CommonHeader) String() string
func (*CommonHeader) ToMap ¶
func (h *CommonHeader) ToMap() map[string]string
type DefaultFilterContext ¶
type DefaultFilterContext struct {
// contains filtered or unexported fields
}
func (*DefaultFilterContext) OnDownStreamReceived ¶
func (c *DefaultFilterContext) OnDownStreamReceived(headers Header, data Buffer, trailers Header) types.Action
impl FilterContext
func (*DefaultFilterContext) OnFilterStreamDone ¶
func (*DefaultFilterContext) OnFilterStreamDone()
func (*DefaultFilterContext) OnLog ¶
func (*DefaultFilterContext) OnLog()
func (*DefaultFilterContext) OnUpstreamReceived ¶
type DefaultOptions ¶
type DefaultOptions struct { }
func (*DefaultOptions) EnableGenerateRequestID ¶
func (o *DefaultOptions) EnableGenerateRequestID() bool
func (*DefaultOptions) EnableWorkerPool ¶
func (o *DefaultOptions) EnableWorkerPool() bool
func (*DefaultOptions) GenerateRequestID ¶
func (o *DefaultOptions) GenerateRequestID(v *uint64) uint64
func (*DefaultOptions) PoolMode ¶
func (o *DefaultOptions) PoolMode() types.PoolMode
type DefaultProtocolContext ¶
type DefaultProtocolContext struct {
// contains filtered or unexported fields
}
func (*DefaultProtocolContext) Codec ¶
func (*DefaultProtocolContext) Codec() Codec
func (*DefaultProtocolContext) Hijacker ¶
func (*DefaultProtocolContext) Hijacker() Hijacker
func (*DefaultProtocolContext) KeepAlive ¶
func (*DefaultProtocolContext) KeepAlive() KeepAlive
func (*DefaultProtocolContext) Name ¶
func (*DefaultProtocolContext) Name() string
impl ProtocolContext
func (*DefaultProtocolContext) OnLog ¶
func (*DefaultProtocolContext) OnLog()
func (*DefaultProtocolContext) OnProtocolDone ¶
func (*DefaultProtocolContext) OnProtocolDone()
func (*DefaultProtocolContext) Options ¶
func (*DefaultProtocolContext) Options() Options
type DefaultRootContext ¶
type DefaultRootContext struct{}
func (*DefaultRootContext) OnPluginStart ¶
func (*DefaultRootContext) OnPluginStart(conf ConfigMap) bool
func (*DefaultRootContext) OnVMDone ¶
func (*DefaultRootContext) OnVMDone() bool
func (*DefaultRootContext) OnVMStart ¶
func (*DefaultRootContext) OnVMStart(conf ConfigMap) bool
type DefaultStreamContext ¶
type DefaultStreamContext struct{}
func (*DefaultStreamContext) OnDownstreamClose ¶
func (*DefaultStreamContext) OnDownstreamClose(peerType types.PeerType)
func (*DefaultStreamContext) OnDownstreamData ¶
func (*DefaultStreamContext) OnDownstreamData(buffer Buffer, endOfStream bool) types.Action
impl StreamContext
func (*DefaultStreamContext) OnLog ¶
func (*DefaultStreamContext) OnLog()
func (*DefaultStreamContext) OnNewConnection ¶
func (*DefaultStreamContext) OnNewConnection() types.Action
func (*DefaultStreamContext) OnStreamDone ¶
func (*DefaultStreamContext) OnStreamDone()
func (*DefaultStreamContext) OnUpstreamClose ¶
func (*DefaultStreamContext) OnUpstreamClose(peerType types.PeerType)
func (*DefaultStreamContext) OnUpstreamData ¶
func (*DefaultStreamContext) OnUpstreamData(buffer Buffer, endOfStream bool) types.Action
type FilterContext ¶
type FilterContext interface { // OnDownStreamReceived Called when the data requests, // The caller should check if the parameter value is nil OnDownStreamReceived(headers Header, data Buffer, trailers Header) types.Action // OnUpstreamReceived Called when the data responds, // The caller should check if the parameter value is nil OnUpstreamReceived(headers Header, data Buffer, trailers Header) types.Action //// Context Used to save and pass data during a session //Context() context.Context OnFilterStreamDone() OnLog() }
L7 layer extension
type Header ¶
type Header interface { // Get value of key // If multiple values associated with this key, first one will be returned. Get(key string) (string, bool) // Set key-value pair in header map, the previous pair will be replaced if exists Set(key, value string) // Add value for given key. // Multiple headers with the same key may be added with this function. // Use Set for setting a single header for the given key. Add(key, value string) // Del delete pair of specified key Del(key string) // Range calls f sequentially for each key and value present in the map. // If f returns false, range stops the iteration. Range(f func(key, value string) bool) // Size header key value pair count Size() int ToMap() map[string]string }
type HostEmulator ¶
type HostEmulator interface { // release emulator resource and reset state Done() // Root StartVM() StartPlugin() FinishVM() GetLogs(level types.LogLevel) []string GetTickPeriod() uint32 Tick() // protocol L7 level NewProtocolContext() (contextID uint32) Decode(contextID uint32, data Buffer) (Command, error) Encode(contextID uint32, cmd Command) (Buffer, error) // heartbeat KeepAlive(contextID uint32, requestId uint64) Request ReplyKeepAlive(contextID uint32, request Request) Response // hijacker Hijack(contextID uint32, request Request, code uint32) Response // easy for test only CurrentStreamId() uint64 // finish protocol pipeline CompleteProtocolContext(contextID uint32) // filter L7 level NewFilterContext() (contextID uint32) PutRequestHeaders(contextID uint32, headers map[string]string, endOfStream bool) PutRequestBody(contextID uint32, body []byte, endOfStream bool) PutRequestTrailers(contextID uint32, headers map[string]string) GetRequestHeaders(contextID uint32) (headers map[string]string) GetRequestBody(contextID uint32) []byte PutResponseHeaders(contextID uint32, headers map[string]string, endOfStream bool) PutResponseBody(contextID uint32, body []byte, endOfStream bool) PutResponseTrailers(contextID uint32, headers map[string]string) GetResponseHeaders(contextID uint32) (headers map[string]string) GetResponseBody(contextID uint32) []byte GetCurrentStreamAction(contextID uint32) types.Action CompleteFilterContext(contextID uint32) }
func NewHostEmulator ¶
func NewHostEmulator(opt *Option) HostEmulator
type HttpCalloutAttribute ¶
type HttpCalloutCallBack ¶
type HttpCalloutResponse ¶
type HttpCalloutResponse struct {
// contains filtered or unexported fields
}
type LocalHttpResponse ¶
type Logger ¶
type Logger interface { Debug(msg string) Debugf(format string, args ...interface{}) Info(msg string) Infof(format string, args ...interface{}) Warn(msg string) Warnf(format string, args ...interface{}) Error(msg string) Errorf(format string, args ...interface{}) Fatal(msg string) Fatalf(format string, args ...interface{}) }
var Log Logger
type Node ¶
type Node struct { Name string // extension name Context interface{} // extension context Order int // registered priority Next *Node // next node // contains filtered or unexported fields }
Node pub or sub host metadata, Keep the structure as simple as possible.
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
func NewEmulatorOption ¶
func NewEmulatorOption() *Option
func (*Option) WithNewHttpContext ¶
func (o *Option) WithNewHttpContext(f func(uint32, uint32) FilterContext) *Option
func (*Option) WithNewProtocolContext ¶
func (o *Option) WithNewProtocolContext(f func(uint32, uint32) ProtocolContext) *Option
func (*Option) WithNewRootContext ¶
func (o *Option) WithNewRootContext(f func(uint32) RootContext) *Option
func (*Option) WithNewStreamContext ¶
func (o *Option) WithNewStreamContext(f func(uint32, uint32) StreamContext) *Option
func (*Option) WithPluginConfiguration ¶
func (*Option) WithVMConfiguration ¶
type Options ¶
type Options interface { // default Multiplex PoolMode() types.PoolMode // EnableWorkerPool same meaning as EnableWorkerPool in types.StreamConnection EnableWorkerPool() bool // EnableGenerateRequestID check if the protocol requires custom streamId. // If need to generate, you should override the GenerateRequestID method implementation EnableGenerateRequestID() bool // GenerateRequestID generate a request id for stream to combine stream request && response // use connection param as base GenerateRequestID(*uint64) uint64 }
Options Features required for a particular host
type ProtocolContext ¶
type ProtocolContext interface { Name() string // protocol name Codec() Codec // frame encode & decode KeepAlive() KeepAlive // protocol keep alive Hijacker() Hijacker // protocol hijacker Options() Options // protocol options }
L7 layer extension
type RootContext ¶
type StreamContext ¶
type StreamContext interface { OnDownstreamData(buffer Buffer, endOfStream bool) types.Action OnDownstreamClose(peerType types.PeerType) OnNewConnection() types.Action OnUpstreamData(buffer Buffer, endOfStream bool) types.Action OnUpstreamClose(peerType types.PeerType) OnStreamDone() OnLog() }
L4 layer extension (host not support now.)
Source Files ¶
- abi_allocate.go
- abi_config.go
- abi_hostcall.go
- abi_l4.go
- abi_l7.go
- abi_loader.go
- abi_log.go
- abi_protocol.go
- abi_timer.go
- abi_unsafe.go
- abi_unsafe_tinygo.go
- abi_version.go
- api_context.go
- api_state.go
- api_utils.go
- buffer.go
- context.go
- emulator.go
- emulator_filter.go
- emulator_network.go
- emulator_option.go
- emulator_protocol.go
- emulator_root.go
- header_codec.go
- log.go
- protocol.go