Skip to content
Browse files

Update changelog and document StatefulToxics

  • Loading branch information
xthexder committed Sep 1, 2016
1 parent e8cd761 commit ee8478ae932ecdbca544681031c154bedea6171f
Showing with 23 additions and 0 deletions.
  1. +5 −0
  2. +18 −0
@@ -1,3 +1,8 @@
# 2.1.0 (Unreleased)

* Add support for stateful toxics
* Add limit_data toxic

# 2.0.0

* Add CLI (`toxiproxy-cli`) and rename server binary to `toxiproxy-server` #93
@@ -115,6 +115,24 @@ The unit used by `GetBufferSize()` is `StreamChunk`s. Chunks are generally anywh
1 byte, up to 32KB, so keep this in mind when thinking about how much buffering you need,
and how much memory you are comfortable with using.

## Stateful toxics

If a toxic needs to store extra information for a connection such as the number of bytes
transferred (See `limit_data` toxic), a state object can be created by implementing the
`StatefulToxic` interface. This interface defines the `NewState()` function that can create
a new state object with default values set.

When a stateful toxic is created, the state object will be stored on the `ToxicStub` and
can be accessed from `toxic.Pipe()`:

state := stub.State.(*ExampleToxicState)

If necessary, some global state can be stored in the toxic struct, which will not be
instanced per-connection. These fields cannot have a custom default value set and will
not be thread-safe, so proper locking or atomic operations will need to be used.

## Using `io.Reader` and `io.Writer`

If your toxic involves modifying the data going through a proxy, you can use the `ChanReader`

0 comments on commit ee8478a

Please sign in to comment.
You can’t perform that action at this time.