summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Data/Torrent/Client.hs1
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs21
2 files changed, 18 insertions, 4 deletions
diff --git a/src/Data/Torrent/Client.hs b/src/Data/Torrent/Client.hs
index 0fd6722b..079b63c1 100644
--- a/src/Data/Torrent/Client.hs
+++ b/src/Data/Torrent/Client.hs
@@ -50,6 +50,7 @@ import Paths_bittorrent (version)
50-- 50--
51data ClientImpl = 51data ClientImpl =
52 IUnknown 52 IUnknown
53 | IMainline
53 | IAres 54 | IAres
54 | IArctic 55 | IArctic
55 | IAvicora 56 | IAvicora
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] []