core

package
v0.0.0-...-d6eac65 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2020 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

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

type Extension interface {
	// Extend extends the given processor to use the Crypto extension. `kind` is a
	// string: either "server" or "client". On a server, it installs the key
	// exchange endpoints.
	Extend(kind string, target Processor) error
}

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)

func (*PacketPipeline) Process

func (pp *PacketPipeline) Process(ctx *TargetCtx, pw packet.Writer) error

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 PipelineCtx

type PipelineCtx struct {
	Pkt  packet.Packet
	Stat int
	Msg  string
}

type Processor

type Processor interface {
	DataProcessor() DataProcessor
	PacketProcessor() PacketProcessor
}

type TargetCallback

type TargetCallback func(ctx *TargetCtx, pw packet.Writer)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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