diff options
Diffstat (limited to 'tests/Network/BitTorrent/Tracker')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/TestData.hs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/Network/BitTorrent/Tracker/TestData.hs b/tests/Network/BitTorrent/Tracker/TestData.hs new file mode 100644 index 00000000..5d9718e5 --- /dev/null +++ b/tests/Network/BitTorrent/Tracker/TestData.hs | |||
@@ -0,0 +1,71 @@ | |||
1 | {-# OPTIONS_GHC -fno-warn-orphans #-} | ||
2 | module Network.BitTorrent.Tracker.TestData | ||
3 | ( TrackerEntry (..) | ||
4 | , trackers | ||
5 | ) where | ||
6 | |||
7 | import Data.Maybe | ||
8 | import Data.String | ||
9 | import Network.URI | ||
10 | |||
11 | import Data.Torrent.InfoHash | ||
12 | |||
13 | |||
14 | data TrackerEntry = TrackerEntry | ||
15 | { -- | May be used to show tracker name in test suite report. | ||
16 | trackerName :: String | ||
17 | |||
18 | -- | Announce uri of the tracker. | ||
19 | , trackerURI :: URI | ||
20 | |||
21 | -- | Some trackers abadoned, so don't even try to announce. | ||
22 | , tryAnnounce :: Bool | ||
23 | |||
24 | -- | Some trackers do not support scraping, so we should not even | ||
25 | -- try to scrape them. | ||
26 | , tryScraping :: Bool | ||
27 | |||
28 | -- | Some trackers allow | ||
29 | , hashList :: Maybe [InfoHash] | ||
30 | } | ||
31 | |||
32 | instance IsString URI where | ||
33 | fromString str = fromMaybe err $ parseURI str | ||
34 | where | ||
35 | err = error $ "fromString: bad URI " ++ show str | ||
36 | |||
37 | trackerEntry :: URI -> TrackerEntry | ||
38 | trackerEntry uri = TrackerEntry | ||
39 | { trackerName = maybe "<unknown>" uriRegName (uriAuthority uri) | ||
40 | , trackerURI = uri | ||
41 | , tryAnnounce = False | ||
42 | , tryScraping = False | ||
43 | , hashList = Nothing | ||
44 | } | ||
45 | |||
46 | announceOnly :: String -> URI -> TrackerEntry | ||
47 | announceOnly name uri = (trackerEntry uri) | ||
48 | { trackerName = name | ||
49 | , tryAnnounce = True | ||
50 | } | ||
51 | |||
52 | announceScrape :: String -> URI -> TrackerEntry | ||
53 | announceScrape name uri = (announceOnly name uri) | ||
54 | { tryScraping = True | ||
55 | } | ||
56 | |||
57 | notWorking :: String -> URI -> TrackerEntry | ||
58 | notWorking name uri = (trackerEntry uri) | ||
59 | { trackerName = name | ||
60 | } | ||
61 | |||
62 | trackers :: [TrackerEntry] | ||
63 | trackers = | ||
64 | [ announceOnly "LinuxTracker" | ||
65 | "http://linuxtracker.org:2710/00000000000000000000000000000000/announce" | ||
66 | |||
67 | , announceScrape "OpenBitTorrent" "udp://tracker.openbittorrent.com:80/announce" | ||
68 | , announceScrape "PublicBT" "udp://tracker.publicbt.com:80/announce" | ||
69 | , notWorking "OpenBitTorrent" "http://tracker.openbittorrent.com:80/announce" | ||
70 | , notWorking "PublicBT" "http://tracker.publicbt.com:80/announce" | ||
71 | ] | ||