Documentation ¶
Index ¶
Constants ¶
const ( // CodeContinue 0 means "continue callback queue execution". CodeContinue = 0 // CodeStopError means "stop callback queue execution, send error message (ctx.Msg)" CodeStopError = -1 // CodeStopCloseSend means "stop callback queue execution, close response and send". CodeStopCloseSend = 1 // CodeStopNoop means "stop callback queue execution, and do nothing". CodeStopNoop = 2 // CodeRelay means "processing complete, relay the packet to another address, // as specified in the packet metadata" CodeRelay = 3 )
Context Status codes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BufferTransform ¶
type BufferTransform func(ctx *TransformContext, buff []byte) (result []byte)
BufferTransform is a function which acts on a byte slice, updating its contents in some way. An example of a buffer transform is a cryptographic function which decodes/encodes the contents of the buffer.
type DataPipeline ¶
type DataPipeline struct {
// contains filtered or unexported fields
}
DataPipeline manages the transformations to be performed on binary data immediately after it has been read and just before it is written to the connection.
func NewDataPipeline ¶
func NewDataPipeline() *DataPipeline
func (*DataPipeline) AddTransform ¶
func (d *DataPipeline) AddTransform(pipelineName string, transform BufferTransform)
func (*DataPipeline) Lock ¶
func (d *DataPipeline) Lock()
func (*DataPipeline) Process ¶
func (d *DataPipeline) Process(ctx *TransformContext, data []byte) ([]byte, error)
func (*DataPipeline) Unlock ¶
func (d *DataPipeline) Unlock()
type DataProcessor ¶
type DataProcessor interface { // Lock processor - prevent writes, only executing pipelines allowed Lock() // Unlock processort - enable writes Unlock() // AddTransform adds the given transform to the pipeline specfied. If the // processor is already locked, then nothing is done. AddTransform(pipelineName string, transform BufferTransform) // Process runs the pipeline specified on the given data and returns the // transformed data and any error that may have occurred. Process(ctx *TransformContext, data []byte) ([]byte, error) }
DataProcessor is used to build pipelines for operating on binary data, using BufferTransforms. Multiple BufferTransforms may be run, in succession, on one piece of data, forming a data pipeline. The pipeline may have to prematurely exit (for example if the data is malformed) and this can be done using the transform context by setting the Stat field to -1 and, possibly, setting an error message in the Msg field.
type PacketPipeline ¶
type PacketPipeline struct {
// contains filtered or unexported fields
}
func NewPacketPipeline ¶
func NewPacketPipeline() *PacketPipeline
func (*PacketPipeline) AddCallback ¶
func (pp *PacketPipeline) AddCallback(targetName string, cb TargetCallback)
type PacketProcessor ¶
type PacketProcessor interface { // AddCallback adds the given calback function to the callback queue for the // given target name. AddCallback(targetName string, cb TargetCallback) // Process executes the callback queue for the given packet's target Process(ctx *TargetCtx, pw packet.Writer) error }
PacketProcessor is used to build callback queues for different targets. Packets are then processed according to their target. The TargetCtx allows TargetCallback functions to alter the execution of the callback queue.
type Processor ¶
type Processor interface { DataProcessor() DataProcessor PacketProcessor() PacketProcessor }
type TargetCallback ¶
TargetCallback defines the signature of a callback for a target in the server.
type TargetCtx ¶
type TargetCtx struct { PipelineCtx TargetName string From string }
TargetCtx is the server's callback queue execution context. To end the callback queue execution for a particular packet, TargetCallbacks should set Stat to -1 and the server will terminate the execution. In such a case, the server will inform the sender of the error using the content of the Msg field. These two fields appear in the Metadata of a Packet at the keys "_stat" and "_msg" respectively. Other status codes will cause the server to respond differently, but a non-zero status code will surely stop execution of the callback queue. Each of these status codes have names, provided in the constants section of the `internal` package, which are more sensible and easy to remember.
type TransformContext ¶
type TransformContext struct { PipelineCtx PipelineName string From string }
TransformContext is information shared by all BufferTransform functions executed on a buffer.