X-Git-Url: https://git.rkrishnan.org/?p=functorrent.git;a=blobdiff_plain;f=src%2FFuncTorrent%2FTracker.hs;h=b9e977acff1bea112cfc1090ac5f93c85b0cc6a9;hp=ac99ce288d23b208319abf0972a8c78255b1c0f9;hb=aa5477676dd98fb07a2afa118c29f98a4885fdc9;hpb=2b7c4456d2a16f9392108b617c4147c429f1ce59 diff --git a/src/FuncTorrent/Tracker.hs b/src/FuncTorrent/Tracker.hs index ac99ce2..b9e977a 100644 --- a/src/FuncTorrent/Tracker.hs +++ b/src/FuncTorrent/Tracker.hs @@ -29,14 +29,13 @@ import Control.Concurrent.Chan (Chan, newChan, readChan, writeChan) import Control.Concurrent.MVar (newEmptyMVar, putMVar, readMVar) import Control.Monad.State (StateT, liftIO, get, runStateT) import Control.Monad (forever) -import Data.ByteString.Char8 (ByteString, pack, unpack) +import Data.ByteString.Char8 (ByteString) import Data.List (isPrefixOf) 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 FuncTorrent.Utils (Port, toPort, getHostname) import qualified FuncTorrent.FileSystem as FS (MsgChannel) import FuncTorrent.PeerMsgs (Peer) @@ -48,12 +47,13 @@ newTracker = newChan runTracker :: MsgChannel -> FS.MsgChannel -> ByteString -> PortNumber -> String -> [String] -> Integer -> IO () runTracker msgChannel fsChan infohash port peerId announceList sz = do + let fn = getTrackerLoopFn turl ps <- newEmptyMVar - forkIO $ (getTrackerLoopFn turl) turl port peerId infohash fsChan (initialTState ps) - runStateT (msgHandler msgChannel) (initialTState ps) + _ <- forkIO $ fn turl port peerId infohash fsChan (initialTState ps) + _ <- runStateT (msgHandler msgChannel) (initialTState ps) return () - where getTrackerLoopFn turl = - case getTrackerType turl of + where getTrackerLoopFn turl' = + case getTrackerType turl' of Http -> HT.trackerLoop Udp -> UT.trackerLoop _ -> error "Tracker Protocol unimplemented"