summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Tracker/RPC/UDP.hs7
-rw-r--r--tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs13
2 files changed, 19 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Tracker/RPC/UDP.hs b/src/Network/BitTorrent/Tracker/RPC/UDP.hs
index 160397dd..0cb8e95e 100644
--- a/src/Network/BitTorrent/Tracker/RPC/UDP.hs
+++ b/src/Network/BitTorrent/Tracker/RPC/UDP.hs
@@ -212,6 +212,9 @@ data RpcException
212 -- | Unable to lookup hostname; 212 -- | Unable to lookup hostname;
213 | HostLookupFailed 213 | HostLookupFailed
214 214
215 -- | Expecting 'udp:', but some other scheme provided.
216 | UnrecognizedScheme String
217
215 -- | Tracker exists but not responding for specific number of seconds. 218 -- | Tracker exists but not responding for specific number of seconds.
216 | TimeoutExpired Int 219 | TimeoutExpired Int
217 220
@@ -250,7 +253,9 @@ resolveURI _ = throwIO HostUnknown
250 253
251-- TODO caching? 254-- TODO caching?
252getTrackerAddr :: Manager -> URI -> IO SockAddr 255getTrackerAddr :: Manager -> URI -> IO SockAddr
253getTrackerAddr _ = resolveURI 256getTrackerAddr _ uri
257 | uriScheme uri == "udp:" = resolveURI uri
258 | otherwise = throwIO (UnrecognizedScheme (uriScheme uri))
254 259
255{----------------------------------------------------------------------- 260{-----------------------------------------------------------------------
256 Tokens 261 Tokens
diff --git a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs
index 598b2866..8a1ffc01 100644
--- a/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/RPC/UDPSpec.hs
@@ -97,6 +97,19 @@ spec = parallel $ do
97 scrape mgr (trackerURI badTracker) [def] `shouldThrow` isSomeException 97 scrape mgr (trackerURI badTracker) [def] `shouldThrow` isSomeException
98 98
99 describe "RPC" $ do 99 describe "RPC" $ do
100 describe "announce" $ do
101 it "must fail on bad scheme" $ do
102 withManager rpcOpts $ \ mgr -> do
103 q <- arbitrarySample
104 announce mgr "magnet://a.com" q
105 `shouldThrow` (== UnrecognizedScheme "magnet:")
106
107 describe "scrape" $ do
108 it "must fail on bad scheme" $ do
109 withManager rpcOpts $ \ mgr -> do
110 scrape mgr "magnet://a.com" []
111 `shouldThrow` (== UnrecognizedScheme "magnet:")
112
100 forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} -> 113 forM_ (L.filter isUdpTracker trackers) $ \ TrackerEntry {..} ->
101 context trackerName $ do 114 context trackerName $ do
102 115