printError :: Parsec.ParseError -> IO ()
printError e = putStrLn $ "parse error: " ++ show e
-genPeerId :: String
-genPeerId = "-HS0001-20150215"
+peerId :: String
+peerId = "-HS0001-*-*-20150215"
exit :: IO BC.ByteString
exit = exitSuccess
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
- body <- BC.pack <$> T.connect (MInfo.announce m) (T.prepareRequest d genPeerId)
- 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 peerId len)
+ print (P.getPeers (P.getPeerResponse body))
+ Left e -> printError e
+ putStrLn "done"