summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Sessions
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-16 20:25:43 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-16 20:25:43 +0400
commit412919e88e1d60303f7a14134e37f27becf5f959 (patch)
tree89711599f2ca1101c1d905e65516b2778c50fd07 /src/Network/BitTorrent/Sessions
parent8c6e5818ee6b901efd975392c54aff5cf2721ae4 (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')
-rw-r--r--src/Network/BitTorrent/Sessions/Types.lhs18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/Network/BitTorrent/Sessions/Types.lhs b/src/Network/BitTorrent/Sessions/Types.lhs
index 69411d4e..af2a6755 100644
--- a/src/Network/BitTorrent/Sessions/Types.lhs
+++ b/src/Network/BitTorrent/Sessions/Types.lhs
@@ -299,7 +299,7 @@ So if client is a leecher then max sessions count depends on the
299number of unchoke slots. 299number of unchoke slots.
300 300
301> -- | Used to bound the number of simultaneous connections and, which 301> -- | Used to bound the number of simultaneous connections and, which
302> -- is the same, P2P sessions within the swarm session. 302> -- is the same, P2P sessions within the swarm session.
303> type SessionCount = Int 303> type SessionCount = Int
304 304
305However if client is a seeder then the value depends on . 305However if client is a seeder then the value depends on .
@@ -322,8 +322,6 @@ Throttling* section.
322Client bitfield is used to keep track "the client have" piece set. 322Client bitfield is used to keep track "the client have" piece set.
323Modify this carefully always updating global progress. 323Modify this carefully always updating global progress.
324 324
325> , clientBitfield :: !(TVar Bitfield)
326
327> , storage :: !Storage 325> , storage :: !Storage
328 326
329We keep set of the all connected peers for the each particular torrent 327We keep set of the all connected peers for the each particular torrent
@@ -371,7 +369,7 @@ INVARIANT: max_sessions_count - sizeof connectedPeers = value vacantPeers
371> compare = comparing (tInfoHash . torrentMeta) 369> compare = comparing (tInfoHash . torrentMeta)
372 370
373> getClientBitfield :: SwarmSession -> IO Bitfield 371> getClientBitfield :: SwarmSession -> IO Bitfield
374> getClientBitfield = readTVarIO . clientBitfield 372> getClientBitfield SwarmSession {..} = atomically $ getCompleteBitfield storage
375 373
376Peer sessions 374Peer sessions
377------------------------------------------------------------------------ 375------------------------------------------------------------------------
@@ -458,16 +456,14 @@ messages & events we should send.
4582. Update downloaded stats --/ 4562. Update downloaded stats --/
4593. Signal to the all other peer about this. 4573. Signal to the all other peer about this.
460 458
461> available :: Bitfield -> SwarmSession -> IO () 459> available :: Bitfield -> SwarmSession -> STM ()
462> available bf se @ SwarmSession {..} = {-# SCC available #-} do 460> available bf SwarmSession {..} = {-# SCC available #-} do
463> mark >> atomically broadcast 461> updateProgress >> broadcast
464> where 462> where
465> mark = do 463> updateProgress = do
466> let piLen = ciPieceLength $ tInfo $ torrentMeta 464> let piLen = ciPieceLength $ tInfo $ torrentMeta
467> let bytes = piLen * BF.haveCount bf 465> let bytes = piLen * BF.haveCount bf
468> atomically $ do 466> modifyTVar' (currentProgress clientSession) (downloadedProgress bytes)
469> modifyTVar' clientBitfield (BF.union bf)
470> modifyTVar' (currentProgress clientSession) (downloadedProgress bytes)
471> 467>
472> broadcast = mapM_ (writeTChan broadcastMessages . Have) (BF.toList bf) 468> broadcast = mapM_ (writeTChan broadcastMessages . Have) (BF.toList bf)
473 469