diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 04:29:59 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-11-23 04:29:59 +0400 |
commit | e3ee3bf4b174363f55c3af2195bd191e9c0d25b7 (patch) | |
tree | af432782fe94c10d901c15a1b9579975577edd77 /src/Network/BitTorrent/Core | |
parent | ed25a297094b483dce06e14d52ced2f93f6dca41 (diff) |
Add mainline client implementation id
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs index 6aebe8d4..75a4d7a0 100644 --- a/src/Network/BitTorrent/Core/PeerId.hs +++ b/src/Network/BitTorrent/Core/PeerId.hs | |||
@@ -39,12 +39,14 @@ import Control.Applicative | |||
39 | import Data.Aeson | 39 | import Data.Aeson |
40 | import Data.BEncode as BE | 40 | import Data.BEncode as BE |
41 | import Data.ByteString as BS | 41 | import Data.ByteString as BS |
42 | import Data.ByteString.Internal as BS | ||
42 | import Data.ByteString.Char8 as BC | 43 | import Data.ByteString.Char8 as BC |
43 | import qualified Data.ByteString.Lazy as BL | 44 | import qualified Data.ByteString.Lazy as BL |
44 | import qualified Data.ByteString.Lazy.Builder as BS | 45 | import qualified Data.ByteString.Lazy.Builder as BS |
45 | import Data.Default | 46 | import Data.Default |
46 | import Data.Foldable (foldMap) | 47 | import Data.Foldable (foldMap) |
47 | import Data.List as L | 48 | import Data.List as L |
49 | import Data.List.Split as L | ||
48 | import Data.Maybe (fromMaybe) | 50 | import Data.Maybe (fromMaybe) |
49 | import Data.Monoid | 51 | import Data.Monoid |
50 | import Data.Serialize as S | 52 | import Data.Serialize as S |
@@ -279,9 +281,20 @@ parseImpl = f . BC.unpack | |||
279 | -- | 281 | -- |
280 | clientInfo :: PeerId -> ClientInfo | 282 | clientInfo :: PeerId -> ClientInfo |
281 | clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid) | 283 | clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid) |
282 | where -- TODO other styles | 284 | where |
283 | getCI = getWord8 >> ClientInfo <$> getClientImpl <*> getClientVersion | 285 | getCI = do |
284 | getClientImpl = parseImpl <$> getByteString 2 | 286 | leading <- BS.w2c <$> getWord8 |
285 | getClientVersion = mkVer <$> getByteString 4 | 287 | case leading of |
288 | '-' -> ClientInfo <$> getAzureusImpl <*> getAzureusVersion | ||
289 | 'M' -> ClientInfo <$> pure IMainline <*> getMainlineVersion | ||
290 | _ -> pure def | ||
291 | |||
292 | getMainlineVersion = do | ||
293 | str <- BC.unpack <$> getByteString 7 | ||
294 | let mnums = L.filter (not . L.null) $ L.linesBy ('-' ==) str | ||
295 | return $ Version (fromMaybe [] $ sequence $ L.map readMaybe mnums) [] | ||
296 | |||
297 | getAzureusImpl = parseImpl <$> getByteString 2 | ||
298 | getAzureusVersion = mkVer <$> getByteString 4 | ||
286 | where | 299 | where |
287 | mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] [] | 300 | mkVer bs = Version [fromMaybe 0 $ readMaybe $ BC.unpack bs] [] |