summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Internal.lhs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-13 23:06:21 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-13 23:06:21 +0400
commit5a4a37953226702485aaeca137ba9ea3dc6c4356 (patch)
tree38d8519258ea0b1fff8298dcbdcd246e4e71985d /src/Network/BitTorrent/Internal.lhs
parent07fb54d4844a7667dcef10527d0d3c010f851768 (diff)
~ Minor changes.
Diffstat (limited to 'src/Network/BitTorrent/Internal.lhs')
-rw-r--r--src/Network/BitTorrent/Internal.lhs39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/Network/BitTorrent/Internal.lhs b/src/Network/BitTorrent/Internal.lhs
index d30057f7..23b3708a 100644
--- a/src/Network/BitTorrent/Internal.lhs
+++ b/src/Network/BitTorrent/Internal.lhs
@@ -274,7 +274,7 @@ so we need to do this on demand: if a peer asks for a block, we
274validate corresponding piece and only after read and send the block 274validate corresponding piece and only after read and send the block
275back. 275back.
276 276
277> registerTorrent :: TVar TorrentMap -> InfoHash -> TorrentLoc -> IO () 277> registerTorrent :: TVar TorrentMap -> TorrentLoc -> IO ()
278> registerTorrent = error "registerTorrent" 278> registerTorrent = error "registerTorrent"
279> {- 279> {-
280> Torrent {..} <- validateTorrent tl 280> Torrent {..} <- validateTorrent tl
@@ -498,7 +498,7 @@ Modify this carefully always updating global progress.
498 498
499> , clientBitfield :: !(TVar Bitfield) 499> , clientBitfield :: !(TVar Bitfield)
500 500
501-- > , storage :: Storage 501> , storage :: !Storage
502 502
503We keep set of the all connected peers for the each particular torrent 503We keep set of the all connected peers for the each particular torrent
504to prevent duplicated and therefore reduntant TCP connections. For 504to prevent duplicated and therefore reduntant TCP connections. For
@@ -547,14 +547,41 @@ INVARIANT: max_sessions_count - sizeof connectedPeers = value vacantPeers
547> newSwarmSession :: Int -> Bitfield -> ClientSession -> Torrent 547> newSwarmSession :: Int -> Bitfield -> ClientSession -> Torrent
548> -> IO SwarmSession 548> -> IO SwarmSession
549> newSwarmSession n bf cs @ ClientSession {..} t @ Torrent {..} 549> newSwarmSession n bf cs @ ClientSession {..} t @ Torrent {..}
550> = SwarmSession <$> pure t 550> = SwarmSession t cs
551> <*> pure cs 551> <$> MSem.new n
552> <*> MSem.new n
553> <*> newTVarIO bf 552> <*> newTVarIO bf
553> <*> undefined
554> <*> newTVarIO S.empty 554> <*> newTVarIO S.empty
555> <*> newBroadcastTChanIO 555> <*> newBroadcastTChanIO
556 556
557> -- | New swarm session in which the client allowed to upload only. 557-- > openSwarmSession :: ClientSession -> InfoHash -> IO SwarmSession
558-- > openSwarmSession ClientSession {..} ih = do
559-- > loc <- HM.lookup <$> readTVarIO torrentMap
560-- > torrent <- validateLocation loc
561-- > return undefined
562
563> closeSwarmSession :: SwarmSession -> IO ()
564> closeSwarmSession se @ SwarmSession {..} = do
565> unregisterSwarmSession se
566> -- TODO stop discovery
567> -- TODO killall peer sessions
568> -- TODO the order is important!
569> closeStorage storage
570
571
572
573> unregisterSwarmSession :: SwarmSession -> IO ()
574> unregisterSwarmSession SwarmSession {..} =
575> atomically $ modifyTVar (swarmSessions clientSession) $
576> M.delete $ tInfoHash torrentMeta
577
578getSwarm :: ClientSession -> InfoHash -> IO SwarmSession
579getSwarm cs @ ClientSession {..} ih = do
580 ss <- readTVarIO $ swarmSessions
581 case HM.lookup ih ss of
582 Just sw -> return sw
583 Nothing -> openSwarm cs
584
558> newSeeder :: ClientSession -> Torrent -> IO SwarmSession 585> newSeeder :: ClientSession -> Torrent -> IO SwarmSession
559> newSeeder cs t @ Torrent {..} 586> newSeeder cs t @ Torrent {..}
560> = newSwarmSession defSeederConns (haveAll (pieceCount tInfo)) cs t 587> = newSwarmSession defSeederConns (haveAll (pieceCount tInfo)) cs t