import FuncTorrent.Network (sendGetRequest)
import FuncTorrent.PeerMsgs (makePeer)
import FuncTorrent.Utils (splitN, IP, Port)
-import FuncTorrent.Tracker.Types(TState(..), TrackerResponse(..))
+import FuncTorrent.Tracker.Types(TState(..), HttpTrackerResponse(..))
--- | URL encode hash as per RFC1738
void $ swapMVar (connectedPeers tstate) (peers tresp)
threadDelay $ fromIntegral (interval tresp)
-parseTrackerResponse :: BVal -> Either ByteString TrackerResponse
+parseTrackerResponse :: BVal -> Either ByteString HttpTrackerResponse
parseTrackerResponse resp =
case lookup "failure reason" body of
Just (Bstr err) -> Left err
let (Just (Bint i)) = lookup "interval" body
(Just (Bstr peersBS)) = lookup "peers" body
pl = map makePeer (splitN 6 peersBS)
- in Right TrackerResponse {
+ in Right HttpTrackerResponse {
interval = i
, peers = pl
, complete = Nothing
-}
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE DuplicateRecordFields #-}
module FuncTorrent.Tracker.Types
( TrackerProtocol(..)
- , TrackerResponse(..)
+ , HttpTrackerResponse(..)
+ , UdpTrackerResponse(..)
, TrackerEventState(..)
, TState(..)
, TrackerMsg(..)
) where
import Data.ByteString (ByteString)
+import Data.Word (Word32)
import Control.Concurrent.MVar (MVar)
import FuncTorrent.PeerMsgs (Peer)
}
-- | Tracker response
-data TrackerResponse = TrackerResponse {
+data HttpTrackerResponse = HttpTrackerResponse {
interval :: Integer
, peers :: [Peer]
, complete :: Maybe Integer
, incomplete :: Maybe Integer
} deriving (Show, Eq)
+
+data UdpTrackerResponse = UdpTrackerResponse {
+ leechers :: Word32
+ , seeders :: Word32
+ , interval :: Word32
+ , peers :: [Peer]
+ } deriving (Show)
import System.Timeout (timeout)
import FuncTorrent.PeerMsgs (Peer(..))
-import FuncTorrent.Tracker.Types (TrackerEventState(..), TState(..))
+import FuncTorrent.Tracker.Types (TrackerEventState(..), TState(..), UdpTrackerResponse(..))
import FuncTorrent.Utils (IP, Port, toIP, toPort, getHostname, getPort)
import qualified FuncTorrent.FileSystem as FS (MsgChannel, Stats(..), getStats)
liftIO $ sendRequest h (toStrict pkt)
return tidi
-data PeerStats = PeerStats { leechers :: Word32
- , seeders :: Word32
- , interval :: Word32
- , peers :: [Peer]
- } deriving (Show)
-
-announceResponse :: Word32 -> ReaderT UDPTrackerHandle IO PeerStats
+announceResponse :: Word32 -> ReaderT UDPTrackerHandle IO UdpTrackerResponse
announceResponse tid = do
h <- ask
resp <- liftIO $ recvResponse h
if tidr == tid
then do
liftIO $ putStrLn "announce succeeded"
- return $ PeerStats ls ss interval xs
+ return $ UdpTrackerResponse ls ss interval xs
else
- return $ PeerStats 0 0 0 []
- _ -> return $ PeerStats 0 0 0 []
+ return $ UdpTrackerResponse 0 0 0 []
+ _ -> return $ UdpTrackerResponse 0 0 0 []
getIPPortPairs :: Get [Peer]
getIPPortPairs = do
extra-deps: []
# Specifies the GHC version and set of packages available (e.g., lts-3.5, nightly-2015-09-21, ghc-7.10.2)
-resolver: lts-5.2
+resolver: nightly-2016-06-19
rebuild-ghc-options: true
ghc-options: