api

package
v1.27.3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: Apache-2.0 Imports: 4 Imported by: 21

Documentation

Index

Constants

View Source
const (
	NormalFinalize int = 0 // normal, finalize on destroy
	GCFinalize     int = 1 // finalize in GC sweep
)

Variables

This section is empty.

Functions

func CgoCheckDisabled

func CgoCheckDisabled() bool

Types

type BufferAction

type BufferAction int

*************** BufferInstance start **************//

const (
	SetBuffer     BufferAction = 0
	AppendBuffer  BufferAction = 1
	PrependBuffer BufferAction = 2
)

type BufferInstance

type BufferInstance interface {
	DataBufferBase

	// Set overwrite the whole buffer content with byte slice.
	Set([]byte) error

	// SetString overwrite the whole buffer content with string.
	SetString(string) error

	// Prepend prepend the contents of the slice data to the buffer.
	Prepend(data []byte) error

	// Prepend prepend the contents of the string data to the buffer.
	PrependString(s string) error

	// Append append the contents of the string data to the buffer.
	AppendString(s string) error
}

type ConnectionCallback

type ConnectionCallback interface {
	// StreamInfo returns the stream info of the connection
	StreamInfo() StreamInfo
	// Write data to the connection.
	Write(buffer []byte, endStream bool)
	// Close the connection.
	Close(closeType ConnectionCloseType)
}

type ConnectionCloseType

type ConnectionCloseType int

Type of connection close to perform.

const (
	// Flush pending write data before raising ConnectionEvent::LocalClose
	FlushWrite ConnectionCloseType = 0
	// Do not flush any pending data. Write the pending data to buffer and then immediately
	// raise ConnectionEvent::LocalClose
	NoFlush ConnectionCloseType = 1
	// Flush pending write data and delay raising a ConnectionEvent::LocalClose
	// until the delayed_close_timeout expires
	FlushWriteAndDelay ConnectionCloseType = 2
	// Do not write/flush any pending data and immediately raise ConnectionEvent::LocalClose
	Abort ConnectionCloseType = 3
)

func (ConnectionCloseType) String

func (t ConnectionCloseType) String() string

type ConnectionEvent

type ConnectionEvent int

Events that occur on a connection.

const (
	RemoteClose      ConnectionEvent = 0
	LocalClose       ConnectionEvent = 1
	Connected        ConnectionEvent = 2
	ConnectedZeroRtt ConnectionEvent = 3
)

func (ConnectionEvent) String

func (e ConnectionEvent) String() string

type ConnectionInfoType

type ConnectionInfoType int
const (
	ConnectionInfoLocalAddr  ConnectionInfoType = 0
	ConnectionInfoRemoteAddr ConnectionInfoType = 1
)

func (ConnectionInfoType) String

func (t ConnectionInfoType) String() string

type DataBufferBase

type DataBufferBase interface {
	// Write appends the contents of p to the buffer, growing the buffer as
	// needed. The return value n is the length of p; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	Write(p []byte) (n int, err error)

	// WriteString appends the string to the buffer, growing the buffer as
	// needed. The return value n is the length of s; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	WriteString(s string) (n int, err error)

	// WriteByte appends the byte to the buffer, growing the buffer as
	// needed. The return value n is the length of s; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	WriteByte(p byte) error

	// WriteUint16 appends the uint16 to the buffer, growing the buffer as
	// needed. The return value n is the length of s; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	WriteUint16(p uint16) error

	// WriteUint32 appends the uint32 to the buffer, growing the buffer as
	// needed. The return value n is the length of s; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	WriteUint32(p uint32) error

	// WriteUint64 appends the uint64 to the buffer, growing the buffer as
	// needed. The return value n is the length of s; err is always nil. If the
	// buffer becomes too large, Write will panic with ErrTooLarge.
	WriteUint64(p uint64) error

	// Peek returns n bytes from buffer, without draining any buffered data.
	// If n > readable buffer, nil will be returned.
	// It can be used in codec to check first-n-bytes magic bytes
	// Note: do not change content in return bytes, use write instead
	Peek(n int) []byte

	// Bytes returns all bytes from buffer, without draining any buffered data.
	// It can be used to get fixed-length content, such as headers, body.
	// Note: do not change content in return bytes, use write instead
	Bytes() []byte

	// Drain drains a offset length of bytes in buffer.
	// It can be used with Bytes(), after consuming a fixed-length of data
	Drain(offset int)

	// Len returns the number of bytes of the unread portion of the buffer;
	// b.Len() == len(b.Bytes()).
	Len() int

	// Reset resets the buffer to be empty.
	Reset()

	// String returns the contents of the buffer as a string.
	String() string

	// Append append the contents of the slice data to the buffer.
	Append(data []byte) error
}

