network-control-0.1.0: Library to control network protocols
Safe HaskellSafe-Inferred
LanguageHaskell2010

Network.Control

Description

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

Synopsis

Flow control

This is based on the total approach of QUIC rather than the difference approach of HTTP/2 because QUIC'one is considered safer. Please refer to Using HTTP/3 Stream Limits in HTTP/2 to understand that QUIC's approaches are better though its topic is about stream concurrency.

Constants for flow control.

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. (1M bytes)

Flow control for sending

data TxFlow Source #

Flow for sending

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

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

Constructors

TxFlow 

Fields

Instances

Instances details
Show TxFlow Source # 
Instance details

Defined in Network.Control.Flow

Eq TxFlow Source # 
Instance details

Defined in Network.Control.Flow

Methods

(==) :: TxFlow -> TxFlow -> Bool #

(/=) :: TxFlow -> TxFlow -> Bool #

newTxFlow :: WindowSize -> TxFlow Source #

Creating TX flow with a receive buffer size.

type WindowSize = Int Source #

Window size.

Flow control for receiving

data RxFlow Source #

Flow for receiving.

                rxfBufSize
       |------------------------|
-------------------------------------->
       ^            ^           ^
  rxfConsumed   rxfReceived  rxfLimit

                    |-----------| The size which the peer can send
                       Window

Constructors

RxFlow 

Fields

Instances

Instances details
Show RxFlow Source # 
Instance details

Defined in Network.Control.Flow

Eq RxFlow Source # 
Instance details

Defined in Network.Control.Flow

Methods

(==) :: RxFlow -> RxFlow -> Bool #

(/=) :: RxFlow -> RxFlow -> Bool #

newRxFlow :: WindowSize -> RxFlow Source #

Creating RX flow with an initial window size.

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.

When an application consumed received data, this function should be called to update rxfConsumed. If the available buffer size is less than the half of the total buffer size. the representation of window size update is returned.

Example:

                rxfBufSize
       |------------------------|
-------------------------------------->
       ^            ^           ^
  rxfConsumed   rxfReceived  rxfLimit
                    |01234567890|

In the case where the window update should be informed to the peer,
rxfConsumed and rxfLimit move to the right. The difference
of old and new rxfLimit is window update.

                  rxfBufSize
         |------------------------|
-------------------------------------->
         ^          ^             ^
    rxfConsumed rxfReceived    rxfLimit
                    |0123456789012| : window glows

Otherwise, only rxfConsumed moves to the right.

                rxfBufSize
       |------------------------|
-------------------------------------->
         ^          ^           ^
    rxfConsumed rxfReceived  rxfLimit
                    |01234567890| : window stays

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.

LRU cache

data LRUCache k v Source #

Sized cache based on least recently used.

empty Source #

Arguments

:: Int

The size of LRUCache.

-> LRUCache k v 

Empty LRUCache.

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

Inserting.

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

Deleting.

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

Looking up.

Rate control

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.