toxics - ActiveState ActiveGo 1.8

Package toxics

import ""

Overview ▾


var ToxicRegistry map[string]Toxic

func Count

func Count() int

func Register

func Register(typeName string, toxic Toxic)

type BandwidthToxic

The BandwidthToxic passes data through at a limited rate

type BandwidthToxic struct {
    // Rate in KB/s
    Rate int64 `json:"rate"`

func (*BandwidthToxic) Pipe

func (t *BandwidthToxic) Pipe(stub *ToxicStub)

type BufferedToxic

type BufferedToxic interface {
    // Defines the size of buffer this toxic should use
    GetBufferSize() int

type CleanupToxic

type CleanupToxic interface {
    // Cleanup is called before a toxic is removed.

type LatencyToxic

The LatencyToxic passes data through with the a delay of latency +/- jitter added.

type LatencyToxic struct {
    // Times in milliseconds
    Latency int64 `json:"latency"`
    Jitter  int64 `json:"jitter"`

func (*LatencyToxic) GetBufferSize

func (t *LatencyToxic) GetBufferSize() int

func (*LatencyToxic) Pipe

func (t *LatencyToxic) Pipe(stub *ToxicStub)

type LimitDataToxic

LimitDataToxic has limit in bytes

type LimitDataToxic struct {
    Bytes int64 `json:"bytes"`

func (*LimitDataToxic) NewState

func (t *LimitDataToxic) NewState() interface{}

func (*LimitDataToxic) Pipe

func (t *LimitDataToxic) Pipe(stub *ToxicStub)

type LimitDataToxicState

type LimitDataToxicState struct {
    // contains filtered or unexported fields

type NoopToxic

The NoopToxic passes all data through without any toxic effects.

type NoopToxic struct{}

func (*NoopToxic) Pipe

func (t *NoopToxic) Pipe(stub *ToxicStub)

type SlicerToxic

The SlicerToxic slices data into multiple smaller packets to simulate real-world TCP behaviour.

type SlicerToxic struct {
    // Average number of bytes to slice at
    AverageSize int `json:"average_size"`
    // +/- bytes to vary sliced amounts. Must be less than
    // the average size
    SizeVariation int `json:"size_variation"`
    // Microseconds to delay each packet. May be useful since there's
    // usually some kind of buffering of network data
    Delay int `json:"delay"`

func (*SlicerToxic) Pipe

func (t *SlicerToxic) Pipe(stub *ToxicStub)

type SlowCloseToxic

The SlowCloseToxic stops the TCP connection from closing until after a delay.

type SlowCloseToxic struct {
    // Times in milliseconds
    Delay int64 `json:"delay"`

func (*SlowCloseToxic) Pipe

func (t *SlowCloseToxic) Pipe(stub *ToxicStub)

type StatefulToxic

Stateful toxics store a per-connection state object on the ToxicStub. The state is created once when the toxic is added and persists until the toxic is removed or the connection is closed.

type StatefulToxic interface {
    // Creates a new object to store toxic state in
    NewState() interface{}

type TimeoutToxic

The TimeoutToxic stops any data from flowing through, and will close the connection after a timeout. If the timeout is set to 0, then the connection will not be closed.

type TimeoutToxic struct {
    // Times in milliseconds
    Timeout int64 `json:"timeout"`

func (*TimeoutToxic) Cleanup

func (t *TimeoutToxic) Cleanup(stub *ToxicStub)

func (*TimeoutToxic) Pipe

func (t *TimeoutToxic) Pipe(stub *ToxicStub)

type Toxic

type Toxic interface {
    // Defines how packets flow through a ToxicStub. Pipe() blocks until the link is closed or interrupted.

func New

func New(wrapper *ToxicWrapper) Toxic

type ToxicStub

type ToxicStub struct {
    Input     <-chan *stream.StreamChunk
    Output    chan<- *stream.StreamChunk
    State     interface{}
    Interrupt chan struct{}
    // contains filtered or unexported fields

func NewToxicStub

func NewToxicStub(input <-chan *stream.StreamChunk, output chan<- *stream.StreamChunk) *ToxicStub

func (*ToxicStub) Close

func (s *ToxicStub) Close()

func (*ToxicStub) Closed

func (s *ToxicStub) Closed() bool

func (*ToxicStub) InterruptToxic

func (s *ToxicStub) InterruptToxic() bool

Interrupt the flow of data so that the toxic controlling the stub can be replaced. Returns true if the stream was successfully interrupted, or false if the stream is closed.

func (*ToxicStub) Run

func (s *ToxicStub) Run(toxic *ToxicWrapper)

Begin running a toxic on this stub, can be interrupted. Runs a noop toxic randomly depending on toxicity

type ToxicWrapper

type ToxicWrapper struct {
    Toxic      `json:"attributes"`
    Name       string           `json:"name"`
    Type       string           `json:"type"`
    Stream     string           `json:"stream"`
    Toxicity   float32          `json:"toxicity"`
    Direction  stream.Direction `json:"-"`
    Index      int              `json:"-"`
    BufferSize int              `json:"-"`