diff options
-rw-r--r-- | src/Network/BitTorrent/Tracker.hs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/Tracker.hs b/src/Network/BitTorrent/Tracker.hs index 0501f428..74b0b593 100644 --- a/src/Network/BitTorrent/Tracker.hs +++ b/src/Network/BitTorrent/Tracker.hs | |||
@@ -43,6 +43,28 @@ import Data.Torrent.Metainfo | |||
43 | import Network.BitTorrent.Peer | 43 | import Network.BitTorrent.Peer |
44 | import Network.BitTorrent.Tracker.Protocol as Tracker | 44 | import Network.BitTorrent.Tracker.Protocol as Tracker |
45 | import Network.BitTorrent.Tracker.HTTP | 45 | import Network.BitTorrent.Tracker.HTTP |
46 | import Network.BitTorrent.Tracker.UDP | ||
47 | |||
48 | {----------------------------------------------------------------------- | ||
49 | Generalized Tracker instance — UDP + HTTP | ||
50 | -----------------------------------------------------------------------} | ||
51 | |||
52 | data BitTracker = HTTPTr HTTPTracker | ||
53 | | UDPTr UDPTracker | ||
54 | |||
55 | instance Tracker BitTracker where | ||
56 | connect uri @ URI {..} | ||
57 | | uriScheme == "udp:" = UDPTr <$> connect uri | ||
58 | | uriScheme == "http:" = HTTPTr <$> connect uri | ||
59 | | otherwise = throwIO $ userError msg | ||
60 | where | ||
61 | msg = "unknown tracker protocol scheme: " ++ show uriScheme | ||
62 | |||
63 | announce (HTTPTr t) = Tracker.announce t | ||
64 | announce (UDPTr t) = Tracker.announce t | ||
65 | |||
66 | scrape (HTTPTr t) = scrape t | ||
67 | scrape (UDPTr t) = scrape t | ||
46 | 68 | ||
47 | {----------------------------------------------------------------------- | 69 | {----------------------------------------------------------------------- |
48 | Tracker connection | 70 | Tracker connection |
@@ -149,7 +171,7 @@ data TSession = TSession { | |||
149 | seProgress :: TVar Progress | 171 | seProgress :: TVar Progress |
150 | , seInterval :: IORef TimeInterval | 172 | , seInterval :: IORef TimeInterval |
151 | , sePeers :: BoundedChan PeerAddr | 173 | , sePeers :: BoundedChan PeerAddr |
152 | , seTracker :: HTTPTracker | 174 | , seTracker :: BitTracker |
153 | } | 175 | } |
154 | 176 | ||
155 | type PeerCount = Int | 177 | type PeerCount = Int |
@@ -164,7 +186,7 @@ getProgress :: TSession -> IO Progress | |||
164 | getProgress = readTVarIO . seProgress | 186 | getProgress = readTVarIO . seProgress |
165 | 187 | ||
166 | newSession :: PeerCount -> Progress -> TimeInterval -> [PeerAddr] | 188 | newSession :: PeerCount -> Progress -> TimeInterval -> [PeerAddr] |
167 | -> HTTPTracker | 189 | -> BitTracker |
168 | -> IO TSession | 190 | -> IO TSession |
169 | newSession chanSize pr i ps tr | 191 | newSession chanSize pr i ps tr |
170 | | chanSize < 1 | 192 | | chanSize < 1 |