summaryrefslogtreecommitdiff
path: root/tests/client.hs
blob: bab11b1173e0c40a332dc0fa242f5cab102ea2bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Main (main) where

import System.Environment
import Data.ByteString as B
import Data.ByteString.Lazy as L
import Data.BEncode

import Data.Torrent
import Network.Torrent.THP
import Network.Torrent.PeerID

showWarn :: TResponse -> IO ()
showWarn resp
  | Just msg <- respWarning resp = print msg
  | otherwise = return ()

main :: IO ()
main = do
  [path] <- getArgs
  contents <- B.readFile path

  let Right contents' = decode contents >>= return . L.toStrict . encode
  print (contents' == contents)

--  let (a, b) = showInfos contents
--  print b
--  print a
--  print (encode b == encoded a)

  let Right b = decode contents
  let Right t = fromBEncode b

  peerID <- newPeerID

  let req = defaultRequest (tAnnounce t) (tInfoHash t) (peerID)
  Right resp <- sendRequest req

  print resp
  showWarn resp