summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Client')
-rw-r--r--src/Network/BitTorrent/Client/Handle.hs7
-rw-r--r--src/Network/BitTorrent/Client/Types.hs27
2 files changed, 14 insertions, 20 deletions
diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs
index 25316a0a..0d1b7f92 100644
--- a/src/Network/BitTorrent/Client/Handle.hs
+++ b/src/Network/BitTorrent/Client/Handle.hs
@@ -14,11 +14,7 @@ module Network.BitTorrent.Client.Handle
14 14
15 -- * Query 15 -- * Query
16 , getHandle 16 , getHandle
17 , HandleStatus (..)
18 , getStatus 17 , getStatus
19
20 -- * Events
21 , HandleEvent (..)
22 ) where 18 ) where
23 19
24import Control.Concurrent.Chan.Split 20import Control.Concurrent.Chan.Split
@@ -192,6 +188,3 @@ getHandle ih = do
192 188
193getStatus :: Handle -> IO HandleStatus 189getStatus :: Handle -> IO HandleStatus
194getStatus Handle {..} = readMVar handleStatus 190getStatus Handle {..} = readMVar handleStatus
195
196subscription :: Handle -> IO (ReceivePort HandleEvent)
197subscription Handle {..} = listen handleEvents
diff --git a/src/Network/BitTorrent/Client/Types.hs b/src/Network/BitTorrent/Client/Types.hs
index aa876ff1..c019bc5f 100644
--- a/src/Network/BitTorrent/Client/Types.hs
+++ b/src/Network/BitTorrent/Client/Types.hs
@@ -17,13 +17,12 @@ module Network.BitTorrent.Client.Types
17 , MonadBitTorrent (..) 17 , MonadBitTorrent (..)
18 18
19 -- * Events 19 -- * Events
20 , ClientEvent (..) 20 , Types.Event (..)
21 , HandleEvent (..)
22 ) where 21 ) where
23 22
24import Control.Applicative 23import Control.Applicative
25import Control.Concurrent 24import Control.Concurrent
26import Control.Concurrent.Chan.Split 25import Control.Concurrent.Chan.Split as CS
27import Control.Monad.Base 26import Control.Monad.Base
28import Control.Monad.Logger 27import Control.Monad.Logger
29import Control.Monad.Reader 28import Control.Monad.Reader
@@ -36,19 +35,17 @@ import Network
36import System.Log.FastLogger 35import System.Log.FastLogger
37 36
38import Data.Torrent.InfoHash 37import Data.Torrent.InfoHash
38import Network.BitTorrent.Internal.Types as Types
39import Network.BitTorrent.Core 39import Network.BitTorrent.Core
40import Network.BitTorrent.DHT as DHT 40import Network.BitTorrent.DHT as DHT
41import Network.BitTorrent.Exchange as Exchange 41import Network.BitTorrent.Exchange as Exchange
42import Network.BitTorrent.Tracker as Tracker 42import Network.BitTorrent.Tracker as Tracker hiding (Event)
43 43
44data HandleStatus 44data HandleStatus
45 = Running 45 = Running
46 | Stopped 46 | Stopped
47 deriving (Show, Eq) 47 deriving (Show, Eq)
48 48
49data HandleEvent
50 = StatusChanged HandleStatus
51
52data Handle = Handle 49data Handle = Handle
53 { handleTopic :: !InfoHash 50 { handleTopic :: !InfoHash
54 , handlePrivate :: !Bool 51 , handlePrivate :: !Bool
@@ -56,9 +53,13 @@ data Handle = Handle
56 , handleStatus :: !(MVar HandleStatus) 53 , handleStatus :: !(MVar HandleStatus)
57 , handleTrackers :: !Tracker.Session 54 , handleTrackers :: !Tracker.Session
58 , handleExchange :: !Exchange.Session 55 , handleExchange :: !Exchange.Session
59 , handleEvents :: !(SendPort HandleEvent) 56 , handleEvents :: !(SendPort (Event Handle))
60 } 57 }
61 58
59instance EventSource Handle where
60 data Event Handle = StatusChanged HandleStatus
61 listen Handle {..} = CS.listen undefined
62
62data Client = Client 63data Client = Client
63 { clientPeerId :: !PeerId 64 { clientPeerId :: !PeerId
64 , clientListenerPort :: !PortNumber 65 , clientListenerPort :: !PortNumber
@@ -69,7 +70,7 @@ data Client = Client
69 , clientNode :: !(Node IPv4) 70 , clientNode :: !(Node IPv4)
70 , clientTorrents :: !(MVar (HashMap InfoHash Handle)) 71 , clientTorrents :: !(MVar (HashMap InfoHash Handle))
71 , clientLogger :: !LogFun 72 , clientLogger :: !LogFun
72 , clientEvents :: !(SendPort ClientEvent) 73 , clientEvents :: !(SendPort (Event Client))
73 } 74 }
74 75
75instance Eq Client where 76instance Eq Client where
@@ -78,6 +79,10 @@ instance Eq Client where
78instance Ord Client where 79instance Ord Client where
79 compare = comparing clientPeerId 80 compare = comparing clientPeerId
80 81
82instance EventSource Client where
83 data Event Client = TorrentAdded InfoHash
84 listen Client {..} = CS.listen clientEvents
85
81-- | External IP address of a host running a bittorrent client 86-- | External IP address of a host running a bittorrent client
82-- software may be used to acknowledge remote peer the host connected 87-- software may be used to acknowledge remote peer the host connected
83-- to. See 'Network.BitTorrent.Exchange.Message.ExtendedHandshake'. 88-- to. See 'Network.BitTorrent.Exchange.Message.ExtendedHandshake'.
@@ -88,10 +93,6 @@ externalAddr Client {..} = PeerAddr
88 , peerPort = clientListenerPort 93 , peerPort = clientListenerPort
89 } 94 }
90 95
91data ClientEvent
92 = TorrentAdded InfoHash
93 deriving (Show, Eq)
94
95{----------------------------------------------------------------------- 96{-----------------------------------------------------------------------
96-- BitTorrent monad 97-- BitTorrent monad
97-----------------------------------------------------------------------} 98-----------------------------------------------------------------------}