From: Divam Date: Sun, 1 Mar 2015 15:10:13 +0000 (+0530) Subject: Feedback from @jaseemabid, Fixes #6 X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/bcase/?a=commitdiff_plain;h=6d5f62f23f09eb8f94b824261c8d13cf797b315c;p=functorrent.git Feedback from @jaseemabid, Fixes #6 --- diff --git a/src/Logger.hs b/src/Logger.hs index 5863cce..c1a5894 100644 --- a/src/Logger.hs +++ b/src/Logger.hs @@ -1,6 +1,5 @@ module Logger ( - Logger - , initLogger + initLogger , logMessage , logStop ) where diff --git a/src/Main.hs b/src/Main.hs index 2213ac9..b8afb0e 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -13,8 +13,8 @@ import Tracker (connect, prepareRequest) import Text.ParserCombinators.Parsec (ParseError) import Logger -printError :: ParseError -> Logger -> IO () -printError e l = logMessage l $ "parse error: \n" ++ show e +logError :: ParseError -> (String -> IO ()) -> IO () +logError e logMsg = logMsg $ "parse error: \n" ++ show e peerId :: String peerId = "-HS0001-*-*-20150215" @@ -34,22 +34,28 @@ main :: IO () main = do args <- getArgs logR <- initLogger - logMessage logR $ "Starting parsing input file: " ++ (concat args) + let logMsg = logMessage logR + logMsg $ "Parsing input file: " ++ concat args torrentStr <- parse args case decode torrentStr of Right d -> case mkMetaInfo d of - Nothing -> logMessage logR "parse error" + Nothing -> logMsg "parse error" Just m -> do + logMsg "Input File OK" + let len = lengthInBytes $ info m (Bdict d') = d + + logMsg "Trying to fetch peers: " + body <- pack <$> connect (announce m) (prepareRequest d' peerId len) let peerResponse = show $ getPeers $ getPeerResponse body - logMessage logR $ "Peers List : " ++ peerResponse + logMsg $ "Peers List : " ++ peerResponse let hsMsgLen = show $ length $ handShakeMsg d' peerId - logMessage logR $ "Hand-shake message length : " ++ hsMsgLen + logMsg $ "Hand-shake message length : " ++ hsMsgLen - Left e -> printError e logR + Left e -> logError e logMsg logStop logR