summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core/PeerId.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-23 05:31:12 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-23 05:31:12 +0400
commit2a410ac4c7a176fa20d5b102be3002075079f199 (patch)
treeb36211c9129694dc1f7d57336f2044f8e21fe97e /src/Network/BitTorrent/Core/PeerId.hs
parent53fd4f2c4a3aa66d2f4cb36a673be3199002414e (diff)
Opera peer id encoding style
Diffstat (limited to 'src/Network/BitTorrent/Core/PeerId.hs')
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs14
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