]> git.rkrishnan.org Git - functorrent.git/blob - src/Main.hs
talk to tracker and get the peer dict
[functorrent.git] / src / Main.hs
1 module Main where
2
3 import System.Environment (getArgs)
4 import qualified Data.ByteString.Char8 as BC
5 import qualified Bencode as Benc
6 import qualified Metainfo as MInfo
7 import qualified Tracker as T
8
9 import Text.ParserCombinators.Parsec
10
11 printError :: ParseError -> IO ()
12 printError e = putStrLn "parse error"
13
14 genPeerId :: String
15 genPeerId = "-HS0001-20150215"
16
17 main :: IO ()
18 main = do
19   args <- getArgs
20   torrentStr <- BC.readFile (head args)
21   case (Benc.decode torrentStr) of
22    Right d -> case (MInfo.mkMetaInfo d) of
23                Nothing -> putStrLn "parse error"
24                Just m -> do
25                  let (Benc.Bdict d') = d
26 --                 putStrLn (show m)
27 --                 putStrLn (T.urlEncode (T.infoHash d'))
28                  do body <- T.connect (MInfo.announce m) (T.prepareRequest d genPeerId)
29                     putStrLn body
30    Left e -> printError e
31   putStrLn "done"