summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 04:29:59 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 04:29:59 +0400
commite3ee3bf4b174363f55c3af2195bd191e9c0d25b7 (patch)
treeaf432782fe94c10d901c15a1b9579975577edd77 /src/Network/BitTorrent/Core
parented25a297094b483dce06e14d52ced2f93f6dca41 (diff)
Add mainline client implementation id
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs21
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
39import Data.Aeson 39import Data.Aeson
40import Data.BEncode as BE 40import Data.BEncode as BE
41import Data.ByteString as BS 41import Data.ByteString as BS
42import Data.ByteString.Internal as BS
42import Data.ByteString.Char8 as BC 43import Data.ByteString.Char8 as BC
43import qualified Data.ByteString.Lazy as BL 44import qualified Data.ByteString.Lazy as BL
44import qualified Data.ByteString.Lazy.Builder as BS 45import qualified Data.ByteString.Lazy.Builder as BS
45import Data.Default 46import Data.Default
46import Data.Foldable (foldMap) 47import Data.Foldable (foldMap)
47import Data.List as L 48import Data.List as L
49import Data.List.Split as L
48import Data.Maybe (fromMaybe) 50import Data.Maybe (fromMaybe)
49import Data.Monoid 51import Data.Monoid
50import Data.Serialize as S 52import Data.Serialize as S
@@ -279,9 +281,20 @@ parseImpl = f . BC.unpack
279-- 281--
280clientInfo :: PeerId -> ClientInfo 282clientInfo :: PeerId -> ClientInfo
281clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid) 283clientInfo 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] []