type DestroyReason

type DestroyReason int
const (
	Normal    DestroyReason = 0
	Terminate DestroyReason = 1
)

type DownstreamFilter

type DownstreamFilter interface {
	// Called when a connection is first established.
	OnNewConnection() FilterStatus
	// Called when data is read on the connection.
	OnData(buffer []byte, endOfStream bool) FilterStatus
	// Callback for connection events.
	OnEvent(event ConnectionEvent)
	// Called when data is to be written on the connection.
	OnWrite(buffer []byte, endOfStream bool) FilterStatus
}

type DynamicMetadata

type DynamicMetadata interface {
	Get(filterName string) map[string]interface{}
	Set(filterName string, key string, value interface{})
}

type EnvoyRequestPhase

type EnvoyRequestPhase int
const (
	DecodeHeaderPhase EnvoyRequestPhase = iota + 1
	DecodeDataPhase
	DecodeTrailerPhase
	EncodeHeaderPhase
	EncodeDataPhase
	EncodeTrailerPhase
)

func (EnvoyRequestPhase) String

func (e EnvoyRequestPhase) String() string

type FilterCallbackHandler

type FilterCallbackHandler interface {
	FilterCallbacks
}

type FilterCallbacks

type FilterCallbacks interface {
	StreamFilterCallbacks
	// Continue or SendLocalReply should be last API invoked, no more code after them.
	Continue(StatusType)
	SendLocalReply(responseCode int, bodyText string, headers map[string]string, grpcStatus int64, details string)
	// RecoverPanic recover panic in defer and terminate the request by SendLocalReply with 500 status code.
	RecoverPanic()
	Log(level LogType, msg string)
	LogLevel() LogType
}

type FilterState

type FilterState interface {
	SetString(key, value string, stateType StateType, lifeSpan LifeSpan, streamSharing StreamSharing)
	GetString(key string) string
}

type FilterStatus

type FilterStatus int

Status codes returned by filters that can cause future filters to not get iterated to.

const (
	// Continue to further filters.
	NetworkFilterContinue FilterStatus = 0
	// Stop executing further filters.
	NetworkFilterStopIteration FilterStatus = 1
)

func (FilterStatus) String

func (s FilterStatus) String() string

type HeaderMap

type HeaderMap interface {
	// GetRaw is unsafe, reuse the memory from Envoy
	GetRaw(name string) string

	// Get value of key
	// If multiple values associated with this key, first one will be returned.
	Get(key string) (string, bool)

	// Values returns all values associated with the given key.
	// The returned slice is not a copy.
	Values(key string) []string

	// Set key-value pair in header map, the previous pair will be replaced if exists.
	// It may not take affects immediately in the Envoy thread side when it's invoked in a Go thread.
	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.
	// It may not take affects immediately in the Envoy thread side when it's invoked in a Go thread.
	Add(key, value string)

	// Del delete pair of specified key
	// It may not take affects immediately in the Envoy thread side when it's invoked in a Go thread.
	Del(key string)

	// Range calls f sequentially for each key and value present in the map.
	// If f returns false, range stops the iteration.
	// When there are multiple values of a key, f will be invoked multiple times with the same key and each value.
	Range(f func(key, value string) bool)

	// RangeWithCopy calls f sequentially for each key and value copied from the map.
	RangeWithCopy(f func(key, value string) bool)

	// ByteSize return size of HeaderMap
	ByteSize() uint64
}

