summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Client.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-11 12:30:50 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-11 12:30:50 +0400
commit0ec910a0fb7c1e5d72e06f00806b85111138461a (patch)
tree396fbcac569a171d9ef0e2ffe59dbd27a7f6978f /src/Network/BitTorrent/Client.hs
parent4fef598f29cbb138e7b93c5011887c2b92a12879 (diff)
Add exchange manager and session to client session
Diffstat (limited to 'src/Network/BitTorrent/Client.hs')
-rw-r--r--src/Network/BitTorrent/Client.hs43
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
33import Control.Exception 37import Control.Exception
@@ -40,12 +44,13 @@ import Data.Maybe
40import Data.Text 44import Data.Text
41import Network 45import Network
42 46
43import Network.BitTorrent.Client.Types 47import Network.BitTorrent.Client.Types
44import Network.BitTorrent.Client.Handle 48import Network.BitTorrent.Client.Handle
45import Network.BitTorrent.Core 49import Network.BitTorrent.Core
46import Network.BitTorrent.DHT 50import Network.BitTorrent.DHT
47import Network.BitTorrent.Tracker as Tracker hiding (Options) 51import Network.BitTorrent.Tracker as Tracker hiding (Options)
48import Network.BitTorrent.Exchange.Message 52import Network.BitTorrent.Exchange as Exchange hiding (Options)
53import qualified Network.BitTorrent.Exchange as Exchange (Options(..))
49 54
50 55
51data Options = Options 56data Options = Options
@@ -67,30 +72,40 @@ instance Default Options where
67 , optBootNode = Nothing 72 , optBootNode = Nothing
68 } 73 }
69 74
75exchangeOptions :: PeerId -> Options -> Exchange.Options
76exchangeOptions pid Options {..} = Exchange.Options
77 { optPeerAddr = PeerAddr (Just pid) (peerHost def) optPort
78 , optBacklog = optBacklog def
79 }
80
81--connHandler :: HashMap InfoHash Handle -> Handler
82connHandler tmap = undefined
83
70newClient :: Options -> LogFun -> IO Client 84newClient :: Options -> LogFun -> IO Client
71newClient Options {..} logger = do 85newClient 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
91closeClient :: Client -> IO () 105closeClient :: Client -> IO ()
92closeClient Client {..} = do 106closeClient 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