From: Ramakrishnan Muthukrishnan Date: Mon, 5 Oct 2015 01:36:00 +0000 (+0530) Subject: Tracker: identify tracker protocol from the tracker server url X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/bcase/frontends/FTP-and-SFTP.txt?a=commitdiff_plain;h=e69d363fa517e8769ef4b43962065c827896ea43;p=functorrent.git Tracker: identify tracker protocol from the tracker server url --- diff --git a/src/FuncTorrent/Tracker.hs b/src/FuncTorrent/Tracker.hs index 6ae0281..e0752e9 100644 --- a/src/FuncTorrent/Tracker.hs +++ b/src/FuncTorrent/Tracker.hs @@ -18,7 +18,7 @@ import Data.ByteString (ByteString, hGet, hPut) 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) @@ -31,6 +31,12 @@ import FuncTorrent.Network (sendGetRequest) import FuncTorrent.Peer (Peer(..)) import FuncTorrent.Utils (splitN) + +data TrackerProtocol = Http + | Udp + | UnknownProtocol + deriving (Show) + -- | Tracker response data TrackerResponse = TrackerResponse { interval :: Integer @@ -243,3 +249,8 @@ getResponse h = do 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