summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Internal.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-12 11:16:21 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-12 11:16:21 +0400
commit4e30588737415d59fa36aa7308c037bb8bd8e3d5 (patch)
tree110178a60255633036ac4cdb0fdf4367d8aaf907 /src/Network/BitTorrent/Internal.hs
parenteadb3a6826fb784c33b10b2eab7d4f7bf72b0043 (diff)
+ Add session exception.
Diffstat (limited to 'src/Network/BitTorrent/Internal.hs')
-rw-r--r--src/Network/BitTorrent/Internal.hs27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Internal.hs b/src/Network/BitTorrent/Internal.hs
index da104240..a3e1a5cd 100644
--- a/src/Network/BitTorrent/Internal.hs
+++ b/src/Network/BitTorrent/Internal.hs
@@ -16,6 +16,7 @@
16{-# LANGUAGE OverloadedStrings #-} 16{-# LANGUAGE OverloadedStrings #-}
17{-# LANGUAGE RecordWildCards #-} 17{-# LANGUAGE RecordWildCards #-}
18{-# LANGUAGE TemplateHaskell #-} 18{-# LANGUAGE TemplateHaskell #-}
19{-# LANGUAGE DeriveDataTypeable #-}
19{-# LANGUAGE FlexibleInstances #-} 20{-# LANGUAGE FlexibleInstances #-}
20{-# LANGUAGE FlexibleContexts #-} 21{-# LANGUAGE FlexibleContexts #-}
21{-# LANGUAGE MultiParamTypeClasses #-} 22{-# LANGUAGE MultiParamTypeClasses #-}
@@ -23,20 +24,31 @@
23module Network.BitTorrent.Internal 24module Network.BitTorrent.Internal
24 ( Progress(..), startProgress 25 ( Progress(..), startProgress
25 26
27 -- * Client
26 , ClientSession (clientPeerID, allowedExtensions) 28 , ClientSession (clientPeerID, allowedExtensions)
27 , newClient, getCurrentProgress 29 , newClient, getCurrentProgress
28 30
31 -- * Swarm
29 , SwarmSession(SwarmSession, torrentMeta, clientSession) 32 , SwarmSession(SwarmSession, torrentMeta, clientSession)
30 , newLeacher, newSeeder 33 , newLeacher, newSeeder
31 34
35 -- * Peer
32 , PeerSession(PeerSession, connectedPeerAddr 36 , PeerSession(PeerSession, connectedPeerAddr
33 , swarmSession, enabledExtensions 37 , swarmSession, enabledExtensions
34 ) 38 )
35 , SessionState 39 , SessionState
40 , withPeerSession
41
42 -- ** Exceptions
43 , SessionException(..)
44 , isSessionException
45 , putSessionException
46 , sessionError
47
48 -- ** Properties
36 , bitfield, status 49 , bitfield, status
37 , emptyBF, fullBF, singletonBF, adjustBF 50 , emptyBF, fullBF, singletonBF, adjustBF
38 , getPieceCount, getClientBF 51 , getPieceCount, getClientBF
39 , sessionError, withPeerSession
40 52
41 -- * Timeouts 53 -- * Timeouts
42 , updateIncoming, updateOutcoming 54 , updateIncoming, updateOutcoming
@@ -55,6 +67,7 @@ import Data.Default
55import Data.Function 67import Data.Function
56import Data.Ord 68import Data.Ord
57import Data.Set as S 69import Data.Set as S
70import Data.Typeable
58 71
59import Data.Serialize hiding (get) 72import Data.Serialize hiding (get)
60import Text.PrettyPrint 73import Text.PrettyPrint
@@ -212,6 +225,7 @@ data PeerSession = PeerSession {
212 -- to avoid reduntant KA messages. 225 -- to avoid reduntant KA messages.
213 , outcomingTimeout :: TimeoutKey 226 , outcomingTimeout :: TimeoutKey
214 227
228 -- TODO use dupChan for broadcasting
215 , broadcastMessages :: Chan [Message] 229 , broadcastMessages :: Chan [Message]
216 , sessionState :: IORef SessionState 230 , sessionState :: IORef SessionState
217 } 231 }
@@ -234,6 +248,17 @@ instance (MonadIO m, MonadReader PeerSession m)
234 get = asks sessionState >>= liftIO . readIORef 248 get = asks sessionState >>= liftIO . readIORef
235 put s = asks sessionState >>= \ref -> liftIO $ writeIORef ref s 249 put s = asks sessionState >>= \ref -> liftIO $ writeIORef ref s
236 250
251data SessionException = SessionException
252 deriving (Show, Typeable)
253
254instance Exception SessionException
255
256isSessionException :: Monad m => SessionException -> m ()
257isSessionException _ = return ()
258
259putSessionException :: SessionException -> IO ()
260putSessionException = print
261
237sessionError :: MonadIO m => Doc -> m () 262sessionError :: MonadIO m => Doc -> m ()
238sessionError msg 263sessionError msg
239 = liftIO $ throwIO $ userError $ render $ msg <+> "in session" 264 = liftIO $ throwIO $ userError $ render $ msg <+> "in session"