network-control-0.1.7: Library to control network protocols

Safe Haskell | None
Language | Haskell2010

Network.Control

Description

Common parts to control network protocols. This library assumes that `Int` is 64bit.

Synopsis

- defaultMaxStreams :: Int
- defaultMaxStreamData :: Int
- defaultMaxData :: Int
- data TxFlow = TxFlow {
  - txfSent :: Int
  - txfLimit :: Int
  }
- newTxFlow :: WindowSize -> TxFlow
- txWindowSize :: TxFlow -> WindowSize
- type WindowSize = Int
- data RxFlow = RxFlow {
  - rxfBufSize :: Int
  - rxfConsumed :: Int
  - rxfReceived :: Int
  - rxfLimit :: Int
  }
- newRxFlow :: WindowSize -> RxFlow
- rxWindowSize :: RxFlow -> WindowSize
- data FlowControlType
  - = FCTWindowUpdate
  - | FCTMaxData
- maybeOpenRxWindow :: Int -> FlowControlType -> RxFlow -> (RxFlow, Maybe Int)
- checkRxLimit :: Int -> RxFlow -> (RxFlow, Bool)
- empty :: Int -> LRUCache k v
- lookup :: Ord k => k -> LRUCache k v -> Maybe v
- delete :: Ord k => k -> LRUCache k v -> LRUCache k v
- insert :: Ord k => k -> v -> LRUCache k v -> LRUCache k v
- data LRUCache k v
- lookup' :: Ord k => k -> LRUCache k v -> Maybe (v, LRUCache k v)
- data LRUCacheRef k v
- newLRUCacheRef :: Int -> IO (LRUCacheRef k v)
- cached :: Ord k => LRUCacheRef k v -> k -> IO v -> IO (v, Bool)
- cached' :: Ord k => LRUCacheRef k v -> k -> IO (Maybe v)
- setLRUCapacity :: LRUCacheRef k v -> Int -> IO ()
- empty' :: Int -> Int64 -> LRUCache k v
- data Rate
- newRate :: IO Rate
- getRate :: Rate -> IO Int
- addRate :: Rate -> Int -> IO Int

# Documentation

defaultMaxStreams :: Int Source #

Default max streams. (64)

defaultMaxStreamData :: Int Source #

Default max data of a stream. (256K bytes)

defaultMaxData :: Int Source #

Default max data of a connection.

By default, this is set to `defaultMaxStreams * defaultMaxStreamData`. This ensures that streams that are not currently handled cannot exhaust the connection window.

If you use a smaller connection window size, you must ensure that if you are handling fewer concurrent streams than allowed by `defaultMaxStreams`, that the unhandled streams cannot exhaust the connection window, or risk the entire system deadlocking.

data TxFlow Source #

Flow for sending

    -------------------------------------->
           ^           ^
        txfSent    txfLimit

           |-----------| The size which this node can send
           txWindowSize

Constructors

TxFlow |

Fields

- txfSent :: Int

  The total size of sent data.

- txfLimit :: Int

  The total size of data which can be sent.

#### Instances

Instances details

Show TxFlow Source # |
Instance details Defined in Network.Control.Flow Methods showsPrec :: Int -> TxFlow -> ShowS Source # show :: TxFlow -> String Source # showList :: [TxFlow] -> ShowS Source #
Eq TxFlow Source # |
Instance details Defined in Network.Control.Flow Methods (==) :: TxFlow -> TxFlow -> Bool Source # (/=) :: TxFlow -> TxFlow -> Bool Source #

newTxFlow :: WindowSize -> TxFlow Source #

Creating TX flow with a receive buffer size.

txWindowSize :: TxFlow -> WindowSize Source #

`txfLimit` - `txfSent`.

type WindowSize = Int Source #

Window size.

data RxFlow Source #

Flow for receiving.

The goal of `RxFlow` is to ensure that our network peer does not send us data faster than we can consume it. We therefore impose a maximum number of unconsumed bytes that we are willing to receive from the peer, which we refer to as the buffer size:

                       rxfBufSize
              |---------------------------|
    -------------------------------------------->
              ^              ^
         rxfConsumed    rxvReceived

The peer does not know of course how many bytes we have consumed of the data that they sent us, so they keep track of their own limit of how much data they are allowed to send. We keep track of this limit also:

                       rxfBufSize
              |---------------------------|
    -------------------------------------------->
              ^              ^       ^
         rxfConsumed    rxvReceived  |
                                  rxfLimit

Each time we receive data from the peer, we check that they do not exceed the limit (`checkRxLimit`). When we consume data, we periodically send the peer an update (known as a _window update_) of what their new limit is (`maybeOpenRxWindow`). To decrease overhead, we only this if the window update is at least half the window size.

