packages feed

network-control 0.1.7 → 0.2.0

raw patch · 5 files changed

+37/−22 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Network.Control: RxFlow :: Int -> Int -> Int -> Int -> RxFlow
+ Network.Control: RxFlow :: Int64 -> Int64 -> Int64 -> Int64 -> RxFlow
- Network.Control: TxFlow :: Int -> Int -> TxFlow
+ Network.Control: TxFlow :: Int64 -> Int64 -> TxFlow
- Network.Control: [rxfBufSize] :: RxFlow -> Int
+ Network.Control: [rxfBufSize] :: RxFlow -> Int64
- Network.Control: [rxfConsumed] :: RxFlow -> Int
+ Network.Control: [rxfConsumed] :: RxFlow -> Int64
- Network.Control: [rxfLimit] :: RxFlow -> Int
+ Network.Control: [rxfLimit] :: RxFlow -> Int64
- Network.Control: [rxfReceived] :: RxFlow -> Int
+ Network.Control: [rxfReceived] :: RxFlow -> Int64
- Network.Control: [txfLimit] :: TxFlow -> Int
+ Network.Control: [txfLimit] :: TxFlow -> Int64
- Network.Control: [txfSent] :: TxFlow -> Int
+ Network.Control: [txfSent] :: TxFlow -> Int64
- Network.Control: checkRxLimit :: Int -> RxFlow -> (RxFlow, Bool)
+ Network.Control: checkRxLimit :: Int64 -> RxFlow -> (RxFlow, Bool)
- Network.Control: maybeOpenRxWindow :: Int -> FlowControlType -> RxFlow -> (RxFlow, Maybe Int)
+ Network.Control: maybeOpenRxWindow :: Int64 -> FlowControlType -> RxFlow -> (RxFlow, Maybe Int64)
- Network.Control: newRxFlow :: WindowSize -> RxFlow
+ Network.Control: newRxFlow :: Int64 -> RxFlow
- Network.Control: newTxFlow :: WindowSize -> TxFlow
+ Network.Control: newTxFlow :: Int64 -> TxFlow
- Network.Control: rxWindowSize :: RxFlow -> WindowSize
+ Network.Control: rxWindowSize :: RxFlow -> Int64
- Network.Control: txWindowSize :: TxFlow -> WindowSize
+ Network.Control: txWindowSize :: TxFlow -> Int64

Files

