diff options
author | Joe Crayne <joe@jerkface.net> | 2018-09-08 00:43:34 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2018-09-08 00:43:45 -0400 |
commit | fc871868c05c152c47e716e0f5271d62276ceebb (patch) | |
tree | 6f746920b81d34ca83f400bad9a1f38fda15fb2f | |
parent | d9159028e812f2855558ba183d3c11040d98e408 (diff) |
Documented Network.Lossless.
-rw-r--r-- | src/Network/Lossless.hs | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/Network/Lossless.hs b/src/Network/Lossless.hs index f48dc8fd..ff0b8cc1 100644 --- a/src/Network/Lossless.hs +++ b/src/Network/Lossless.hs | |||
@@ -1,3 +1,9 @@ | |||
1 | -- | This module uses 'Data.PacketBuffer' appropriately to implement a reliable | ||
2 | -- transport over an underlying lossy one. | ||
3 | -- | ||
4 | -- It was written to be a helper to 'Network.Tox.Session' but it is | ||
5 | -- representation-agnostic and so could potentially be used on an unrelated | ||
6 | -- lossy transport. | ||
1 | {-# LANGUAGE CPP #-} | 7 | {-# LANGUAGE CPP #-} |
2 | {-# LANGUAGE LambdaCase #-} | 8 | {-# LANGUAGE LambdaCase #-} |
3 | {-# LANGUAGE TupleSections #-} | 9 | {-# LANGUAGE TupleSections #-} |
@@ -19,21 +25,23 @@ import Control.Concurrent.Lifted.Instrument | |||
19 | import Control.Concurrent.Lifted | 25 | import Control.Concurrent.Lifted |
20 | #endif | 26 | #endif |
21 | 27 | ||
28 | -- | Sequencing information for a packet. | ||
22 | data SequenceInfo = SequenceInfo | 29 | data SequenceInfo = SequenceInfo |
23 | { sequenceNumber :: {-# UNPACK #-} !Word32 | 30 | { sequenceNumber :: {-# UNPACK #-} !Word32 -- ^ Packets are ordered by their 'sequenceNumber'. |
24 | , sequenceAck :: {-# UNPACK #-} !Word32 | 31 | , sequenceAck :: {-# UNPACK #-} !Word32 -- ^ This is the sender's latest received in-order packet. |
25 | } | 32 | } |
26 | deriving (Eq,Ord,Show) | 33 | deriving (Eq,Ord,Show) |
27 | 34 | ||
35 | -- | Obtain a reliable transport form an unreliable one. | ||
28 | lossless :: Show addr => | 36 | lossless :: Show addr => |
29 | (x -> addr -> IO (PacketInboundEvent (x',addr'))) | 37 | (x -> addr -> IO (PacketInboundEvent (x',addr'))) -- ^ Used to classify newly arrived packets. |
30 | -> (SequenceInfo -> x' -> addr' -> IO (Bool,y)) | 38 | -> (SequenceInfo -> x' -> addr' -> IO (Bool,y)) -- ^ Used to encode and classify outbound packets. |
31 | -> addr | 39 | -> addr -- ^ The remote address for this session. |
32 | -> TransportA String addr x y | 40 | -> TransportA String addr x y -- ^ An unreliable lossy transport. |
33 | -> IO ( Transport String addr' x' | 41 | -> IO ( Transport String addr' x' -- ^ A reliable lossless transport. |
34 | , [Word32] -> IO () | 42 | , [Word32] -> IO () -- ^ Use this to request lost packets be re-sent. |
35 | , IO ([Word32],Word32) | 43 | , IO ([Word32],Word32) -- ^ Use this to discover missing packets to request. |
36 | ) | 44 | ) |
37 | lossless isLossless encode saddr udp = do | 45 | lossless isLossless encode saddr udp = do |
38 | pb <- atomically newPacketBuffer | 46 | pb <- atomically newPacketBuffer |
39 | oob <- atomically newTChan -- Out-of-band channel, these packets (or | 47 | oob <- atomically newTChan -- Out-of-band channel, these packets (or |