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/Internal.lhs | |
parent | 9fb9ea59f7f9ee2c4be64a85b424dd632602e781 (diff) |
~ Refactor torrent registration a bit.
Diffstat (limited to 'src/Network/BitTorrent/Internal.lhs')
-rw-r--r-- | src/Network/BitTorrent/Internal.lhs | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/Network/BitTorrent/Internal.lhs b/src/Network/BitTorrent/Internal.lhs index e3fe3dac..475c5e32 100644 --- a/src/Network/BitTorrent/Internal.lhs +++ b/src/Network/BitTorrent/Internal.lhs | |||
@@ -257,25 +257,17 @@ so we need to do this on demand: if a peer asks for a block, we | |||
257 | validate corresponding piece and only after read and send the block | 257 | 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 | > registerTorrent :: TVar TorrentMap -> InfoHash -> TorrentLoc -> IO () |
261 | > validateTorrent :: TorrentLoc -> IO Torrent | 261 | > registerTorrent = error "registerTorrent" |
262 | > validateTorrent TorrentLoc {..} = do | 262 | > {- |
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 | 263 | > Torrent {..} <- validateTorrent tl |
272 | > atomically $ modifyTVar' torrentMap $ HM.insert tInfoHash tl | 264 | > atomically $ modifyTVar' torrentMap $ HM.insert tInfoHash tl |
273 | > return (Just t) | 265 | > return (Just t) |
274 | > | 266 | > -} |
275 | 267 | ||
276 | > unregisterTorrent :: TVar TorrentMap -> InfoHash -> IO () | 268 | > unregisterTorrent :: TVar TorrentMap -> InfoHash -> IO () |
277 | > unregisterTorrent ClientSession {..} ih = do | 269 | > unregisterTorrent = error "unregisterTorrent" |
278 | > modifyTVar' torrentMap $ HM.delete ih | 270 | > -- modifyTVar' torrentMap $ HM.delete ih |
279 | 271 | ||
280 | Client session | 272 | Client session |
281 | ------------------------------------------------------------------------ | 273 | ------------------------------------------------------------------------ |
@@ -374,7 +366,7 @@ and different enabled extensions at the same time. | |||
374 | > ClientSession | 366 | > ClientSession |
375 | > <$> newPeerId | 367 | > <$> newPeerId |
376 | > <*> pure exts | 368 | > <*> pure exts |
377 | > <*> forkListener (error "listener") | 369 | > <*> pure 10 -- forkListener (error "listener") |
378 | > <*> MSem.new n | 370 | > <*> MSem.new n |
379 | > <*> pure n | 371 | > <*> pure n |
380 | > <*> newTVarIO S.empty | 372 | > <*> newTVarIO S.empty |
@@ -382,6 +374,12 @@ and different enabled extensions at the same time. | |||
382 | > <*> newTVarIO (startProgress 0) | 374 | > <*> newTVarIO (startProgress 0) |
383 | > <*> newTVarIO HM.empty | 375 | > <*> newTVarIO HM.empty |
384 | 376 | ||
377 | data TorrentStatus = Active SwarmSession | ||
378 | | Registered TorrentLoc | ||
379 | | Unknown | ||
380 | lookupTorrent :: ClientSession -> InfoHash -> IO TorrentStatus | ||
381 | lookupTorrent ses ih = | ||
382 | |||
385 | Swarm session | 383 | Swarm session |
386 | ------------------------------------------------------------------------ | 384 | ------------------------------------------------------------------------ |
387 | 385 | ||