diff options
Diffstat (limited to 'src/Network/BitTorrent/Internal.lhs')
-rw-r--r-- | src/Network/BitTorrent/Internal.lhs | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/Network/BitTorrent/Internal.lhs b/src/Network/BitTorrent/Internal.lhs index f46ca244..e3fe3dac 100644 --- a/src/Network/BitTorrent/Internal.lhs +++ b/src/Network/BitTorrent/Internal.lhs | |||
@@ -231,7 +231,7 @@ To avoid this we keep just *metainfo* about *metainfo*: | |||
231 | > metafilePath :: FilePath | 231 | > metafilePath :: FilePath |
232 | > -- | Full path to directory contating content files associated | 232 | > -- | Full path to directory contating content files associated |
233 | > -- with the metafile. | 233 | > -- with the metafile. |
234 | > , dataPath :: FilePath | 234 | > , dataDirPath :: FilePath |
235 | > } | 235 | > } |
236 | 236 | ||
237 | TorrentMap is used to keep track all known torrents for the | 237 | TorrentMap is used to keep track all known torrents for the |
@@ -258,8 +258,24 @@ validate corresponding piece and only after read and send the block | |||
258 | back. | 258 | back. |
259 | 259 | ||
260 | > -- | Used to check torrent location before register torrent. | 260 | > -- | Used to check torrent location before register torrent. |
261 | > validateTorrent :: TorrentLoc -> IO () | 261 | > validateTorrent :: TorrentLoc -> IO Torrent |
262 | > validateTorrent = error "validateTorrent: not implemented" | 262 | > validateTorrent TorrentLoc {..} = do |
263 | > t <- fromFile metafilePath | ||
264 | > exists <- doesDirectoryExist dataDirPath | ||
265 | > unless exists $ do | ||
266 | > throw undefined | ||
267 | > return t | ||
268 | |||
269 | > registerTorrent :: TVar TorrentMap -> TorrentLoc -> IO (Maybe Torrent) | ||
270 | > registerTorrent ClientSession {..} tl = do | ||
271 | > Torrent {..} <- validateTorrent tl | ||
272 | > atomically $ modifyTVar' torrentMap $ HM.insert tInfoHash tl | ||
273 | > return (Just t) | ||
274 | > | ||
275 | |||
276 | > unregisterTorrent :: TVar TorrentMap -> InfoHash -> IO () | ||
277 | > unregisterTorrent ClientSession {..} ih = do | ||
278 | > modifyTVar' torrentMap $ HM.delete ih | ||
263 | 279 | ||
264 | Client session | 280 | Client session |
265 | ------------------------------------------------------------------------ | 281 | ------------------------------------------------------------------------ |
@@ -366,14 +382,6 @@ and different enabled extensions at the same time. | |||
366 | > <*> newTVarIO (startProgress 0) | 382 | > <*> newTVarIO (startProgress 0) |
367 | > <*> newTVarIO HM.empty | 383 | > <*> newTVarIO HM.empty |
368 | 384 | ||
369 | > registerTorrent :: ClientSession -> InfoHash -> TorrentLoc -> STM () | ||
370 | > registerTorrent ClientSession {..} ih tl = do | ||
371 | > modifyTVar' torrentMap $ HM.insert ih tl | ||
372 | |||
373 | > unregisterTorrent :: ClientSession -> InfoHash -> STM () | ||
374 | > unregisterTorrent ClientSession {..} ih = do | ||
375 | > modifyTVar' torrentMap $ HM.delete ih | ||
376 | |||
377 | Swarm session | 385 | Swarm session |
378 | ------------------------------------------------------------------------ | 386 | ------------------------------------------------------------------------ |
379 | 387 | ||