summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r--src/Network/BitTorrent.hs36
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
91import Data.Bitfield as BF 90import Data.Bitfield as BF
92import Data.Torrent 91import Data.Torrent
93import Network.BitTorrent.Internal 92import Network.BitTorrent.Internal
93import Network.BitTorrent.Peer
94import Network.BitTorrent.Extension
94import Network.BitTorrent.Exchange 95import Network.BitTorrent.Exchange
95import Network.BitTorrent.Exchange.Protocol 96import Network.BitTorrent.Exchange.Protocol
96import Network.BitTorrent.Tracker 97import Network.BitTorrent.Tracker
97import Network.BitTorrent.Extension 98import Network.BitTorrent.Discovery
98import Network.BitTorrent.Peer
99 99
100import System.Torrent.Storage 100import 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.
104defaultClient :: IO ClientSession 106withDefaultClient :: PortNumber -> PortNumber -> (ClientSession -> IO ()) -> IO ()
105defaultClient = newClient defaultThreadCount defaultExtensions 107withDefaultClient 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
110discover :: SwarmSession -> P2P () -> IO ()
111discover 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