refer https://github.com/envoyproxy/envoy/blob/main/envoy/http/header_map.h

type HttpCAPI

type HttpCAPI interface {
	HttpContinue(r unsafe.Pointer, status uint64)
	HttpSendLocalReply(r unsafe.Pointer, responseCode int, bodyText string, headers map[string]string, grpcStatus int64, details string)

	// Send a specialized reply that indicates that the filter has failed on the go side. Internally this is used for
	// when unhandled panics are detected.
	HttpSendPanicReply(r unsafe.Pointer, details string)
	// experience api, memory unsafe
	HttpGetHeader(r unsafe.Pointer, key *string, value *string)
	HttpCopyHeaders(r unsafe.Pointer, num uint64, bytes uint64) map[string][]string
	HttpSetHeader(r unsafe.Pointer, key *string, value *string, add bool)
	HttpRemoveHeader(r unsafe.Pointer, key *string)

	HttpGetBuffer(r unsafe.Pointer, bufferPtr uint64, value *string, length uint64)
	HttpSetBufferHelper(r unsafe.Pointer, bufferPtr uint64, value string, action BufferAction)

	HttpCopyTrailers(r unsafe.Pointer, num uint64, bytes uint64) map[string][]string
	HttpSetTrailer(r unsafe.Pointer, key *string, value *string, add bool)
	HttpRemoveTrailer(r unsafe.Pointer, key *string)

	HttpGetStringValue(r unsafe.Pointer, id int) (string, bool)
	HttpGetIntegerValue(r unsafe.Pointer, id int) (uint64, bool)

	HttpGetDynamicMetadata(r unsafe.Pointer, filterName string) map[string]interface{}
	HttpSetDynamicMetadata(r unsafe.Pointer, filterName string, key string, value interface{})

	HttpLog(level LogType, message string)
	HttpLogLevel() LogType

	HttpFinalize(r unsafe.Pointer, reason int)

	HttpSetStringFilterState(r unsafe.Pointer, key string, value string, stateType StateType, lifeSpan LifeSpan, streamSharing StreamSharing)
	HttpGetStringFilterState(r unsafe.Pointer, key string) string
}

type LifeSpan

type LifeSpan int
const (
	LifeSpanFilterChain LifeSpan = 0
	LifeSpanRequest     LifeSpan = 1
	LifeSpanConnection  LifeSpan = 2
	LifeSpanTopSpan     LifeSpan = 3
)

type LogType

type LogType int

****************** log level start ******************//

const (
	Trace    LogType = 0
	Debug    LogType = 1
	Info     LogType = 2
	Warn     LogType = 3
	Error    LogType = 4
	Critical LogType = 5
)

refer https://github.com/envoyproxy/envoy/blob/main/source/common/common/base_logger.h

func (LogType) String

func (self LogType) String() string

type MetadataMap

type MetadataMap interface {
}

type NetworkCAPI

