From 5b55381a4b1d7715df0cfdfcde45d04d0ad42bcd Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Tue, 18 Mar 2014 17:36:34 +0400 Subject: Implement openMagnet function --- src/Network/BitTorrent/Client/Handle.hs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/Network/BitTorrent/Client') diff --git a/src/Network/BitTorrent/Client/Handle.hs b/src/Network/BitTorrent/Client/Handle.hs index d68c57cc..a1fe7b9e 100644 --- a/src/Network/BitTorrent/Client/Handle.hs +++ b/src/Network/BitTorrent/Client/Handle.hs @@ -22,6 +22,7 @@ import Control.Applicative import Control.Concurrent import Control.Monad import Control.Monad.Trans +import Data.Default import Data.List as L import Data.HashMap.Strict as HM @@ -89,7 +90,18 @@ openTorrent rootPath t @ Torrent {..} = do -- | Use 'nullMagnet' to open handle from 'InfoHash'. openMagnet :: FilePath -> Magnet -> BitTorrent Handle -openMagnet rootPath uri @ Magnet {..} = error "openMagnet: not implemnted" +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) + return $ Handle + { topic = exactTopic + , private = False + , trackers = tses + , exchange = eses + } -- | Stop torrent and destroy all sessions. You don't need to close -- handles at application exit, all handles will be automatically -- cgit v1.2.3