port = getPort url
path = getPath url
-getTrackerType :: String -> TrackerProtocol
-getTrackerType url | isPrefixOf "http://" url = Http
- | isPrefixOf "udp://" url = Udp
- | otherwise = UnknownProtocol
-
getHostname :: String -> String
getHostname url = takeWhile (/= ':') $ drop 2 $ dropWhile (/= '/') url
_ ->
error "Tracker Protocol unimplemented"
+getTrackerType :: String -> TrackerProtocol
+getTrackerType url | "http://" `isPrefixOf` url = Http
+ | "udp://" `isPrefixOf` url = Udp
+ | otherwise = UnknownProtocol
+
+
msgHandler :: MsgChannel -> StateT TState IO ()
msgHandler c = forever $ do
st <- get
recvMsg = readChan c
sendResponse msg peers =
case msg of
- GetConnectedPeersMsg var -> do
+ GetConnectedPeersMsg var ->
putMVar var peers
- _ -> do
+ _ ->
putStrLn "Unhandled Tracker Msg"
getConnectedPeers :: MsgChannel -> IO [Peer]
getConnectedPeers c = do
v <- newEmptyMVar
writeChan c (GetConnectedPeersMsg v)
- ps <- readMVar v
- return ps
+ readMVar v
down = FS.bytesWritten st
resp <- sendGetRequest url $ mkArgs port peerId up down (left tstate) infohash
case Benc.decode resp of
- Left e -> do
+ Left e ->
return () -- $ pack (show e)
Right trackerInfo ->
case parseTrackerResponse trackerInfo of