diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-16 20:25:43 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-16 20:25:43 +0400 |
commit | 412919e88e1d60303f7a14134e37f27becf5f959 (patch) | |
tree | 89711599f2ca1101c1d905e65516b2778c50fd07 /src/Network/BitTorrent/Sessions.hs | |
parent | 8c6e5818ee6b901efd975392c54aff5cf2721ae4 (diff) |
~ Move client bitfield to storage.
We localize bitfield mutation in storage module this way.
Also fix some warnings.
Diffstat (limited to 'src/Network/BitTorrent/Sessions.hs')
-rw-r--r-- | src/Network/BitTorrent/Sessions.hs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs index 43a34df9..2118ccf0 100644 --- a/src/Network/BitTorrent/Sessions.hs +++ b/src/Network/BitTorrent/Sessions.hs | |||
@@ -202,9 +202,9 @@ discover swarm @ SwarmSession {..} = {-# SCC discover #-} do | |||
202 | forever $ do | 202 | forever $ do |
203 | addr <- getPeerAddr tses | 203 | addr <- getPeerAddr tses |
204 | forkThrottle swarm $ do | 204 | forkThrottle swarm $ do |
205 | initiatePeerSession swarm addr $ \conn -> do | 205 | initiatePeerSession swarm addr $ \pconn -> do |
206 | print addr | 206 | print addr |
207 | runP2P conn p2p | 207 | runP2P pconn p2p |
208 | 208 | ||
209 | registerSwarmSession :: SwarmSession -> STM () | 209 | registerSwarmSession :: SwarmSession -> STM () |
210 | registerSwarmSession ss @ SwarmSession {..} = | 210 | registerSwarmSession ss @ SwarmSession {..} = |
@@ -223,8 +223,7 @@ openSwarmSession cs @ ClientSession {..} loc @ TorrentLoc {..} = do | |||
223 | 223 | ||
224 | ss <- SwarmSession t cs | 224 | ss <- SwarmSession t cs |
225 | <$> MSem.new defLeecherConns | 225 | <$> MSem.new defLeecherConns |
226 | <*> newTVarIO bf | 226 | <*> openStorage t dataDirPath bf |
227 | <*> openStorage t dataDirPath | ||
228 | <*> newTVarIO S.empty | 227 | <*> newTVarIO S.empty |
229 | <*> newBroadcastTChanIO | 228 | <*> newBroadcastTChanIO |
230 | 229 | ||
@@ -232,7 +231,7 @@ openSwarmSession cs @ ClientSession {..} loc @ TorrentLoc {..} = do | |||
232 | modifyTVar' currentProgress $ enqueuedProgress $ contentLength $ tInfo t | 231 | modifyTVar' currentProgress $ enqueuedProgress $ contentLength $ tInfo t |
233 | registerSwarmSession ss | 232 | registerSwarmSession ss |
234 | 233 | ||
235 | forkIO $ discover ss | 234 | _ <- forkIO $ discover ss |
236 | 235 | ||
237 | return ss | 236 | return ss |
238 | 237 | ||
@@ -246,8 +245,8 @@ closeSwarmSession se @ SwarmSession {..} = do | |||
246 | 245 | ||
247 | getSwarm :: ClientSession -> InfoHash -> IO SwarmSession | 246 | getSwarm :: ClientSession -> InfoHash -> IO SwarmSession |
248 | getSwarm cs @ ClientSession {..} ih = do | 247 | getSwarm cs @ ClientSession {..} ih = do |
249 | status <- torrentPresence cs ih | 248 | tstatus <- torrentPresence cs ih |
250 | case status of | 249 | case tstatus of |
251 | Unknown -> throw $ UnknownTorrent ih | 250 | Unknown -> throw $ UnknownTorrent ih |
252 | Active sw -> return sw | 251 | Active sw -> return sw |
253 | Registered loc -> openSwarmSession cs loc | 252 | Registered loc -> openSwarmSession cs loc |
@@ -342,9 +341,11 @@ openSession :: SwarmSession -> PeerAddr -> Handshake -> IO PeerSession | |||
342 | openSession ss @ SwarmSession {..} addr Handshake {..} = do | 341 | openSession ss @ SwarmSession {..} addr Handshake {..} = do |
343 | let clientCaps = encodeExts $ allowedExtensions $ clientSession | 342 | let clientCaps = encodeExts $ allowedExtensions $ clientSession |
344 | let enabled = decodeExts (enabledCaps clientCaps hsReserved) | 343 | let enabled = decodeExts (enabledCaps clientCaps hsReserved) |
344 | |||
345 | bf <- getClientBitfield ss | ||
345 | ps <- PeerSession addr ss enabled | 346 | ps <- PeerSession addr ss enabled |
346 | <$> atomically (dupTChan broadcastMessages) | 347 | <$> atomically (dupTChan broadcastMessages) |
347 | <*> (newIORef . initialSessionState . totalCount =<< readTVarIO clientBitfield) | 348 | <*> newIORef (initialSessionState (totalCount bf)) |
348 | -- TODO we could implement more interesting throtling scheme | 349 | -- TODO we could implement more interesting throtling scheme |
349 | -- using connected peer information | 350 | -- using connected peer information |
350 | registerPeerSession ps | 351 | registerPeerSession ps |
@@ -408,7 +409,7 @@ listener cs action serverPort = bracket openListener close loop | |||
408 | putStrLn "accepted" | 409 | putStrLn "accepted" |
409 | case addr of | 410 | case addr of |
410 | SockAddrInet port host -> do | 411 | SockAddrInet port host -> do |
411 | forkIO $ do | 412 | _ <- forkIO $ do |
412 | acceptPeerSession cs (PeerAddr Nothing host port) conn action | 413 | acceptPeerSession cs (PeerAddr Nothing host port) conn action |
413 | return () | 414 | return () |
414 | _ -> return () | 415 | _ -> return () |