]> git.rkrishnan.org Git - functorrent.git/blob - src/FuncTorrent/Tracker.hs
Tracker: refactor into http, udp and types modules
[functorrent.git] / src / FuncTorrent / Tracker.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module FuncTorrent.Tracker
3     (TState(..),
4      initialTrackerState,
5      trackerLoop
6     ) where
7
8 import Control.Concurrent.MVar (newEmptyMVar, newMVar)
9 import Data.List (isPrefixOf)
10
11 import FuncTorrent.Tracker.Http(trackerLoop)
12 import FuncTorrent.Tracker.Types(TState(..), TrackerEventState(..), TrackerProtocol(..))
13
14 initialTrackerState :: Integer -> IO TState
15 initialTrackerState sz = do
16   ps <- newEmptyMVar
17   up <- newMVar 0
18   down <- newMVar 0
19   return $ TState { currentState = None
20                   , connectedPeers = ps
21                   , uploaded = up
22                   , downloaded = down
23                   , left = sz }
24
25 getTrackerType :: String -> TrackerProtocol
26 getTrackerType url | isPrefixOf "http://" url = Http
27                    | isPrefixOf "udp://" url  = Udp
28                    | otherwise                = UnknownProtocol
29