Changelog.md view
@@ -1,5 +1,10 @@ # Revision history for network-control +## 0.2.0++* Use Int64 for the amounts of TxFlow and RxFlow+  [#9](https://github.com/kazu-yamamoto/network-control/pull/9)+ ## 0.1.7  * Implementing setLRUCapacity.
Network/Control.hs view
@@ -1,5 +1,4 @@ -- | Common parts to control network protocols.---   This library assumes that 'Int' is 64bit. module Network.Control (     module Network.Control.Flow,     module Network.Control.LRUCache,
Network/Control/Flow.hs view
@@ -28,6 +28,7 @@ ) where  import Data.Bits+import Data.Int (Int64)  -- | Default max streams. (64) defaultMaxStreams :: Int@@ -50,7 +51,9 @@ defaultMaxData :: Int defaultMaxData = defaultMaxStreamData * defaultMaxStreams --- | Window size.+-- | Window size.  The amounts in 'TxFlow' and 'RxFlow' are 'Int64'+--   instead: they are totals over a connection's life, which in QUIC go up+--   to 2^62 whatever the size of 'Int'. type WindowSize = Int  -- | Flow for sending@@ -64,19 +67,19 @@ --        txWindowSize -- @ data TxFlow = TxFlow-    { txfSent :: Int+    { txfSent :: Int64     -- ^ The total size of sent data.-    , txfLimit :: Int+    , txfLimit :: Int64     -- ^ The total size of data which can be sent.     }     deriving (Eq, Show)  -- | Creating TX flow with a receive buffer size.-newTxFlow :: WindowSize -> TxFlow+newTxFlow :: Int64 -> TxFlow newTxFlow win = TxFlow 0 win  -- | 'txfLimit' - 'txfSent'.-txWindowSize :: TxFlow -> WindowSize+txWindowSize :: TxFlow -> Int64 txWindowSize TxFlow{..} = txfLimit - txfSent  -- | Flow for receiving.@@ -113,20 +116,20 @@ -- ('maybeOpenRxWindow'). To decrease overhead, we only this if the window -- update is at least half the window size. data RxFlow = RxFlow-    { rxfBufSize :: Int+    { rxfBufSize :: Int64     -- ^ Maxinum number of unconsumed bytes the peer can send us     --     -- See discussion above for details.-    , rxfConsumed :: Int+    , rxfConsumed :: Int64     -- ^ 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+    , rxfReceived :: Int64     -- ^ How much data have we received from the peer?     --     -- Like 'rxfConsumed', this is an absolute number.-    , rxfLimit :: Int+    , rxfLimit :: Int64     -- ^ Current limit on how many bytes the peer is allowed to send us.     --     -- Like 'rxfConsumed, this is an absolute number.@@ -134,14 +137,14 @@     deriving (Eq, Show)  -- | Creating RX flow with an initial window size.-newRxFlow :: WindowSize -> RxFlow+newRxFlow :: Int64 -> RxFlow newRxFlow win = RxFlow win 0 0 win  -- | '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.-rxWindowSize :: RxFlow -> WindowSize+rxWindowSize :: RxFlow -> Int64 rxWindowSize RxFlow{..} = rxfLimit - rxfReceived  -- | The representation of window size update.@@ -155,11 +158,11 @@ -- -- May return a window update; see 'RxFlow' for details. maybeOpenRxWindow-    :: Int+    :: Int64     -- ^ The consumed size.     -> FlowControlType     -> RxFlow-    -> (RxFlow, Maybe Int)+    -> (RxFlow, Maybe Int64)     -- ^ 'Just' if the size should be informed to the peer. maybeOpenRxWindow consumed fct flow@RxFlow{..}     | winUpdate >= threshold =@@ -188,7 +191,7 @@ -- | Checking if received data is acceptable against the --   current window. checkRxLimit-    :: Int+    :: Int64     -- ^ The size of received data.     -> RxFlow     -> (RxFlow, Bool)
network-control.cabal view
@@ -1,6 +1,6 @@ cabal-version:   3.0 name:            network-control-version:         0.1.7+version:         0.2.0 license:         BSD-3-Clause license-file:    LICENSE maintainer:      kazu@iij.ad.jp
test/Network/Control/FlowSpec.hs view
@@ -4,6 +4,7 @@  module Network.Control.FlowSpec (spec) where +import Data.Int (Int64) import Data.List import Data.Text.Lazy (unpack) import Network.Control@@ -17,10 +18,10 @@ data Op = Consume | Receive     deriving (Eq, Show, Bounded, Enum) -data OpWithResult = ConsumeWithResult (Maybe Int) | ReceiveWithResult Bool+data OpWithResult = ConsumeWithResult (Maybe Int64) | ReceiveWithResult Bool     deriving (Eq, Show) -data Step op = Step {stepOp :: op, stepArg :: Int}+data Step op = Step {stepOp :: op, stepArg :: Int64}     deriving (Eq, Show)  data Trace = Trace@@ -31,7 +32,7 @@  -- arbitrary instances -maxWindowSize :: Int+maxWindowSize :: Int64 maxWindowSize = 200 -- (more realistic: 2_000_000)  instance Arbitrary RxFlow where@@ -40,7 +41,7 @@         newRxFlow             <$> oneof                 [ elements [1, 10, 50, 100]-                , chooseInt (1, maxWindowSize)+                , choose (1, maxWindowSize)                 ]  instance Arbitrary Op where@@ -65,12 +66,12 @@             -- size are theoretically possible (but will trivially be rejected             -- as exceeding the window).             mkReceive =-                Step Receive <$> chooseInt (0, rxfBufSize oldFlow * 2)+                Step Receive <$> choose (0, rxfBufSize oldFlow * 2)              -- We can only consume as much as we have received             -- (but it is in principle not a problem to consume 0 bytes)             mkConsume =-                Step Consume <$> chooseInt (0, rxfReceived oldFlow - rxfConsumed oldFlow)+                Step Consume <$> choose (0, rxfReceived oldFlow - rxfConsumed oldFlow)          runStep :: RxFlow -> Step Op -> (Step OpWithResult, RxFlow)         runStep oldFlow = \case@@ -158,3 +159,10 @@     describe "Flow" $ do         prop "state transition graph checks out" $ \trace ->             counterexample (unpack $ pShowNoColor trace) (assertTrace trace)+        -- QUIC's totals go up to 2^62, past a 32-bit Int.+        it "keeps totals past 32 bits" $ do+            let big = 2 ^ (40 :: Int) :: Int64+                (flow, ok) = checkRxLimit big $ newRxFlow (big + 1)+            ok `shouldBe` True+            rxWindowSize flow `shouldBe` 1+            txWindowSize (TxFlow big (big * 2)) `shouldBe` big