]> git.rkrishnan.org Git - functorrent.git/blobdiff - src/FuncTorrent/Tracker.hs
Misc fixes to http tracker.
[functorrent.git] / src / FuncTorrent / Tracker.hs
index 7ad3997ffe1010ef6c4a7ee4c197119072d2b2ff..9873fe1513f073f05efe79b97b2e9bae1522e75e 100644 (file)
@@ -36,37 +36,15 @@ import Network (PortNumber)
 import qualified FuncTorrent.Tracker.Http as HT (trackerLoop)
 import qualified FuncTorrent.Tracker.Udp as UT (trackerLoop)
 import FuncTorrent.Tracker.Types (TState(..), TrackerEventState(..), TrackerProtocol(..), TrackerMsg(..))
 import qualified FuncTorrent.Tracker.Http as HT (trackerLoop)
 import qualified FuncTorrent.Tracker.Udp as UT (trackerLoop)
 import FuncTorrent.Tracker.Types (TState(..), TrackerEventState(..), TrackerProtocol(..), TrackerMsg(..))
-import FuncTorrent.Utils (Port, toPort)
+import FuncTorrent.Utils (Port, toPort, getHostname)
 import qualified FuncTorrent.FileSystem as FS (MsgChannel)
 import FuncTorrent.Peer (Peer)
 
 type MsgChannel = Chan TrackerMsg
 
 import qualified FuncTorrent.FileSystem as FS (MsgChannel)
 import FuncTorrent.Peer (Peer)
 
 type MsgChannel = Chan TrackerMsg
 
-data TrackerUrl = TrackerUrl { protocol :: TrackerProtocol
-                             , host :: String
-                             , port :: Port
-                             , path :: String
-                             }
-
 newTracker :: IO MsgChannel
 newTracker = newChan
 
 newTracker :: IO MsgChannel
 newTracker = newChan
 
-parseUrl :: String -> TrackerUrl
-parseUrl url = TrackerUrl proto host port path
-  where proto = getTrackerType url
-        host = getHostname url
-        port = getPort url
-        path = getPath url
-
-getHostname :: String -> String
-getHostname url = takeWhile (/= ':') $ drop 2 $ dropWhile (/= '/') url
-
-getPort :: String -> Port
-getPort url = toPort . pack $ takeWhile (/= '/') $ drop 1 $ dropWhile (/= ':') $ drop 2 $ dropWhile (/= '/') url
-
-getPath :: String -> String
-getPath url = dropWhile (/= '/') $ dropWhile (/= ':') $ drop 1 $ dropWhile (/= ':') url
-
 runTracker :: MsgChannel -> FS.MsgChannel -> ByteString -> PortNumber
            -> String -> [String] -> Integer -> IO ()
 runTracker msgChannel fsChan infohash port peerId announceList sz = do
 runTracker :: MsgChannel -> FS.MsgChannel -> ByteString -> PortNumber
            -> String -> [String] -> Integer -> IO ()
 runTracker msgChannel fsChan infohash port peerId announceList sz = do
@@ -78,11 +56,11 @@ runTracker msgChannel fsChan infohash port peerId announceList sz = do
       host = getHostname turl
   case getTrackerType turl of
     Http -> do
       host = getHostname turl
   case getTrackerType turl of
     Http -> do
-      _ <- forkIO $ HT.trackerLoop host port peerId infohash fsChan initialTState
+      _ <- forkIO $ HT.trackerLoop turl port peerId infohash fsChan initialTState
       runStateT (msgHandler msgChannel) initialTState
       return ()
     Udp -> do
       runStateT (msgHandler msgChannel) initialTState
       return ()
     Udp -> do
-      _ <- forkIO $ UT.trackerLoop host (fromIntegral port) peerId infohash fsChan initialTState
+      _ <- forkIO $ UT.trackerLoop turl (fromIntegral port) peerId infohash fsChan initialTState
       return ()
     _ ->
       error "Tracker Protocol unimplemented"
       return ()
     _ ->
       error "Tracker Protocol unimplemented"
@@ -90,7 +68,7 @@ runTracker msgChannel fsChan infohash port peerId announceList sz = do
 getTrackerType :: String -> TrackerProtocol
 getTrackerType url | "http://" `isPrefixOf` url = Http
                    | "udp://" `isPrefixOf` url  = Udp
 getTrackerType :: String -> TrackerProtocol
 getTrackerType url | "http://" `isPrefixOf` url = Http
                    | "udp://" `isPrefixOf` url  = Udp
-                   | otherwise                = UnknownProtocol
+                   | otherwise                  = UnknownProtocol
 
 
 msgHandler :: MsgChannel -> StateT TState IO ()
 
 
 msgHandler :: MsgChannel -> StateT TState IO ()