{-# LANGUAGE OverloadedStrings #-}
module FuncTorrent.Network
(
- httpget,
+ sendGetRequest,
mkParams
) where
mkParams :: [(String, ByteString)] -> ByteString
mkParams params = BC.intercalate "&" [concat [pack f, "=", s] | (f,s) <- params]
-httpget :: String -> [(String, ByteString)] -> IO ByteString
-httpget url args = simpleHTTP (defaultGETRequest_ url') >>= getResponseBody
+sendGetRequest :: String -> [(String, ByteString)] -> IO ByteString
+sendGetRequest url args = simpleHTTP (defaultGETRequest_ url') >>= getResponseBody
where url' = case parseURI $ unpack $ concat [pack url, "?", qstr] of
Just x -> x
_ -> error "Bad tracker URL"
import FuncTorrent.Bencode (BVal(..), decode)
import FuncTorrent.Metainfo (Info(..), Metainfo(..))
-import FuncTorrent.Network (httpget)
+import FuncTorrent.Network (sendGetRequest)
import FuncTorrent.Peer (Peer(..))
import FuncTorrent.Utils (splitN)
trackerLoop port peerId m st = do
up <- liftIO $ readMVar $ uploaded st
down <- liftIO $ readMVar $ downloaded st
- resp <- liftIO $ httpget (head . announceList $ m) $ mkArgs port peerId up down m
+ resp <- liftIO $ sendGetRequest (head . announceList $ m) $ mkArgs port peerId up down m
case decode resp of
Left e -> return $ pack (show e)
Right trackerInfo ->