summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-07-17 03:13:23 +0400
committerSam T <pxqr.sta@gmail.com>2013-07-17 03:13:23 +0400
commit36cac7b4646d64c485320f066e6fb6a2a54427d3 (patch)
tree2c2f825f38ab60770088ff6ee08da40eea41305f /src
parentb2b6e8e2bef7c87f0c8026766eec92aab0ff1e3e (diff)
+ Get torrent info with caching.
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent.hs1
-rw-r--r--src/Network/BitTorrent/Sessions.hs9
-rw-r--r--src/System/Torrent/Storage.hs2
3 files changed, 11 insertions, 1 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index ad96a1b8..8bbd774e 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -23,6 +23,7 @@ module Network.BitTorrent
23 , getSessionCount 23 , getSessionCount
24 , getSwarm 24 , getSwarm
25 , getStorage 25 , getStorage
26 , getTorrentInfo
26 27
27 -- * Extensions 28 -- * Extensions
28 , Extension 29 , Extension
diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs
index 5047f06c..4e58be5c 100644
--- a/src/Network/BitTorrent/Sessions.hs
+++ b/src/Network/BitTorrent/Sessions.hs
@@ -33,6 +33,7 @@ module Network.BitTorrent.Sessions
33 , getPeerCount 33 , getPeerCount
34 , getSwarm 34 , getSwarm
35 , getStorage 35 , getStorage
36 , getTorrentInfo
36 , openSwarmSession 37 , openSwarmSession
37 38
38 -- * Swarm 39 -- * Swarm
@@ -250,6 +251,14 @@ getSwarm cs @ ClientSession {..} ih = do
250getStorage :: ClientSession -> InfoHash -> IO Storage 251getStorage :: ClientSession -> InfoHash -> IO Storage
251getStorage cs ih = storage <$> getSwarm cs ih 252getStorage cs ih = storage <$> getSwarm cs ih
252 253
254getTorrentInfo :: ClientSession -> InfoHash -> IO (Maybe Torrent)
255getTorrentInfo cs ih = do
256 tstatus <- torrentPresence cs ih
257 case tstatus of
258 Unknown -> return Nothing
259 Active (SwarmSession {..}) -> return $ Just torrentMeta
260 Registered (TorrentLoc {..}) -> Just <$> fromFile metafilePath
261
253-- | Get the number of connected peers in the given swarm. 262-- | Get the number of connected peers in the given swarm.
254getSessionCount :: SwarmSession -> IO SessionCount 263getSessionCount :: SwarmSession -> IO SessionCount
255getSessionCount SwarmSession {..} = do 264getSessionCount SwarmSession {..} = do
diff --git a/src/System/Torrent/Storage.hs b/src/System/Torrent/Storage.hs
index c33be89c..99d164f2 100644
--- a/src/System/Torrent/Storage.hs
+++ b/src/System/Torrent/Storage.hs
@@ -299,7 +299,7 @@ readFD fd @ FD {..} offset reqSize =
299 readAhead fd offset expSize 299 readAhead fd offset expSize
300 return $ Right bs 300 return $ Right bs
301 301
302-- TODO 302-- TODO implement COW; needed for applications which want to change files.
303writeFD :: FD -> ByteString -> Offset -> IO () 303writeFD :: FD -> ByteString -> Offset -> IO ()
304writeFD FD {..} bs offset = return () 304writeFD FD {..} bs offset = return ()
305 305