summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 04:54:37 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 04:54:37 +0400
commit0d45d13454644224d6eb461225ef938b84adab6a (patch)
treedbae0e4130e50df0b3e01b7328a657e2ccf5a595 /src
parente3ee3bf4b174363f55c3af2195bd191e9c0d25b7 (diff)
Decode shadow style de peer Ids
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent/Client.hs12
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs23
2 files changed, 33 insertions, 2 deletions
diff --git a/src/Data/Torrent/Client.hs b/src/Data/Torrent/Client.hs
index 079b63c1..1b24105f 100644
--- a/src/Data/Torrent/Client.hs
+++ b/src/Data/Torrent/Client.hs
@@ -50,7 +50,19 @@ import Paths_bittorrent (version)
50-- 50--
51data ClientImpl = 51data ClientImpl =
52 IUnknown 52 IUnknown
53
53 | IMainline 54 | IMainline
55
56 | IABC
57 | IOspreyPermaseed
58 | IBTQueue
59 | ITribler
60 | IShadow
61 | IBitTornado
62
63-- UPnP(!) Bit Torrent !???
64-- 'U' - UPnP NAT Bit Torrent
65
54 | IAres 66 | IAres
55 | IArctic 67 | IArctic
56 | IAvicora 68 | IAvicora
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs
index 75a4d7a0..5962a6e5 100644
--- a/src/Network/BitTorrent/Core/PeerId.hs
+++ b/src/Network/BitTorrent/Core/PeerId.hs
@@ -47,7 +47,7 @@ import Data.Default
47import Data.Foldable (foldMap) 47import Data.Foldable (foldMap)
48import Data.List as L 48import Data.List as L
49import Data.List.Split as L 49import Data.List.Split as L
50import Data.Maybe (fromMaybe) 50import Data.Maybe (fromMaybe, catMaybes)
51import Data.Monoid 51import Data.Monoid
52import Data.Serialize as S 52import Data.Serialize as S
53import Data.String 53import Data.String
@@ -287,7 +287,7 @@ clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid)
287 case leading of 287 case leading of
288 '-' -> ClientInfo <$> getAzureusImpl <*> getAzureusVersion 288 '-' -> ClientInfo <$> getAzureusImpl <*> getAzureusVersion
289 'M' -> ClientInfo <$> pure IMainline <*> getMainlineVersion 289 'M' -> ClientInfo <$> pure IMainline <*> getMainlineVersion
290 _ -> pure def 290 c -> ClientInfo <$> pure (getShadowImpl c) <*> getShadowVersion
291 291
292 getMainlineVersion = do 292 getMainlineVersion = do
293 str <- BC.unpack <$> getByteString 7 293 str <- BC.unpack <$> getByteString 7
@@ -298,3 +298,22 @@ clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid)
298 getAzureusVersion = mkVer <$> getByteString 4 298 getAzureusVersion = mkVer <$> getByteString 4
299 where 299 where
300 mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] [] 300 mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] []
301
302 getShadowImpl 'A' = IABC
303 getShadowImpl 'O' = IOspreyPermaseed
304 getShadowImpl 'Q' = IBTQueue
305 getShadowImpl 'R' = ITribler
306 getShadowImpl 'S' = IShadow
307 getShadowImpl 'T' = IBitTornado
308 getShadowImpl _ = IUnknown
309
310 decodeShadowVerNr :: Char -> Maybe Int
311 decodeShadowVerNr c
312 | '0' < c && c <= '9' = Just (fromEnum c - fromEnum '0')
313 | 'A' < c && c <= 'Z' = Just ((fromEnum c - fromEnum 'A') + 10)
314 | 'a' < c && c <= 'z' = Just ((fromEnum c - fromEnum 'a') + 36)
315 | otherwise = Nothing
316
317 getShadowVersion = do
318 str <- BC.unpack <$> getByteString 5
319 return $ Version (catMaybes $ L.map decodeShadowVerNr str) []