From b153806a0b9945e9ba3b82296ce0c39b627eb6b9 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 24 Mar 2014 04:20:22 +0400 Subject: Factor exchange session construction to newExchangeSession --- src/Network/BitTorrent/Client/Handle.hs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs index 97ffc637..9601e691 100644 --- a/src/Network/BitTorrent/Client/Handle.hs +++ b/src/Network/BitTorrent/Client/Handle.hs @@ -71,16 +71,19 @@ lookupHandle ih = do -- Initialization -----------------------------------------------------------------------} +newExchangeSession :: FilePath -> InfoDict -> BitTorrent Exchange.Session +newExchangeSession rootPath dict = do + c @ Client {..} <- getClient + liftIO $ Exchange.newSession clientLogger (externalAddr c) rootPath dict + -- | Open a torrent in 'stop'ed state. Use 'nullTorrent' to open -- handle from 'InfoDict'. This operation do not block. openTorrent :: FilePath -> Torrent -> BitTorrent Handle openTorrent rootPath t @ Torrent {..} = do let ih = idInfoHash tInfoDict allocHandle ih $ do - c @ Client {..} <- getClient tses <- liftIO $ Tracker.newSession ih (trackerList t) - eses <- liftIO $ Exchange.newSession clientLogger (externalAddr c) - rootPath tInfoDict + eses <- newExchangeSession rootPath tInfoDict return $ Handle { handleTopic = ih , handlePrivate = idPrivate tInfoDict @@ -92,10 +95,8 @@ openTorrent rootPath t @ Torrent {..} = do openMagnet :: FilePath -> Magnet -> BitTorrent Handle openMagnet rootPath uri @ Magnet {..} = do allocHandle exactTopic $ do - c @ Client {..} <- getClient tses <- liftIO $ Tracker.newSession exactTopic def - eses <- liftIO $ Exchange.newSession clientLogger (externalAddr c) - rootPath (error "openMagnet" exactTopic) + eses <- newExchangeSession rootPath (error "openMagnet" exactTopic) return $ Handle { handleTopic = exactTopic , handlePrivate = False -- cgit v1.2.3