type NetworkCAPI interface {
	// DownstreamWrite writes buffer data into downstream connection.
	DownstreamWrite(f unsafe.Pointer, bufferPtr unsafe.Pointer, bufferLen int, endStream int)
	// DownstreamClose closes the downstream connection
	DownstreamClose(f unsafe.Pointer, closeType int)
	// DownstreamFinalize cleans up the resource of downstream connection, should be called only by runtime.SetFinalizer
	DownstreamFinalize(f unsafe.Pointer, reason int)
	// DownstreamInfo gets the downstream connection info of infoType
	DownstreamInfo(f unsafe.Pointer, infoType int) string
	// GetFilterState gets the filter state of key
	GetFilterState(f unsafe.Pointer, key string) string
	// SetFilterState sets the filter state of key to value
	SetFilterState(f unsafe.Pointer, key string, value string, stateType StateType, lifeSpan LifeSpan, streamSharing StreamSharing)

	// UpstreamConnect creates an envoy upstream connection to address
	UpstreamConnect(libraryID string, addr string) unsafe.Pointer
	// UpstreamWrite writes buffer data into upstream connection.
	UpstreamWrite(f unsafe.Pointer, bufferPtr unsafe.Pointer, bufferLen int, endStream int)
	// UpstreamClose closes the upstream connection
	UpstreamClose(f unsafe.Pointer, closeType int)
	// UpstreamFinalize cleans up the resource of upstream connection, should be called only by runtime.SetFinalizer
	UpstreamFinalize(f unsafe.Pointer, reason int)
	// UpstreamInfo gets the upstream connection info of infoType
	UpstreamInfo(f unsafe.Pointer, infoType int) string
}

type PassThroughStreamDecoderFilter

type PassThroughStreamDecoderFilter struct{}

PassThroughStreamDecoderFilter provides the no-op implementation of the StreamDecoderFilter interface.

func (*PassThroughStreamDecoderFilter) DecodeData

func (*PassThroughStreamDecoderFilter) DecodeHeaders

func (*PassThroughStreamDecoderFilter) DecodeTrailers

type PassThroughStreamEncoderFilter

type PassThroughStreamEncoderFilter struct{}

PassThroughStreamEncoderFilter provides the no-op implementation of the StreamEncoderFilter interface.

func (*PassThroughStreamEncoderFilter) EncodeData

func (*PassThroughStreamEncoderFilter) EncodeHeaders

func (*PassThroughStreamEncoderFilter) EncodeTrailers

type PassThroughStreamFilter

type PassThroughStreamFilter struct {
	PassThroughStreamDecoderFilter
	PassThroughStreamEncoderFilter
}

PassThroughStreamFilter provides the no-op implementation of the StreamFilter interface.

func (*PassThroughStreamFilter) OnDestroy

type PoolFailureReason

type PoolFailureReason int
const (
	// A resource overflowed and policy prevented a new connection from being created.
	Overflow PoolFailureReason = 0
	// A local connection failure took place while creating a new connection.
	LocalConnectionFailure PoolFailureReason = 1
	// A remote connection failure took place while creating a new connection.
	RemoteConnectionFailure PoolFailureReason = 2
	// A timeout occurred while creating a new connection.
	Timeout PoolFailureReason = 3
)

func (PoolFailureReason) String

func (r PoolFailureReason) String() string

type RequestHeaderMap

type RequestHeaderMap interface {
	HeaderMap
	Protocol() string
	Scheme() string
	Method() string
	Host() string
	Path() string
}

type RequestTrailerMap

type RequestTrailerMap interface {
	HeaderMap
}

type ResponseHeaderMap

type ResponseHeaderMap interface {
	HeaderMap
	Status() (int, bool)
}

type ResponseTrailerMap

type ResponseTrailerMap interface {
	HeaderMap
}

type StateType

type StateType int
const (
	StateTypeReadOnly StateType = 0
	StateTypeMutable  StateType = 1
)

type StatusType

type StatusType int

****************** filter status start ******************//

const (
	Running                StatusType = 0
	LocalReply             StatusType = 1
	Continue               StatusType = 2
	StopAndBuffer          StatusType = 3
	StopAndBufferWatermark StatusType = 4
	StopNoBuffer           StatusType = 5
)
const (
	HeaderContinue                     StatusType = 100
	HeaderStopIteration                StatusType = 101
	HeaderContinueAndDontEndStream     StatusType = 102
	HeaderStopAllIterationAndBuffer    StatusType = 103
	HeaderStopAllIterationAndWatermark StatusType = 104
)

header status refer https://github.com/envoyproxy/envoy/blob/main/envoy/http/filter.h