Constructors

RxFlow |

Fields

- rxfBufSize :: Int

  Maxinum number of unconsumed bytes the peer can send us

  See discussion above for details.

- rxfConsumed :: Int

  How much of the data that the peer has sent us have we consumed?

  This is an absolute number: the total about of bytes consumed over the lifetime of the connection or stream (i.e., not relative to the window).

- rxfReceived :: Int

  How much data have we received from the peer?

  Like `rxfConsumed`, this is an absolute number.

- rxfLimit :: Int

  Current limit on how many bytes the peer is allowed to send us.

  Like 'rxfConsumed, this is an absolute number.

#### Instances

Instances details

Show RxFlow Source # |
Instance details Defined in Network.Control.Flow Methods showsPrec :: Int -> RxFlow -> ShowS Source # show :: RxFlow -> String Source # showList :: [RxFlow] -> ShowS Source #
Eq RxFlow Source # |
Instance details Defined in Network.Control.Flow Methods (==) :: RxFlow -> RxFlow -> Bool Source # (/=) :: RxFlow -> RxFlow -> Bool Source #

newRxFlow :: WindowSize -> RxFlow Source #

Creating RX flow with an initial window size.

rxWindowSize :: RxFlow -> WindowSize Source #

`rxfLimit` - `rxfReceived`.

This is the number of bytes the peer is still allowed to send before they must wait for a window update; see `RxFlow` for details.

data FlowControlType Source #

The representation of window size update.

Constructors

FCTWindowUpdate | HTTP/2 style
FCTMaxData | QUIC style

maybeOpenRxWindow Source #

Arguments

:: Int | The consumed size.
-> FlowControlType |
-> RxFlow |
-> (RxFlow, Maybe Int) | `Just` if the size should be informed to the peer.

Record that we have consumed some received data

May return a window update; see `RxFlow` for details.

checkRxLimit Source #

Arguments

:: Int | The size of received data.
-> RxFlow |
-> (RxFlow, Bool) | Acceptable if `True`.

Checking if received data is acceptable against the current window.

empty Source #

Arguments

:: Int | The size of `LRUCache`.
-> LRUCache k v |

Empty `LRUCache`. O(1)

lookup :: Ord k => k -> LRUCache k v -> Maybe v Source #

Looking up. O(log n)

delete :: Ord k => k -> LRUCache k v -> LRUCache k v Source #

Deleting. O(log n)

insert :: Ord k => k -> v -> LRUCache k v -> LRUCache k v Source #

Inserting. O(log n)

data LRUCache k v Source #

Sized cache based on least recently used.

#### Instances

Instances details

(Show v, Show k) => Show (LRUCache k v) Source # |
Instance details Defined in Network.Control.LRUCache Methods showsPrec :: Int -> LRUCache k v -> ShowS Source # show :: LRUCache k v -> String Source # showList :: [LRUCache k v] -> ShowS Source #
(Ord k, Eq v) => Eq (LRUCache k v) Source # |
Instance details Defined in Network.Control.LRUCache Methods (==) :: LRUCache k v -> LRUCache k v -> Bool Source # (/=) :: LRUCache k v -> LRUCache k v -> Bool Source #

lookup' :: Ord k => k -> LRUCache k v -> Maybe (v, LRUCache k v) Source #

Looking up and changing priority. O(log n)

data LRUCacheRef k v Source #

Mutable LRUCache.

newLRUCacheRef :: Int -> IO (LRUCacheRef k v) Source #

Creating `LRUCacheRef`.

cached :: Ord k => LRUCacheRef k v -> k -> IO v -> IO (v, Bool) Source #

Looking up a target and adjusting the LRU cache. If not found, a new value is inserted. A pair of value and "found" is returned.

cached' :: Ord k => LRUCacheRef k v -> k -> IO (Maybe v) Source #

Looking up a target and adjusting the LRU cache.

setLRUCapacity :: LRUCacheRef k v -> Int -> IO () Source #

Setting capacity of the LRU cache.

empty' Source #

Arguments

:: Int | The size of `LRUCache`.
-> Int64 | Counter
-> LRUCache k v |

Empty `LRUCache`. O(1)

data Rate Source #

Type for rating.

newRate :: IO Rate Source #

Creating a new `Rate`.

getRate :: Rate -> IO Int Source #

Getting the current rate. If one or more seconds have passed since the previous call, the counter is re-initialized with 1 and it is returned. Otherwise, incremented counter number is returned.

addRate :: Rate -> Int -> IO Int Source #

Getting the current rate. If one or more seconds have passed since the previous call, the counter is re-initialized with the second argument and it is returned. Otherwise, increased counter number is returned.