summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-08-28 05:13:35 +0400
committerSam T <pxqr.sta@gmail.com>2013-08-28 05:13:35 +0400
commit8661b97e62e785b8c95479ea0bb8855632f55dec (patch)
treedccd153bea4c73be9ad65a9912cf4158a95155bf /src/Network
parent03841eb1f2e8e0d38833b8855a55e393fb4d766a (diff)
+ Add generalized tracker.
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Tracker.hs26
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
43import Network.BitTorrent.Peer 43import Network.BitTorrent.Peer
44import Network.BitTorrent.Tracker.Protocol as Tracker 44import Network.BitTorrent.Tracker.Protocol as Tracker
45import Network.BitTorrent.Tracker.HTTP 45import Network.BitTorrent.Tracker.HTTP
46import Network.BitTorrent.Tracker.UDP
47
48{-----------------------------------------------------------------------
49 Generalized Tracker instance — UDP + HTTP
50-----------------------------------------------------------------------}
51
52data BitTracker = HTTPTr HTTPTracker
53 | UDPTr UDPTracker
54
55instance 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
155type PeerCount = Int 177type PeerCount = Int
@@ -164,7 +186,7 @@ getProgress :: TSession -> IO Progress
164getProgress = readTVarIO . seProgress 186getProgress = readTVarIO . seProgress
165 187
166newSession :: PeerCount -> Progress -> TimeInterval -> [PeerAddr] 188newSession :: PeerCount -> Progress -> TimeInterval -> [PeerAddr]
167 -> HTTPTracker 189 -> BitTracker
168 -> IO TSession 190 -> IO TSession
169newSession chanSize pr i ps tr 191newSession chanSize pr i ps tr
170 | chanSize < 1 192 | chanSize < 1