X-Git-Url: https://git.rkrishnan.org/?p=functorrent.git;a=blobdiff_plain;f=src%2FFuncTorrent%2FTracker%2FHttp.hs;h=9edf3fca6691149ed218f012df2a5784b826ef02;hp=f911b2f7ad1a3c4e67682b4ba6a24cd9b076544a;hb=9beb0fb9814b33725f6adfa5adabb3225a54277b;hpb=2ddd7237e3615d4a55460ca86de22a669c90232c diff --git a/src/FuncTorrent/Tracker/Http.hs b/src/FuncTorrent/Tracker/Http.hs index f911b2f..9edf3fc 100644 --- a/src/FuncTorrent/Tracker/Http.hs +++ b/src/FuncTorrent/Tracker/Http.hs @@ -23,16 +23,15 @@ module FuncTorrent.Tracker.Http (trackerLoop ) where -import Prelude hiding (lookup, splitAt) +import Prelude hiding (lookup) import Control.Concurrent (threadDelay) import Control.Concurrent.MVar (readMVar, putMVar, isEmptyMVar, swapMVar) import Control.Monad (forever, void) import qualified Data.ByteString.Base16 as B16 (encode) import Data.ByteString (ByteString) -import Data.ByteString.Char8 as BC (pack, unpack, splitAt) +import Data.ByteString.Char8 as BC (pack, unpack) import Data.Char (chr) -import Data.List (intercalate) import Data.Map as M (lookup) import Network (PortNumber) import Network.HTTP.Base (urlEncode) @@ -41,7 +40,7 @@ import qualified FuncTorrent.Bencode as Benc import FuncTorrent.Bencode (BVal(..)) import qualified FuncTorrent.FileSystem as FS (MsgChannel, Stats(..), getStats) import FuncTorrent.Network (sendGetRequest) -import FuncTorrent.PeerMsgs (Peer(..), makePeer) +import FuncTorrent.PeerMsgs (makePeer) import FuncTorrent.Utils (splitN, IP, Port) import FuncTorrent.Tracker.Types(TState(..), TrackerResponse(..)) @@ -75,10 +74,9 @@ mkArgs port peer_id up down left' infoHash = trackerLoop :: String -> PortNumber -> String -> ByteString -> FS.MsgChannel -> TState -> IO () trackerLoop url sport peerId infohash fschan tstate = forever $ do - st' <- FS.getStats fschan - st <- readMVar st' - let up = FS.bytesRead st - down = FS.bytesWritten st + st <- readMVar <$> FS.getStats fschan + up <- fmap FS.bytesRead st + down <- fmap FS.bytesWritten st resp <- sendGetRequest url $ mkArgs sport peerId up down (left tstate) infohash case Benc.decode resp of Left e ->