diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs index b8dd17e2..3e6fac24 100644 --- a/src/Network/BitTorrent/Core/PeerId.hs +++ b/src/Network/BitTorrent/Core/PeerId.hs | |||
@@ -275,6 +275,8 @@ parseImpl = f . BC.unpack | |||
275 | f "ZT" = IZipTorrent | 275 | f "ZT" = IZipTorrent |
276 | f _ = IUnknown | 276 | f _ = IUnknown |
277 | 277 | ||
278 | -- TODO use regexps | ||
279 | |||
278 | -- | Tries to extract meaningful information from peer ID bytes. If | 280 | -- | Tries to extract meaningful information from peer ID bytes. If |
279 | -- peer id uses unknown coding style then client info returned is | 281 | -- peer id uses unknown coding style then client info returned is |
280 | -- 'def'. | 282 | -- 'def'. |
@@ -289,7 +291,13 @@ clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid) | |||
289 | 'M' -> ClientInfo <$> pure IMainline <*> getMainlineVersion | 291 | 'M' -> ClientInfo <$> pure IMainline <*> getMainlineVersion |
290 | 'e' -> ClientInfo <$> getBitCometImpl <*> getBitCometVersion | 292 | 'e' -> ClientInfo <$> getBitCometImpl <*> getBitCometVersion |
291 | 'F' -> ClientInfo <$> getBitCometImpl <*> getBitCometVersion | 293 | 'F' -> ClientInfo <$> getBitCometImpl <*> getBitCometVersion |
292 | c -> ClientInfo <$> pure (getShadowImpl c) <*> getShadowVersion | 294 | c -> do |
295 | c1 <- w2c <$> lookAhead getWord8 | ||
296 | if c1 == 'P' | ||
297 | then do | ||
298 | _ <- getWord8 | ||
299 | ClientInfo <$> pure IOpera <*> getOperaVersion | ||
300 | else ClientInfo <$> pure (getShadowImpl c) <*> getShadowVersion | ||
293 | 301 | ||
294 | getMainlineVersion = do | 302 | getMainlineVersion = do |
295 | str <- BC.unpack <$> getByteString 7 | 303 | str <- BC.unpack <$> getByteString 7 |
@@ -316,6 +324,10 @@ clientInfo pid = either (const def) id $ runGet getCI (getPeerId pid) | |||
316 | y <- getWord8 | 324 | y <- getWord8 |
317 | return $ Version [fromIntegral x, fromIntegral y] [] | 325 | return $ Version [fromIntegral x, fromIntegral y] [] |
318 | 326 | ||
327 | getOperaVersion = do | ||
328 | str <- BC.unpack <$> getByteString 4 | ||
329 | return $ Version [fromMaybe 0 $ readMaybe str] [] | ||
330 | |||
319 | getShadowImpl 'A' = IABC | 331 | getShadowImpl 'A' = IABC |
320 | getShadowImpl 'O' = IOspreyPermaseed | 332 | getShadowImpl 'O' = IOspreyPermaseed |
321 | getShadowImpl 'Q' = IBTQueue | 333 | getShadowImpl 'Q' = IBTQueue |