diff options
Diffstat (limited to 'src/Network/BitTorrent/Sessions.hs')
-rw-r--r-- | src/Network/BitTorrent/Sessions.hs | 18 |
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 | ||
47 | import Prelude hiding (mapM_, elem) | 56 | import 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 | ||
175 | getActiveSwarms :: ClientSession -> IO [SwarmSession] | ||
176 | getActiveSwarms ClientSession {..} = M.elems <$> readTVarIO swarmSessions | ||
177 | |||
166 | getListenerPort :: ClientSession -> IO PortNumber | 178 | getListenerPort :: ClientSession -> IO PortNumber |
167 | getListenerPort ClientSession {..} = servPort <$> readMVar peerListener | 179 | getListenerPort ClientSession {..} = servPort <$> readMVar peerListener |
168 | 180 | ||
@@ -249,6 +261,10 @@ getSwarm cs @ ClientSession {..} ih = do | |||
249 | getStorage :: ClientSession -> InfoHash -> IO Storage | 261 | getStorage :: ClientSession -> InfoHash -> IO Storage |
250 | getStorage cs ih = storage <$> getSwarm cs ih | 262 | getStorage cs ih = storage <$> getSwarm cs ih |
251 | 263 | ||
264 | -- TODO keep sorted? | ||
265 | getActivePeers :: SwarmSession -> IO [PeerSession] | ||
266 | getActivePeers SwarmSession {..} = S.toList <$> readTVarIO connectedPeers | ||
267 | |||
252 | getTorrentInfo :: ClientSession -> InfoHash -> IO (Maybe Torrent) | 268 | getTorrentInfo :: ClientSession -> InfoHash -> IO (Maybe Torrent) |
253 | getTorrentInfo cs ih = do | 269 | getTorrentInfo cs ih = do |
254 | tstatus <- torrentPresence cs ih | 270 | tstatus <- torrentPresence cs ih |