summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Tracker/RPC.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Tracker/RPC.hs')
-rw-r--r--src/Network/BitTorrent/Tracker/RPC.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC.hs b/src/Network/BitTorrent/Tracker/RPC.hs
new file mode 100644
index 00000000..c5aaeb03
--- /dev/null
+++ b/src/Network/BitTorrent/Tracker/RPC.hs
@@ -0,0 +1,41 @@
1module Network.BitTorrent.Tracker.RPC
2 ( module Network.BitTorrent.Tracker.RPC.Message
3 , TrackerRPC (..)
4 ) where
5
6import Network.BitTorrent.Tracker.RPC.Message
7import Network.BitTorrent.Tracker.RPC.HTTP as HTTP
8import Network.BitTorrent.Tracker.RPC.UDP as UDP
9
10-- | Set of tracker RPCs.
11class Tracker s where
12 connect :: URI -> IO s
13 announce :: s -> AnnounceQuery -> IO AnnounceInfo
14 scrape :: s -> ScrapeQuery -> IO Scrape
15
16instance Tracker HTTP.Tracker where
17 connect = return . HTTP.Tracker
18 announce = HTTP.announce
19 scrape = undefined
20
21instance Tracker UDP.Tracker where
22 connect = initialTracker
23 announce = announce
24 scrape = undefined
25
26data BitTracker = HTTPTr HTTPTracker
27 | UDPTr UDPTracker
28
29instance Tracker BitTracker where
30 connect uri @ URI {..}
31 | uriScheme == "udp:" = UDPTr <$> connect uri
32 | uriScheme == "http:" = HTTPTr <$> connect uri
33 | otherwise = throwIO $ userError msg
34 where
35 msg = "unknown tracker protocol scheme: " ++ show uriScheme
36
37 announce (HTTPTr t) = Tracker.announce t
38 announce (UDPTr t) = Tracker.announce t
39
40 scrape (HTTPTr t) = scrape t
41 scrape (UDPTr t) = scrape t