diff options
Diffstat (limited to 'src/Network/BitTorrent/Peer/ClientInfo.hs')
-rw-r--r-- | src/Network/BitTorrent/Peer/ClientInfo.hs | 289 |
1 files changed, 0 insertions, 289 deletions
diff --git a/src/Network/BitTorrent/Peer/ClientInfo.hs b/src/Network/BitTorrent/Peer/ClientInfo.hs deleted file mode 100644 index 7200471a..00000000 --- a/src/Network/BitTorrent/Peer/ClientInfo.hs +++ /dev/null | |||
@@ -1,289 +0,0 @@ | |||
1 | -- | | ||
2 | -- Copyright : (c) Sam T. 2013 | ||
3 | -- License : MIT | ||
4 | -- Maintainer : pxqr.sta@gmail.com | ||
5 | -- Stability : experimental | ||
6 | -- Portability : portable | ||
7 | -- | ||
8 | -- This module detect client information such as version and | ||
9 | -- implementation that can be later printed in human frienly | ||
10 | -- form. Useful for debugging and logging. | ||
11 | -- | ||
12 | -- See <http://bittorrent.org/beps/bep_0020.html> for more | ||
13 | -- information. | ||
14 | -- | ||
15 | {-# LANGUAGE OverloadedStrings #-} | ||
16 | {-# LANGUAGE RecordWildCards #-} | ||
17 | module Network.BitTorrent.Peer.ClientInfo | ||
18 | ( -- * Info | ||
19 | ClientInfo(..), clientInfo, ppClientInfo, unknownClient | ||
20 | |||
21 | -- * Version | ||
22 | , ClientVersion, ppClientVersion | ||
23 | |||
24 | -- * Implementation | ||
25 | , ClientImpl(..), ppClientImpl | ||
26 | |||
27 | -- , mkEnumTyDef, mkPars, nameMap | ||
28 | ) where | ||
29 | |||
30 | import Control.Applicative | ||
31 | --import Data.List | ||
32 | import Data.ByteString (ByteString) | ||
33 | import qualified Data.ByteString.Char8 as BC | ||
34 | import Data.Serialize.Get | ||
35 | import Text.PrettyPrint | ||
36 | |||
37 | import Network.BitTorrent.Peer.ID | ||
38 | |||
39 | |||
40 | -- | All known client versions. | ||
41 | data ClientImpl = | ||
42 | IUnknown | ||
43 | | IAres | ||
44 | | IArctic | ||
45 | | IAvicora | ||
46 | | IBitPump | ||
47 | | IAzureus | ||
48 | | IBitBuddy | ||
49 | | IBitComet | ||
50 | | IBitflu | ||
51 | | IBTG | ||
52 | | IBitRocket | ||
53 | | IBTSlave | ||
54 | | IBittorrentX | ||
55 | | IEnhancedCTorrent | ||
56 | | ICTorrent | ||
57 | | IDelugeTorrent | ||
58 | | IPropagateDataClient | ||
59 | | IEBit | ||
60 | | IElectricSheep | ||
61 | | IFoxTorrent | ||
62 | | IGSTorrent | ||
63 | | IHalite | ||
64 | | IlibHSbittorrent | ||
65 | | IHydranode | ||
66 | | IKGet | ||
67 | | IKTorrent | ||
68 | | ILH_ABC | ||
69 | | ILphant | ||
70 | | ILibtorrent | ||
71 | | ILibTorrent | ||
72 | | ILimeWire | ||
73 | | IMonoTorrent | ||
74 | | IMooPolice | ||
75 | | IMiro | ||
76 | | IMoonlightTorrent | ||
77 | | INetTransport | ||
78 | | IPando | ||
79 | | IqBittorrent | ||
80 | | IQQDownload | ||
81 | | IQt4TorrentExample | ||
82 | | IRetriever | ||
83 | | IShareaza | ||
84 | | ISwiftbit | ||
85 | | ISwarmScope | ||
86 | | ISymTorrent | ||
87 | | Isharktorrent | ||
88 | | ITorrentDotNET | ||
89 | | ITransmission | ||
90 | | ITorrentstorm | ||
91 | | ITuoTu | ||
92 | | IuLeecher | ||
93 | | IuTorrent | ||
94 | | IVagaa | ||
95 | | IBitLet | ||
96 | | IFireTorrent | ||
97 | | IXunlei | ||
98 | | IXanTorrent | ||
99 | | IXtorrent | ||
100 | | IZipTorrent | ||
101 | deriving (Show, Eq, Ord) | ||
102 | |||
103 | parseImpl :: ByteString -> ClientImpl | ||
104 | parseImpl = f . BC.unpack | ||
105 | where | ||
106 | f "AG" = IAres | ||
107 | f "A~" = IAres | ||
108 | f "AR" = IArctic | ||
109 | f "AV" = IAvicora | ||
110 | f "AX" = IBitPump | ||
111 | f "AZ" = IAzureus | ||
112 | f "BB" = IBitBuddy | ||
113 | f "BC" = IBitComet | ||
114 | f "BF" = IBitflu | ||
115 | f "BG" = IBTG | ||
116 | f "BR" = IBitRocket | ||
117 | f "BS" = IBTSlave | ||
118 | f "BX" = IBittorrentX | ||
119 | f "CD" = IEnhancedCTorrent | ||
120 | f "CT" = ICTorrent | ||
121 | f "DE" = IDelugeTorrent | ||
122 | f "DP" = IPropagateDataClient | ||
123 | f "EB" = IEBit | ||
124 | f "ES" = IElectricSheep | ||
125 | f "FT" = IFoxTorrent | ||
126 | f "GS" = IGSTorrent | ||
127 | f "HL" = IHalite | ||
128 | f "HS" = IlibHSbittorrent | ||
129 | f "HN" = IHydranode | ||
130 | f "KG" = IKGet | ||
131 | f "KT" = IKTorrent | ||
132 | f "LH" = ILH_ABC | ||
133 | f "LP" = ILphant | ||
134 | f "LT" = ILibtorrent | ||
135 | f "lt" = ILibTorrent | ||
136 | f "LW" = ILimeWire | ||
137 | f "MO" = IMonoTorrent | ||
138 | f "MP" = IMooPolice | ||
139 | f "MR" = IMiro | ||
140 | f "MT" = IMoonlightTorrent | ||
141 | f "NX" = INetTransport | ||
142 | f "PD" = IPando | ||
143 | f "qB" = IqBittorrent | ||
144 | f "QD" = IQQDownload | ||
145 | f "QT" = IQt4TorrentExample | ||
146 | f "RT" = IRetriever | ||
147 | f "S~" = IShareaza | ||
148 | f "SB" = ISwiftbit | ||
149 | f "SS" = ISwarmScope | ||
150 | f "ST" = ISymTorrent | ||
151 | f "st" = Isharktorrent | ||
152 | f "SZ" = IShareaza | ||
153 | f "TN" = ITorrentDotNET | ||
154 | f "TR" = ITransmission | ||
155 | f "TS" = ITorrentstorm | ||
156 | f "TT" = ITuoTu | ||
157 | f "UL" = IuLeecher | ||
158 | f "UT" = IuTorrent | ||
159 | f "VG" = IVagaa | ||
160 | f "WT" = IBitLet | ||
161 | f "WY" = IFireTorrent | ||
162 | f "XL" = IXunlei | ||
163 | f "XT" = IXanTorrent | ||
164 | f "XX" = IXtorrent | ||
165 | f "ZT" = IZipTorrent | ||
166 | f _ = IUnknown | ||
167 | |||
168 | -- | Format client implementation info in human readable form. | ||
169 | ppClientImpl :: ClientImpl -> Doc | ||
170 | ppClientImpl = text . tail . show | ||
171 | |||
172 | unknownImpl :: ClientImpl | ||
173 | unknownImpl = IUnknown | ||
174 | |||
175 | |||
176 | |||
177 | type ClientVersion = ByteString | ||
178 | |||
179 | -- | Format client implementation version in human readable form. | ||
180 | ppClientVersion :: ClientVersion -> Doc | ||
181 | ppClientVersion = text . BC.unpack | ||
182 | |||
183 | unknownVersion :: ClientVersion | ||
184 | unknownVersion = "0000" | ||
185 | |||
186 | |||
187 | -- | All useful infomation that can be obtained from a peer | ||
188 | -- identifier. | ||
189 | data ClientInfo = ClientInfo { | ||
190 | ciImpl :: ClientImpl | ||
191 | , ciVersion :: ClientVersion | ||
192 | } deriving (Show, Eq, Ord) | ||
193 | |||
194 | -- | Format client implementation in human readable form. | ||
195 | ppClientInfo :: ClientInfo -> Doc | ||
196 | ppClientInfo ClientInfo {..} = | ||
197 | ppClientImpl ciImpl <+> "version" <+> ppClientVersion ciVersion | ||
198 | |||
199 | |||
200 | -- | Unrecognized client implementation. | ||
201 | unknownClient :: ClientInfo | ||
202 | unknownClient = ClientInfo unknownImpl unknownVersion | ||
203 | |||
204 | -- | Tries to extract meaningful information from peer ID bytes. If | ||
205 | -- peer id uses unknown coding style then client info returned is | ||
206 | -- 'unknownClient'. | ||
207 | -- | ||
208 | clientInfo :: PeerID -> ClientInfo | ||
209 | clientInfo pid = either (const unknownClient) id $ runGet getCI (getPeerID pid) | ||
210 | where -- TODO other styles | ||
211 | getCI = do | ||
212 | _ <- getWord8 | ||
213 | ClientInfo <$> (parseImpl <$> getByteString 2) <*> getByteString 4 | ||
214 | |||
215 | |||
216 | {- | ||
217 | -- code used for generation; remove it later on | ||
218 | |||
219 | mkEnumTyDef :: NM -> String | ||
220 | mkEnumTyDef = unlines . map (" | I" ++) . nub . map snd | ||
221 | |||
222 | mkPars :: NM -> String | ||
223 | mkPars = unlines . map (\(code, impl) -> " f \"" ++ code ++ "\" = " ++ "I" ++ impl) | ||
224 | |||
225 | type NM = [(String, String)] | ||
226 | nameMap :: NM | ||
227 | nameMap = | ||
228 | [ ("AG", "Ares") | ||
229 | , ("A~", "Ares") | ||
230 | , ("AR", "Arctic") | ||
231 | , ("AV", "Avicora") | ||
232 | , ("AX", "BitPump") | ||
233 | , ("AZ", "Azureus") | ||
234 | , ("BB", "BitBuddy") | ||
235 | , ("BC", "BitComet") | ||
236 | , ("BF", "Bitflu") | ||
237 | , ("BG", "BTG") | ||
238 | , ("BR", "BitRocket") | ||
239 | , ("BS", "BTSlave") | ||
240 | , ("BX", "BittorrentX") | ||
241 | , ("CD", "EnhancedCTorrent") | ||
242 | , ("CT", "CTorrent") | ||
243 | , ("DE", "DelugeTorrent") | ||
244 | , ("DP", "PropagateDataClient") | ||
245 | , ("EB", "EBit") | ||
246 | , ("ES", "ElectricSheep") | ||
247 | , ("FT", "FoxTorrent") | ||
248 | , ("GS", "GSTorrent") | ||
249 | , ("HL", "Halite") | ||
250 | , ("HS", "libHSnetwork_bittorrent") | ||
251 | , ("HN", "Hydranode") | ||
252 | , ("KG", "KGet") | ||
253 | , ("KT", "KTorrent") | ||
254 | , ("LH", "LH_ABC") | ||
255 | , ("LP", "Lphant") | ||
256 | , ("LT", "Libtorrent") | ||
257 | , ("lt", "LibTorrent") | ||
258 | , ("LW", "LimeWire") | ||
259 | , ("MO", "MonoTorrent") | ||
260 | , ("MP", "MooPolice") | ||
261 | , ("MR", "Miro") | ||
262 | , ("MT", "MoonlightTorrent") | ||
263 | , ("NX", "NetTransport") | ||
264 | , ("PD", "Pando") | ||
265 | , ("qB", "qBittorrent") | ||
266 | , ("QD", "QQDownload") | ||
267 | , ("QT", "Qt4TorrentExample") | ||
268 | , ("RT", "Retriever") | ||
269 | , ("S~", "Shareaza") | ||
270 | , ("SB", "Swiftbit") | ||
271 | , ("SS", "SwarmScope") | ||
272 | , ("ST", "SymTorrent") | ||
273 | , ("st", "sharktorrent") | ||
274 | , ("SZ", "Shareaza") | ||
275 | , ("TN", "TorrentDotNET") | ||
276 | , ("TR", "Transmission") | ||
277 | , ("TS", "Torrentstorm") | ||
278 | , ("TT", "TuoTu") | ||
279 | , ("UL", "uLeecher") | ||
280 | , ("UT", "uTorrent") | ||
281 | , ("VG", "Vagaa") | ||
282 | , ("WT", "BitLet") | ||
283 | , ("WY", "FireTorrent") | ||
284 | , ("XL", "Xunlei") | ||
285 | , ("XT", "XanTorrent") | ||
286 | , ("XX", "Xtorrent") | ||
287 | , ("ZT", "ZipTorrent") | ||
288 | ] | ||
289 | -} \ No newline at end of file | ||