From bf2e6269470162da408555e05edef7655f7023b0 Mon Sep 17 00:00:00 2001 From: Jaseem Abid Date: Thu, 19 Feb 2015 01:58:51 +0530 Subject: [PATCH] A few lint fixes to get started - Making `GHC -Wall` and hlint happy. - Renaming length to len, to not shadow prelude function - Remove unused import --- src/Main.hs | 24 ++++++++++++------------ src/Tracker.hs | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 482b433..015c323 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -8,7 +8,6 @@ import qualified Metainfo as MInfo import qualified Tracker as T import qualified Text.ParserCombinators.Parsec as Parsec import qualified Peer as P -import qualified Data.Map as M import Data.Functor printError :: Parsec.ParseError -> IO () @@ -30,14 +29,15 @@ parse _ = exit main :: IO () main = do - args <- getArgs - torrentStr <- parse args - case Benc.decode torrentStr of - Right d -> case MInfo.mkMetaInfo d of - Nothing -> putStrLn "parse error" - Just m -> do - let length = MInfo.lengthInBytes (MInfo.info m) - body <- BC.pack <$> T.connect (MInfo.announce m) (T.prepareRequest d genPeerId length) - print (P.getPeers (P.getPeerResponse body)) - Left e -> printError e - putStrLn "done" + args <- getArgs + torrentStr <- parse args + case Benc.decode torrentStr of + Right d -> + case MInfo.mkMetaInfo d of + Nothing -> putStrLn "parse error" + Just m -> do + let len = MInfo.lengthInBytes (MInfo.info m) + body <- BC.pack <$> T.connect (MInfo.announce m) (T.prepareRequest d genPeerId len) + print (P.getPeers (P.getPeerResponse body)) + Left e -> printError e + putStrLn "done" diff --git a/src/Tracker.hs b/src/Tracker.hs index 68cf28c..c523683 100644 --- a/src/Tracker.hs +++ b/src/Tracker.hs @@ -20,7 +20,7 @@ type Url = String -- "%124Vx%9a%bc%de%f1%23Eg%89%ab%cd%ef%124Vx%9a" urlEncode :: BC.ByteString -> String urlEncode bs = concatMap (encode . BC.unpack) (U.splitN 2 bs) - where encode b@(c1 : c2 : []) = let c = chr (read ("0x" ++ b)) + where encode b@[c1, c2] = let c = chr (read ("0x" ++ b)) in escape c c1 c2 encode _ = "" @@ -39,13 +39,13 @@ peerHash :: String -> BC.ByteString peerHash = B16.encode . SHA1.hash . BC.pack prepareRequest :: Benc.BVal -> String -> Integer -> String -prepareRequest (Benc.Bdict d) peer_id length = +prepareRequest (Benc.Bdict d) peer_id len = let p = [("info_hash", urlEncode (infoHash d)), ("peer_id", urlEncode (peerHash peer_id)), ("port", "6881"), ("uploaded", "0"), ("downloaded", "0"), - ("left", show length), + ("left", show len), ("compact", "1"), ("event", "started")] in -- 2.45.2