diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Torrent/Client.hs | 1 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 21 |
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 | -- |
51 | data ClientImpl = | 51 | data 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 | |||
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] [] |