const (
	DataContinue                  StatusType = 200
	DataStopIterationAndBuffer    StatusType = 201
	DataStopIterationAndWatermark StatusType = 202
	DataStopIterationNoBuffer     StatusType = 203
)

data status refer https://github.com/envoyproxy/envoy/blob/main/envoy/http/filter.h

const (
	TrailerContinue      StatusType = 300
	TrailerStopIteration StatusType = 301
)

Trailer status refer https://github.com/envoyproxy/envoy/blob/main/envoy/http/filter.h

type StreamDecoderFilter

type StreamDecoderFilter interface {
	DecodeHeaders(RequestHeaderMap, bool) StatusType
	DecodeData(BufferInstance, bool) StatusType
	DecodeTrailers(RequestTrailerMap) StatusType
}

request

type StreamEncoderFilter

type StreamEncoderFilter interface {
	EncodeHeaders(ResponseHeaderMap, bool) StatusType
	EncodeData(BufferInstance, bool) StatusType
	EncodeTrailers(ResponseTrailerMap) StatusType
}

response

type StreamFilter

type StreamFilter interface {
	// http request
	StreamDecoderFilter
	// response stream
	StreamEncoderFilter
	// destroy filter
	OnDestroy(DestroyReason)
}

type StreamFilterCallbacks

type StreamFilterCallbacks interface {
	StreamInfo() StreamInfo
}

type StreamFilterConfigFactory

type StreamFilterConfigFactory func(config interface{}) StreamFilterFactory

type StreamFilterConfigParser

type StreamFilterConfigParser interface {
	Parse(any *anypb.Any) (interface{}, error)
	Merge(parentConfig interface{}, childConfig interface{}) interface{}
}

type StreamFilterFactory

type StreamFilterFactory func(callbacks FilterCallbackHandler) StreamFilter

type StreamInfo

type StreamInfo interface {
	GetRouteName() string
	FilterChainName() string
	// Protocol return the request's protocol.
	Protocol() (string, bool)
	// ResponseCode return the response code.
	ResponseCode() (uint32, bool)
	// ResponseCodeDetails return the response code details.
	ResponseCodeDetails() (string, bool)
	// AttemptCount return the number of times the request was attempted upstream.
	AttemptCount() uint32
	// Get the dynamic metadata of the request
	DynamicMetadata() DynamicMetadata
	// DownstreamLocalAddress return the downstream local address.
	DownstreamLocalAddress() string
	// DownstreamRemoteAddress return the downstream remote address.
	DownstreamRemoteAddress() string
	// UpstreamLocalAddress return the upstream local address.
	UpstreamLocalAddress() (string, bool)
	// UpstreamRemoteAddress return the upstream remote address.
	UpstreamRemoteAddress() (string, bool)
	// UpstreamClusterName return the upstream host cluster.
	UpstreamClusterName() (string, bool)
	// FilterState return the filter state interface.
	FilterState() FilterState
	// VirtualClusterName returns the name of the virtual cluster which got matched
	VirtualClusterName() (string, bool)
}

stream info refer https://github.com/envoyproxy/envoy/blob/main/envoy/stream_info/stream_info.h

type StreamSharing

type StreamSharing int
const (
	None                             StreamSharing = 0
	SharedWithUpstreamConnection     StreamSharing = 1
	SharedWithUpstreamConnectionOnce StreamSharing = 2
)

type UpstreamFilter

type UpstreamFilter interface {
	// Called when a connection is available to process a request/response.
	OnPoolReady(cb ConnectionCallback)
	// Called when a pool error occurred and no connection could be acquired for making the request.
	OnPoolFailure(poolFailureReason PoolFailureReason, transportFailureReason string)
	// Invoked when data is delivered from the upstream connection.
	OnData(buffer []byte, endOfStream bool)
	// Callback for connection events.
	OnEvent(event ConnectionEvent)
}

Jump to

Keyboard shortcuts

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