diff options
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r-- | src/Network/BitTorrent.hs | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs index c37129cb..8f0f42ce 100644 --- a/src/Network/BitTorrent.hs +++ b/src/Network/BitTorrent.hs | |||
@@ -7,35 +7,50 @@ | |||
7 | -- | 7 | -- |
8 | {-# LANGUAGE RecordWildCards #-} | 8 | {-# LANGUAGE RecordWildCards #-} |
9 | module Network.BitTorrent | 9 | module Network.BitTorrent |
10 | ( module BT | 10 | ( |
11 | , module Data.Torrent | 11 | module Data.Torrent |
12 | 12 | ||
13 | -- * Tracker | 13 | -- * Session |
14 | , ClientSession | ||
15 | , newClient | ||
14 | 16 | ||
15 | -- * P2P | 17 | , SwarmSession |
16 | , ClientSession, newClient | 18 | , newLeacher, newSeeder |
17 | , SwarmSession, newLeacher, newSeeder | 19 | |
18 | , PeerSession | 20 | -- * Discovery |
19 | , discover | 21 | , discover |
22 | |||
23 | -- * Peer to Peer | ||
24 | , P2P, PeerSession | ||
25 | ( connectedPeerAddr, enabledExtensions | ||
26 | , peerBitfield, peerSessionStatus | ||
27 | ) | ||
28 | |||
29 | , awaitEvent, signalEvent | ||
20 | ) where | 30 | ) where |
21 | 31 | ||
32 | import Control.Monad | ||
22 | import Data.IORef | 33 | import Data.IORef |
23 | 34 | ||
24 | import Data.Torrent | 35 | import Data.Torrent |
25 | import Network.BitTorrent.Internal | 36 | import Network.BitTorrent.Internal |
26 | import Network.BitTorrent.Extension as BT | 37 | import Network.BitTorrent.Exchange |
27 | import Network.BitTorrent.Peer as BT | 38 | import Network.BitTorrent.Tracker |
28 | import Network.BitTorrent.Exchange as BT | 39 | |
29 | import Network.BitTorrent.Tracker as BT | 40 | |
30 | 41 | ||
31 | -- discover should hide tracker and DHT communication under the hood | 42 | -- discover should hide tracker and DHT communication under the hood |
32 | -- thus we can obtain unified interface | 43 | -- thus we can obtain unified interface |
33 | 44 | ||
34 | discover :: SwarmSession -> (TSession -> IO a) -> IO a | 45 | discover :: SwarmSession -> P2P () -> IO () |
35 | discover SwarmSession {..} action = do | 46 | discover swarm @ SwarmSession {..} action = do |
36 | let conn = TConnection (tAnnounce torrentMeta) (tInfoHash torrentMeta) | 47 | let conn = TConnection (tAnnounce torrentMeta) (tInfoHash torrentMeta) |
37 | (clientPeerID clientSession) port | 48 | (clientPeerID clientSession) port |
38 | progress <- readIORef (currentProgress clientSession) | 49 | progress <- readIORef (currentProgress clientSession) |
39 | withTracker progress conn action | 50 | withTracker progress conn $ \tses -> do |
51 | forever $ do | ||
52 | addr <- getPeerAddr tses | ||
53 | withPeer swarm addr action | ||
54 | |||
40 | 55 | ||
41 | port = 10000 | 56 | port = 10000 |