summaryrefslogtreecommitdiff
path: root/src/Data
diff options
context:
space:
mode:
Diffstat (limited to 'src/Data')
-rw-r--r--src/Data/Torrent/Client.hs283
1 files changed, 0 insertions, 283 deletions
diff --git a/src/Data/Torrent/Client.hs b/src/Data/Torrent/Client.hs
deleted file mode 100644
index a21a9c92..00000000
--- a/src/Data/Torrent/Client.hs
+++ /dev/null
@@ -1,283 +0,0 @@
1-- |
2-- Copyright : (c) Sam Truzjan 2013
3-- License : BSD3
4-- Maintainer : pxqr.sta@gmail.com
5-- Stability : experimental
6-- Portability : portable
7--
8-- 'ClientInfo' is used to identify the client implementation and
9-- version which also contained in 'Peer'. For exsample first 6
10-- bytes of peer id of this this library are @-HS0100-@ while for
11-- mainline we have @M4-3-6--@. We could extract this info and
12-- print in human-friendly form: this is useful for debugging and
13-- logging.
14--
15-- For more information see:
16-- <http://bittorrent.org/beps/bep_0020.html>
17--
18--
19-- NOTE: Do /not/ use this information to control client
20-- capabilities (such as supported enchancements), this should be
21-- done using 'Network.BitTorrent.Extension'!
22--
23{-# OPTIONS -fno-warn-orphans #-}
24module Data.Torrent.Client
25 ( ClientImpl (..)
26 , ClientInfo (..)
27 , libClientInfo
28 ) where
29
30import Data.Default
31import Data.List as L
32import Data.List.Split as L
33import Data.String
34import Data.Version
35import Text.PrettyPrint hiding ((<>))
36import Text.PrettyPrint.Class
37import Text.Read (readMaybe)
38-- import Paths_bittorrent (version)
39
40-- TODO FIXME
41version :: Version
42version = Version [0, 0, 0, 3] []
43
44-- | List of registered client versions + 'IlibHSbittorrent' (this
45-- package) + 'IUnknown' (for not recognized software). All names are
46-- prefixed by \"I\" because some of them starts from lowercase letter
47-- but that is not a valid Haskell constructor name.
48--
49data ClientImpl =
50 IUnknown
51
52 | IMainline
53
54 | IABC
55 | IOspreyPermaseed
56 | IBTQueue
57 | ITribler
58 | IShadow
59 | IBitTornado
60
61-- UPnP(!) Bit Torrent !???
62-- 'U' - UPnP NAT Bit Torrent
63 | IBitLord
64 | IOpera
65 | IMLdonkey
66
67 | IAres
68 | IArctic
69 | IAvicora
70 | IBitPump
71 | IAzureus
72 | IBitBuddy
73 | IBitComet
74 | IBitflu
75 | IBTG
76 | IBitRocket
77 | IBTSlave
78 | IBittorrentX
79 | IEnhancedCTorrent
80 | ICTorrent
81 | IDelugeTorrent
82 | IPropagateDataClient
83 | IEBit
84 | IElectricSheep
85 | IFoxTorrent
86 | IGSTorrent
87 | IHalite
88 | IlibHSbittorrent
89 | IHydranode
90 | IKGet
91 | IKTorrent
92 | ILH_ABC
93 | ILphant
94 | ILibtorrent
95 | ILibTorrent
96 | ILimeWire
97 | IMonoTorrent
98 | IMooPolice
99 | IMiro
100 | IMoonlightTorrent
101 | INetTransport
102 | IPando
103 | IqBittorrent
104 | IQQDownload
105 | IQt4TorrentExample
106 | IRetriever
107 | IShareaza
108 | ISwiftbit
109 | ISwarmScope
110 | ISymTorrent
111 | Isharktorrent
112 | ITorrentDotNET
113 | ITransmission
114 | ITorrentstorm
115 | ITuoTu
116 | IuLeecher
117 | IuTorrent
118 | IVagaa
119 | IBitLet
120 | IFireTorrent
121 | IXunlei
122 | IXanTorrent
123 | IXtorrent
124 | IZipTorrent
125 deriving (Show, Eq, Ord, Enum, Bounded)
126
127-- | Used to represent a not recognized implementation
128instance Default ClientImpl where
129 def = IUnknown
130 {-# INLINE def #-}
131
132-- | Example: @\"BitLet\" == 'IBitLet'@
133instance IsString ClientImpl where
134 fromString str
135 | Just impl <- L.lookup str alist = impl
136 | otherwise = error $ "fromString: not recognized " ++ str
137 where
138 alist = L.map mk [minBound..maxBound]
139 mk x = (L.tail $ show x, x)
140
141-- | Example: @pretty 'IBitLet' == \"IBitLet\"@
142instance Pretty ClientImpl where
143 pretty = text . L.tail . show
144
145-- | Just the '0' version.
146instance Default Version where
147 def = Version [0] []
148 {-# INLINE def #-}
149
150-- | For dot delimited version strings.
151-- Example: @fromString \"0.1.0.2\" == Version [0, 1, 0, 2]@
152--
153instance IsString Version where
154 fromString str
155 | Just nums <- chunkNums str = Version nums []
156 | otherwise = error $ "fromString: invalid version string " ++ str
157 where
158 chunkNums = sequence . L.map readMaybe . L.linesBy ('.' ==)
159
160instance Pretty Version where
161 pretty = text . showVersion
162
163-- | The all sensible infomation that can be obtained from a peer
164-- identifier or torrent /createdBy/ field.
165data ClientInfo = ClientInfo {
166 ciImpl :: ClientImpl
167 , ciVersion :: Version
168 } deriving (Show, Eq, Ord)
169
170-- | Unrecognized client implementation.
171instance Default ClientInfo where
172 def = ClientInfo def def
173 {-# INLINE def #-}
174
175-- | Example: @\"BitComet-1.2\" == ClientInfo IBitComet (Version [1, 2] [])@
176instance IsString ClientInfo where
177 fromString str
178 | _ : ver <- _ver = ClientInfo (fromString impl) (fromString ver)
179 | otherwise = error $ "fromString: invalid client info string" ++ str
180 where
181 (impl, _ver) = L.span ((/=) '-') str
182
183instance Pretty ClientInfo where
184 pretty ClientInfo {..} = pretty ciImpl <+> "version" <+> pretty ciVersion
185
186-- | Client info of this (the bittorrent library) package. Normally,
187-- applications should introduce its own idenitifiers, otherwise they
188-- can use 'libClientInfo' value.
189--
190libClientInfo :: ClientInfo
191libClientInfo = ClientInfo IlibHSbittorrent version
192
193{-----------------------------------------------------------------------
194-- For torrent file
195-----------------------------------------------------------------------}
196-- TODO collect information about createdBy torrent field
197{-
198renderImpl :: ClientImpl -> Text
199renderImpl = T.pack . L.tail . show
200
201renderVersion :: Version -> Text
202renderVersion = undefined
203
204renderClientInfo :: ClientInfo -> Text
205renderClientInfo ClientInfo {..} = renderImpl ciImpl <> "/" <> renderVersion ciVersion
206
207parseClientInfo :: Text -> ClientImpl
208parseClientInfo t = undefined
209-}
210{-
211-- code used for generation; remove it later on
212
213mkEnumTyDef :: NM -> String
214mkEnumTyDef = unlines . map (" | I" ++) . nub . map snd
215
216mkPars :: NM -> String
217mkPars = unlines . map (\(code, impl) -> " f \"" ++ code ++ "\" = " ++ "I" ++ impl)
218
219type NM = [(String, String)]
220nameMap :: NM
221nameMap =
222 [ ("AG", "Ares")
223 , ("A~", "Ares")
224 , ("AR", "Arctic")
225 , ("AV", "Avicora")
226 , ("AX", "BitPump")
227 , ("AZ", "Azureus")
228 , ("BB", "BitBuddy")
229 , ("BC", "BitComet")
230 , ("BF", "Bitflu")
231 , ("BG", "BTG")
232 , ("BR", "BitRocket")
233 , ("BS", "BTSlave")
234 , ("BX", "BittorrentX")
235 , ("CD", "EnhancedCTorrent")
236 , ("CT", "CTorrent")
237 , ("DE", "DelugeTorrent")
238 , ("DP", "PropagateDataClient")
239 , ("EB", "EBit")
240 , ("ES", "ElectricSheep")
241 , ("FT", "FoxTorrent")
242 , ("GS", "GSTorrent")
243 , ("HL", "Halite")
244 , ("HS", "libHSnetwork_bittorrent")
245 , ("HN", "Hydranode")
246 , ("KG", "KGet")
247 , ("KT", "KTorrent")
248 , ("LH", "LH_ABC")
249 , ("LP", "Lphant")
250 , ("LT", "Libtorrent")
251 , ("lt", "LibTorrent")
252 , ("LW", "LimeWire")
253 , ("MO", "MonoTorrent")
254 , ("MP", "MooPolice")
255 , ("MR", "Miro")
256 , ("MT", "MoonlightTorrent")
257 , ("NX", "NetTransport")
258 , ("PD", "Pando")
259 , ("qB", "qBittorrent")
260 , ("QD", "QQDownload")
261 , ("QT", "Qt4TorrentExample")
262 , ("RT", "Retriever")
263 , ("S~", "Shareaza")
264 , ("SB", "Swiftbit")
265 , ("SS", "SwarmScope")
266 , ("ST", "SymTorrent")
267 , ("st", "sharktorrent")
268 , ("SZ", "Shareaza")
269 , ("TN", "TorrentDotNET")
270 , ("TR", "Transmission")
271 , ("TS", "Torrentstorm")
272 , ("TT", "TuoTu")
273 , ("UL", "uLeecher")
274 , ("UT", "uTorrent")
275 , ("VG", "Vagaa")
276 , ("WT", "BitLet")
277 , ("WY", "FireTorrent")
278 , ("XL", "Xunlei")
279 , ("XT", "XanTorrent")
280 , ("XX", "Xtorrent")
281 , ("ZT", "ZipTorrent")
282 ]
283-}