From: Ramakrishnan Muthukrishnan Date: Sun, 13 Sep 2015 14:47:48 +0000 (+0530) Subject: remove the use of ReaderT X-Git-Url: https://git.rkrishnan.org/(%5B%5E?a=commitdiff_plain;h=721aeee745cc308014b80594b4c6b7b403d4ef1f;p=functorrent.git remove the use of ReaderT --- diff --git a/src/FuncTorrent/Tracker.hs b/src/FuncTorrent/Tracker.hs index 5cd6aea..a2dc48b 100644 --- a/src/FuncTorrent/Tracker.hs +++ b/src/FuncTorrent/Tracker.hs @@ -1,15 +1,11 @@ {-# LANGUAGE OverloadedStrings #-} module FuncTorrent.Tracker (TrackerResponse(..), - mkArgs, - getTrackerResponse, - urlEncodeHash + getTrackerResponse ) where import Prelude hiding (lookup, splitAt) -import Control.Monad.IO.Class (liftIO) -import Control.Monad.Reader (ReaderT, ask, runReaderT) import Data.ByteString (ByteString) import Data.ByteString.Char8 as BC (pack, unpack, splitAt) import Data.Char (chr) @@ -67,18 +63,15 @@ mkTrackerResponse resp = where (ip', port') = splitAt 4 peer -- | Connect to a tracker and get peer info -tracker :: String -> ReaderT Metainfo IO ByteString -tracker peer_id = do - m <- ask - let args = mkArgs peer_id m - liftIO $ get (head . announceList $ m) args - -getTrackerResponse :: String -> ReaderT Metainfo IO (Either ByteString TrackerResponse) -getTrackerResponse peerId = do - m <- ask - resp <- liftIO $ runReaderT (tracker peerId) m +tracker :: String -> Metainfo -> IO ByteString +tracker peer_id m = do + get (head . announceList $ m) $ mkArgs peer_id m + +getTrackerResponse :: String -> Metainfo -> IO (Either ByteString TrackerResponse) +getTrackerResponse peerId m = do + resp <- tracker peerId m case decode resp of - Right trackerInfo -> liftIO $ return $ mkTrackerResponse trackerInfo + Right trackerInfo -> return $ mkTrackerResponse trackerInfo Left e -> return $ Left (pack (show e)) --- | URL encode hash as per RFC1738