diff options
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r-- | src/Network/BitTorrent.hs | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs index 3602dd7e..06df77dd 100644 --- a/src/Network/BitTorrent.hs +++ b/src/Network/BitTorrent.hs | |||
@@ -17,8 +17,7 @@ module Network.BitTorrent | |||
17 | -- ** Client | 17 | -- ** Client |
18 | , ClientSession( clientPeerId, allowedExtensions ) | 18 | , ClientSession( clientPeerId, allowedExtensions ) |
19 | 19 | ||
20 | , newClient | 20 | , withDefaultClient |
21 | , defaultClient | ||
22 | 21 | ||
23 | , Progress(..) | 22 | , Progress(..) |
24 | , getCurrentProgress | 23 | , getCurrentProgress |
@@ -91,36 +90,25 @@ import Network | |||
91 | import Data.Bitfield as BF | 90 | import Data.Bitfield as BF |
92 | import Data.Torrent | 91 | import Data.Torrent |
93 | import Network.BitTorrent.Internal | 92 | import Network.BitTorrent.Internal |
93 | import Network.BitTorrent.Peer | ||
94 | import Network.BitTorrent.Extension | ||
94 | import Network.BitTorrent.Exchange | 95 | import Network.BitTorrent.Exchange |
95 | import Network.BitTorrent.Exchange.Protocol | 96 | import Network.BitTorrent.Exchange.Protocol |
96 | import Network.BitTorrent.Tracker | 97 | import Network.BitTorrent.Tracker |
97 | import Network.BitTorrent.Extension | 98 | import Network.BitTorrent.Discovery |
98 | import Network.BitTorrent.Peer | ||
99 | 99 | ||
100 | import System.Torrent.Storage | 100 | import System.Torrent.Storage |
101 | 101 | ||
102 | -- TODO remove fork from Network.BitTorrent.Exchange | ||
103 | -- TODO make all forks in Internal. | ||
102 | 104 | ||
103 | -- | Client session with default parameters. Use it for testing only. | 105 | -- | Client session with default parameters. Use it for testing only. |
104 | defaultClient :: IO ClientSession | 106 | withDefaultClient :: PortNumber -> PortNumber -> (ClientSession -> IO ()) -> IO () |
105 | defaultClient = newClient defaultThreadCount defaultExtensions | 107 | withDefaultClient dhtPort listPort action = do |
106 | 108 | withClientSession defaultThreadCount defaultExtensions $ \client -> do | |
107 | -- discover should hide tracker and DHT communication under the hood | 109 | startListener client listPort |
108 | -- thus we can obtain an unified interface | 110 | startDHT client dhtPort |
109 | 111 | action client | |
110 | discover :: SwarmSession -> P2P () -> IO () | ||
111 | discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do | ||
112 | let conn = TConnection (tAnnounce torrentMeta) | ||
113 | (tInfoHash torrentMeta) | ||
114 | (clientPeerId clientSession) | ||
115 | (listenerPort clientSession) | ||
116 | |||
117 | progress <- getCurrentProgress clientSession | ||
118 | |||
119 | withTracker progress conn $ \tses -> do | ||
120 | forever $ do | ||
121 | addr <- getPeerAddr tses | ||
122 | spawnP2P swarm addr $ do | ||
123 | action | ||
124 | 112 | ||
125 | {----------------------------------------------------------------------- | 113 | {----------------------------------------------------------------------- |
126 | Torrent management | 114 | Torrent management |