diff options
Diffstat (limited to 'src/Network/BitTorrent/Client.hs')
-rw-r--r-- | src/Network/BitTorrent/Client.hs | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/src/Network/BitTorrent/Client.hs b/src/Network/BitTorrent/Client.hs index d8c3ee91..255c4dec 100644 --- a/src/Network/BitTorrent/Client.hs +++ b/src/Network/BitTorrent/Client.hs | |||
@@ -28,6 +28,10 @@ module Network.BitTorrent.Client | |||
28 | , openTorrent | 28 | , openTorrent |
29 | , openMagnet | 29 | , openMagnet |
30 | , closeHandle | 30 | , closeHandle |
31 | |||
32 | , start | ||
33 | , pause | ||
34 | , stop | ||
31 | ) where | 35 | ) where |
32 | 36 | ||
33 | import Control.Exception | 37 | import Control.Exception |
@@ -40,12 +44,13 @@ import Data.Maybe | |||
40 | import Data.Text | 44 | import Data.Text |
41 | import Network | 45 | import Network |
42 | 46 | ||
43 | import Network.BitTorrent.Client.Types | 47 | import Network.BitTorrent.Client.Types |
44 | import Network.BitTorrent.Client.Handle | 48 | import Network.BitTorrent.Client.Handle |
45 | import Network.BitTorrent.Core | 49 | import Network.BitTorrent.Core |
46 | import Network.BitTorrent.DHT | 50 | import Network.BitTorrent.DHT |
47 | import Network.BitTorrent.Tracker as Tracker hiding (Options) | 51 | import Network.BitTorrent.Tracker as Tracker hiding (Options) |
48 | import Network.BitTorrent.Exchange.Message | 52 | import Network.BitTorrent.Exchange as Exchange hiding (Options) |
53 | import qualified Network.BitTorrent.Exchange as Exchange (Options(..)) | ||
49 | 54 | ||
50 | 55 | ||
51 | data Options = Options | 56 | data Options = Options |
@@ -67,30 +72,40 @@ instance Default Options where | |||
67 | , optBootNode = Nothing | 72 | , optBootNode = Nothing |
68 | } | 73 | } |
69 | 74 | ||
75 | exchangeOptions :: PeerId -> Options -> Exchange.Options | ||
76 | exchangeOptions pid Options {..} = Exchange.Options | ||
77 | { optPeerAddr = PeerAddr (Just pid) (peerHost def) optPort | ||
78 | , optBacklog = optBacklog def | ||
79 | } | ||
80 | |||
81 | --connHandler :: HashMap InfoHash Handle -> Handler | ||
82 | connHandler tmap = undefined | ||
83 | |||
70 | newClient :: Options -> LogFun -> IO Client | 84 | newClient :: Options -> LogFun -> IO Client |
71 | newClient Options {..} logger = do | 85 | newClient opts @ Options {..} logger = do |
72 | pid <- genPeerId | 86 | pid <- genPeerId |
73 | ts <- newMVar HM.empty | 87 | tmap <- newMVar HM.empty |
74 | let peerInfo = PeerInfo pid Nothing optPort | 88 | tmgr <- Tracker.newManager def (PeerInfo pid Nothing optPort) |
75 | mgr <- Tracker.newManager def peerInfo | 89 | emgr <- Exchange.newManager (exchangeOptions pid opts) connHandler |
76 | node <- runResourceT $ do | 90 | node <- runResourceT $ do |
77 | node <- startNode handlers def optNodeAddr logger | 91 | node <- startNode handlers def optNodeAddr logger |
78 | runDHT node $ bootstrap (maybeToList optBootNode) | 92 | runDHT node $ bootstrap (maybeToList optBootNode) |
79 | return node | 93 | return node |
80 | |||
81 | return Client | 94 | return Client |
82 | { clientPeerId = pid | 95 | { clientPeerId = pid |
83 | , clientListenerPort = optPort | 96 | , clientListenerPort = optPort |
84 | , allowedExtensions = toCaps optExtensions | 97 | , allowedExtensions = toCaps optExtensions |
85 | , trackerManager = mgr | 98 | , trackerManager = tmgr |
99 | , exchangeManager = emgr | ||
86 | , clientNode = node | 100 | , clientNode = node |
87 | , clientTorrents = ts | 101 | , clientTorrents = tmap |
88 | , clientLogger = logger | 102 | , clientLogger = logger |
89 | } | 103 | } |
90 | 104 | ||
91 | closeClient :: Client -> IO () | 105 | closeClient :: Client -> IO () |
92 | closeClient Client {..} = do | 106 | closeClient Client {..} = do |
93 | Tracker.closeManager trackerManager | 107 | Exchange.closeManager exchangeManager |
108 | Tracker.closeManager trackerManager | ||
94 | return () | 109 | return () |
95 | -- closeNode clientNode | 110 | -- closeNode clientNode |
96 | 111 | ||