diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-07-07 22:21:05 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-07-07 22:21:05 +0400 |
commit | 8ea2e1f83ba7c06646f200107a018daf4a434bf9 (patch) | |
tree | 5db0f772718cc3df349e9ecfdd62d1aeed376aa0 /src/Network/BitTorrent.hs | |
parent | 9fb9ea59f7f9ee2c4be64a85b424dd632602e781 (diff) |
~ Refactor torrent registration a bit.
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r-- | src/Network/BitTorrent.hs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs index 5521a825..a9d06ab4 100644 --- a/src/Network/BitTorrent.hs +++ b/src/Network/BitTorrent.hs | |||
@@ -125,10 +125,23 @@ discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do | |||
125 | Torrent management | 125 | Torrent management |
126 | -----------------------------------------------------------------------} | 126 | -----------------------------------------------------------------------} |
127 | 127 | ||
128 | -- | Used to check torrent location before register torrent. | ||
129 | validateLocation :: TorrentLoc -> IO Torrent | ||
130 | validateLocation TorrentLoc {..} = do | ||
131 | t <- fromFile metafilePath | ||
132 | -- exists <- doesDirectoryExist dataDirPath | ||
133 | -- unless exists $ do | ||
134 | -- throw undefined | ||
135 | return t | ||
136 | |||
137 | |||
128 | -- | Register torrent and start downloading. | 138 | -- | Register torrent and start downloading. |
129 | addTorrent :: ClientSession -> TorrentLoc -> IO () | 139 | addTorrent :: ClientSession -> TorrentLoc -> IO () |
130 | addTorrent clientSession loc @ TorrentLoc {..} = do | 140 | addTorrent clientSession loc @ TorrentLoc {..} = do |
131 | torrent <- registerTorrent loc | 141 | torrent <- validateLocation loc |
142 | -- registerTorrent loc tInfoHash | ||
143 | -- when (bf is not full) | ||
144 | |||
132 | swarm <- newLeecher clientSession torrent | 145 | swarm <- newLeecher clientSession torrent |
133 | storage <- swarm `bindTo` dataDirPath | 146 | storage <- swarm `bindTo` dataDirPath |
134 | forkIO $ discover swarm $ do | 147 | forkIO $ discover swarm $ do |
@@ -140,7 +153,7 @@ addTorrent clientSession loc @ TorrentLoc {..} = do | |||
140 | 153 | ||
141 | -- | Unregister torrent and stop all running sessions. | 154 | -- | Unregister torrent and stop all running sessions. |
142 | removeTorrent :: ClientSession -> InfoHash -> IO () | 155 | removeTorrent :: ClientSession -> InfoHash -> IO () |
143 | removeTorrent ses loc = atomically $ unregisterTorrent ses loc | 156 | removeTorrent ses loc = undefined -- atomically $ unregisterTorrent ses loc |
144 | 157 | ||
145 | {- | 158 | {- |
146 | -- | The same as 'removeTorrrent' torrent, but delete all torrent | 159 | -- | The same as 'removeTorrrent' torrent, but delete all torrent |