summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Sessions.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Sessions.hs')
-rw-r--r--src/Network/BitTorrent/Sessions.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs
index 8bfa64d1..1d0d21b4 100644
--- a/src/Network/BitTorrent/Sessions.hs
+++ b/src/Network/BitTorrent/Sessions.hs
@@ -29,19 +29,28 @@ module Network.BitTorrent.Sessions
29 , getCurrentProgress 29 , getCurrentProgress
30 , getSwarmCount 30 , getSwarmCount
31 , getPeerCount 31 , getPeerCount
32 , getActiveSwarms
32 , getSwarm 33 , getSwarm
33 , getStorage 34 , getStorage
34 , getTorrentInfo 35 , getTorrentInfo
35 , openSwarmSession 36 , openSwarmSession
36 37
37 -- * Swarm 38 -- * Swarm
38 , SwarmSession( SwarmSession, torrentMeta, clientSession ) 39 , SwarmSession( SwarmSession, torrentMeta
40 , clientSession, storage
41 )
39 42
40 , SessionCount 43 , SessionCount
41 , getSessionCount 44 , getSessionCount
42 , getClientBitfield 45 , getClientBitfield
46 , getActivePeers
43 47
44 , discover 48 , discover
49
50 , PeerSession ( connectedPeerAddr, enabledExtensions )
51 , getSessionState
52
53 , SessionState (..)
45 ) where 54 ) where
46 55
47import Prelude hiding (mapM_, elem) 56import Prelude hiding (mapM_, elem)
@@ -163,6 +172,9 @@ getPeerCount ClientSession {..} = liftIO $ do
163 unused <- peekAvail activeThreads 172 unused <- peekAvail activeThreads
164 return (maxActive - unused) 173 return (maxActive - unused)
165 174
175getActiveSwarms :: ClientSession -> IO [SwarmSession]
176getActiveSwarms ClientSession {..} = M.elems <$> readTVarIO swarmSessions
177
166getListenerPort :: ClientSession -> IO PortNumber 178getListenerPort :: ClientSession -> IO PortNumber
167getListenerPort ClientSession {..} = servPort <$> readMVar peerListener 179getListenerPort ClientSession {..} = servPort <$> readMVar peerListener
168 180
@@ -249,6 +261,10 @@ getSwarm cs @ ClientSession {..} ih = do
249getStorage :: ClientSession -> InfoHash -> IO Storage 261getStorage :: ClientSession -> InfoHash -> IO Storage
250getStorage cs ih = storage <$> getSwarm cs ih 262getStorage cs ih = storage <$> getSwarm cs ih
251 263
264-- TODO keep sorted?
265getActivePeers :: SwarmSession -> IO [PeerSession]
266getActivePeers SwarmSession {..} = S.toList <$> readTVarIO connectedPeers
267
252getTorrentInfo :: ClientSession -> InfoHash -> IO (Maybe Torrent) 268getTorrentInfo :: ClientSession -> InfoHash -> IO (Maybe Torrent)
253getTorrentInfo cs ih = do 269getTorrentInfo cs ih = do
254 tstatus <- torrentPresence cs ih 270 tstatus <- torrentPresence cs ih