From: Ramakrishnan Muthukrishnan Date: Sat, 25 Jun 2016 01:51:35 +0000 (+0530) Subject: more hlint cleanups X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/about/module-simplejson.tests.html?a=commitdiff_plain;h=aa5477676dd98fb07a2afa118c29f98a4885fdc9;p=functorrent.git more hlint cleanups --- 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" diff --git a/src/FuncTorrent/Tracker/Udp.hs b/src/FuncTorrent/Tracker/Udp.hs index ae7ad1e..de99ce2 100644 --- a/src/FuncTorrent/Tracker/Udp.hs +++ b/src/FuncTorrent/Tracker/Udp.hs @@ -96,7 +96,7 @@ instance Binary UDPRequest where putWord32be 0 putWord32be 10 putWord16be $ fromIntegral port - put (ScrapeReq _ _ _) = undefined + put ScrapeReq {} = undefined get = undefined instance Binary UDPResponse where @@ -189,7 +189,7 @@ getIPPortPairs = do ip <- toIP <$> getByteString 4 port <- toPort <$> getByteString 2 ipportpairs <- getIPPortPairs - return $ (Peer ip port) : ipportpairs + return $ Peer ip port : ipportpairs startSession :: String -> Port -> IO UDPTrackerHandle startSession host port = do @@ -198,7 +198,7 @@ startSession host port = do let (SockAddrInet p ip) = addrAddress $ head addrinfos putStrLn "connected to tracker" return UDPTrackerHandle { sock = s - , addr = (SockAddrInet (fromIntegral port) ip) } + , addr = SockAddrInet (fromIntegral port) ip } closeSession :: UDPTrackerHandle -> IO () closeSession (UDPTrackerHandle s _) = close s @@ -229,5 +229,4 @@ trackerLoop url sport peerId infohash fschan tstate = forever $ do t1 <- connectRequest cid <- connectResponse t1 t2 <- announceRequest cid infohash peerId (fromIntegral up) (fromIntegral down) (fromIntegral (left tstate)) (fromIntegral sport) - stats <- announceResponse t2 - return stats + announceResponse t2