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"
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