import Data.ByteString.Char8 as BC (pack, unpack, splitAt)
import Data.ByteString.Lazy (fromStrict, toStrict)
import Data.Char (chr)
-import Data.List (intercalate)
+import Data.List (intercalate, isPrefixOf)
import Data.Map as M (lookup)
import Network (PortNumber)
import Network.HTTP.Base (urlEncode)
import FuncTorrent.Peer (Peer(..))
import FuncTorrent.Utils (splitN)
+
+data TrackerProtocol = Http
+ | Udp
+ | UnknownProtocol
+ deriving (Show)
+
-- | Tracker response
data TrackerResponse = TrackerResponse {
interval :: Integer
sendRequest :: Handle -> UDPRequest -> IO ()
sendRequest h req = hPut h bsReq
where bsReq = toStrict $ encode req
+
+getTrackerType :: String -> TrackerProtocol
+getTrackerType url | isPrefixOf "http://" url = Http
+ | isPrefixOf "udp://" url = Udp
+ | otherwise = UnknownProtocol