{-# LANGUAGE OverloadedStrings #-}
module FuncTorrent.Tracker
(TrackerResponse(..),
- connect,
+ tracker,
mkArgs,
mkTrackerResponse,
urlEncodeHash
where (ip', port') = splitAt 4 peer
-- | Connect to a tracker and get peer info
-connect :: Metainfo -> String -> IO ByteString
-connect m peer_id = get (head . announceList $ m) $ mkArgs m peer_id
+tracker :: Metainfo -> String -> IO ByteString
+tracker m peer_id = get (head . announceList $ m) $ mkArgs m peer_id
--- | URL encode hash as per RFC1738
--- TODO: Add tests
import FuncTorrent.Logger (initLogger, logMessage, logStop)
import FuncTorrent.Metainfo (Info(..), Metainfo(..), mkMetaInfo)
import FuncTorrent.Peer (handShakeMsg)
-import FuncTorrent.Tracker (connect, peers, mkTrackerResponse)
+import FuncTorrent.Tracker (tracker, peers, mkTrackerResponse)
logError :: ParseError -> (String -> IO ()) -> IO ()
logError e logMsg = logMsg $ "parse error: \n" ++ show e
log "Trying to fetch peers"
log $ "Trackers: " ++ head (announceList m)
- response <- connect m peerId
+ response <- tracker m peerId
let hsMsgLen = show $ length $ handShakeMsg m peerId
log $ "Hand-shake message length : " ++ hsMsgLen