diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 04:54:37 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 04:54:37 +0400 |
commit | 0d45d13454644224d6eb461225ef938b84adab6a (patch) | |
tree | dbae0e4130e50df0b3e01b7328a657e2ccf5a595 /src/Network | |
parent | e3ee3bf4b174363f55c3af2195bd191e9c0d25b7 (diff) |
Decode shadow style de peer Ids
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 23 |
1 files changed, 21 insertions, 2 deletions
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 | |||
47 | import Data.Foldable (foldMap) | 47 | import Data.Foldable (foldMap) |
48 | import Data.List as L | 48 | import Data.List as L |
49 | import Data.List.Split as L | 49 | import Data.List.Split as L |
50 | import Data.Maybe (fromMaybe) | 50 | import Data.Maybe (fromMaybe, catMaybes) |
51 | import Data.Monoid | 51 | import Data.Monoid |
52 | import Data.Serialize as S | 52 | import Data.Serialize as S |
53 | import Data.String | 53 | import 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) [] | ||