summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Tracker/TestData.hs
blob: e0edba25264d26530afd7ab6da683280bb97fc5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{-# LANGUAGE RecordWildCards #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Network.BitTorrent.Tracker.TestData
       ( TrackerEntry (..)
       , isUdpTracker
       , isHttpTracker
       , trackers
       , badTracker
       ) where

import Data.Maybe
import Data.String
import Network.URI

import Data.Torrent.InfoHash


data TrackerEntry = TrackerEntry
  { -- | May be used to show tracker name in test suite report.
    trackerName :: String

    -- | Announce uri of the tracker.
  , trackerURI  :: URI

    -- | Some trackers abadoned, so don't even try to announce.
  , tryAnnounce :: Bool

    -- | Some trackers do not support scraping, so we should not even
    -- try to scrape them.
  , tryScraping :: Bool

    -- | Some trackers allow
  , hashList    :: Maybe [InfoHash]
  }

isUdpTracker :: TrackerEntry -> Bool
isUdpTracker TrackerEntry {..} = uriScheme trackerURI == "udp:"

isHttpTracker :: TrackerEntry -> Bool
isHttpTracker TrackerEntry {..} = uriScheme trackerURI == "http:"
                               || uriScheme trackerURI == "https:"

instance IsString URI where
  fromString str = fromMaybe err $ parseURI str
    where
      err = error $ "fromString: bad URI " ++ show str

trackerEntry :: URI -> TrackerEntry
trackerEntry uri = TrackerEntry
  { trackerName = maybe "<unknown>" uriRegName (uriAuthority uri)
  , trackerURI  = uri
  , tryAnnounce = False
  , tryScraping = False
  , hashList    = Nothing
  }

announceOnly :: String -> URI -> TrackerEntry
announceOnly name uri = (trackerEntry uri)
  { trackerName = name
  , tryAnnounce = True
  }

announceScrape :: String -> URI -> TrackerEntry
announceScrape name uri = (announceOnly name uri)
  { tryScraping = True
  }

notWorking :: String -> URI -> TrackerEntry
notWorking name uri = (trackerEntry uri)
  { trackerName = name
  }

trackers :: [TrackerEntry]
trackers =
  [ (announceOnly "LinuxTracker"
    "http://linuxtracker.org:2710/00000000000000000000000000000000/announce")
    { hashList = Just ["1c82a95b9e02bf3db4183da072ad3ef656aacf0e"] -- debian 7
    }

  , (announceScrape "Arch" "http://tracker.archlinux.org:6969/announce")
    { hashList = Just ["bc9ae647a3e6c3636de58535dd3f6360ce9f4621"]
    }

  , notWorking     "rarbg" "udp://9.rarbg.com:2710/announce"

  , announceScrape "OpenBitTorrent" "udp://tracker.openbittorrent.com:80/announce"
  , announceScrape "PublicBT"       "udp://tracker.publicbt.com:80/announce"
  , notWorking     "OpenBitTorrent" "http://tracker.openbittorrent.com:80/announce"
  , notWorking     "PublicBT"       "http://tracker.publicbt.com:80/announce"
  ]

badTracker :: TrackerEntry
badTracker = notWorking "rarbg" "udp://9.rarbg.com:2710/announce"