diff options
Diffstat (limited to 'src/Network/BitTorrent/Client')
-rw-r--r-- | src/Network/BitTorrent/Client/Handle.hs | 7 | ||||
-rw-r--r-- | src/Network/BitTorrent/Client/Types.hs | 27 |
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 | ||
24 | import Control.Concurrent.Chan.Split | 20 | import Control.Concurrent.Chan.Split |
@@ -192,6 +188,3 @@ getHandle ih = do | |||
192 | 188 | ||
193 | getStatus :: Handle -> IO HandleStatus | 189 | getStatus :: Handle -> IO HandleStatus |
194 | getStatus Handle {..} = readMVar handleStatus | 190 | getStatus Handle {..} = readMVar handleStatus |
195 | |||
196 | subscription :: Handle -> IO (ReceivePort HandleEvent) | ||
197 | subscription 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 | ||
24 | import Control.Applicative | 23 | import Control.Applicative |
25 | import Control.Concurrent | 24 | import Control.Concurrent |
26 | import Control.Concurrent.Chan.Split | 25 | import Control.Concurrent.Chan.Split as CS |
27 | import Control.Monad.Base | 26 | import Control.Monad.Base |
28 | import Control.Monad.Logger | 27 | import Control.Monad.Logger |
29 | import Control.Monad.Reader | 28 | import Control.Monad.Reader |
@@ -36,19 +35,17 @@ import Network | |||
36 | import System.Log.FastLogger | 35 | import System.Log.FastLogger |
37 | 36 | ||
38 | import Data.Torrent.InfoHash | 37 | import Data.Torrent.InfoHash |
38 | import Network.BitTorrent.Internal.Types as Types | ||
39 | import Network.BitTorrent.Core | 39 | import Network.BitTorrent.Core |
40 | import Network.BitTorrent.DHT as DHT | 40 | import Network.BitTorrent.DHT as DHT |
41 | import Network.BitTorrent.Exchange as Exchange | 41 | import Network.BitTorrent.Exchange as Exchange |
42 | import Network.BitTorrent.Tracker as Tracker | 42 | import Network.BitTorrent.Tracker as Tracker hiding (Event) |
43 | 43 | ||
44 | data HandleStatus | 44 | data HandleStatus |
45 | = Running | 45 | = Running |
46 | | Stopped | 46 | | Stopped |
47 | deriving (Show, Eq) | 47 | deriving (Show, Eq) |
48 | 48 | ||
49 | data HandleEvent | ||
50 | = StatusChanged HandleStatus | ||
51 | |||
52 | data Handle = Handle | 49 | data 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 | ||
59 | instance EventSource Handle where | ||
60 | data Event Handle = StatusChanged HandleStatus | ||
61 | listen Handle {..} = CS.listen undefined | ||
62 | |||
62 | data Client = Client | 63 | data 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 | ||
75 | instance Eq Client where | 76 | instance Eq Client where |
@@ -78,6 +79,10 @@ instance Eq Client where | |||
78 | instance Ord Client where | 79 | instance Ord Client where |
79 | compare = comparing clientPeerId | 80 | compare = comparing clientPeerId |
80 | 81 | ||
82 | instance 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 | ||
91 | data ClientEvent | ||
92 | = TorrentAdded InfoHash | ||
93 | deriving (Show, Eq) | ||
94 | |||
95 | {----------------------------------------------------------------------- | 96 | {----------------------------------------------------------------------- |
96 | -- BitTorrent monad | 97 | -- BitTorrent monad |
97 | -----------------------------------------------------------------------} | 98 | -----------------------------------------------------------------------} |