summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r--src/Network/BitTorrent.hs25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index ea6b88bd..5521a825 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -24,6 +24,10 @@ module Network.BitTorrent
24 , getPeerCount 24 , getPeerCount
25 , getSwarmCount 25 , getSwarmCount
26 26
27 , TorrentLoc(..)
28 , addTorrent
29 , removeTorrent
30
27 -- ** Swarm 31 -- ** Swarm
28 , SwarmSession(torrentMeta) 32 , SwarmSession(torrentMeta)
29 33
@@ -76,6 +80,7 @@ module Network.BitTorrent
76 ) where 80 ) where
77 81
78import Control.Concurrent 82import Control.Concurrent
83import Control.Concurrent.STM
79import Control.Exception 84import Control.Exception
80import Control.Monad 85import Control.Monad
81import Control.Monad.Reader 86import Control.Monad.Reader
@@ -119,21 +124,27 @@ discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do
119{----------------------------------------------------------------------- 124{-----------------------------------------------------------------------
120 Torrent management 125 Torrent management
121-----------------------------------------------------------------------} 126-----------------------------------------------------------------------}
122{- 127
128-- | Register torrent and start downloading.
123addTorrent :: ClientSession -> TorrentLoc -> IO () 129addTorrent :: ClientSession -> TorrentLoc -> IO ()
124addTorrent ClientSession {..} TorrentLoc {..} = do 130addTorrent clientSession loc @ TorrentLoc {..} = do
125 torrent <- fromFile metafilePath 131 torrent <- registerTorrent loc
126 swarm <- newLeecher clientSession torrent 132 swarm <- newLeecher clientSession torrent
127 storage <- swarm `bindTo` dataDir 133 storage <- swarm `bindTo` dataDirPath
128 discover swarm $ do 134 forkIO $ discover swarm $ do
129 liftIO $ putStrLn "connected to peer" 135 liftIO $ putStrLn "connected to peer"
130 forever $ do 136 forever $ do
131 liftIO $ putStrLn "from mesage loop" 137 liftIO $ putStrLn "from mesage loop"
132 exchange storage 138 exchange storage
139 return ()
133 140
134removeTorrent :: ClientSession -> TorrentLoc -> IO () 141-- | Unregister torrent and stop all running sessions.
135removeTorrent ClientSession {..} TorrentLoc {..} = undefined 142removeTorrent :: ClientSession -> InfoHash -> IO ()
143removeTorrent ses loc = atomically $ unregisterTorrent ses loc
136 144
145{-
146-- | The same as 'removeTorrrent' torrent, but delete all torrent
147-- content files.
137deleteTorrent :: ClientSession -> TorrentLoc -> IO () 148deleteTorrent :: ClientSession -> TorrentLoc -> IO ()
138deleteTorrent ClientSession {..} TorrentLoc {..} = undefined 149deleteTorrent ClientSession {..} TorrentLoc {..} = undefined
139-} \ No newline at end of file 150-} \ No newline at end of file