From 8fe68502f23cd737cfd198ce63ae8522c8e11a7f Mon Sep 17 00:00:00 2001 From: Sam T Date: Sat, 20 Jul 2013 23:24:16 +0400 Subject: ~ Add binary serialization for ScrapeInfo. --- src/Network/BitTorrent/Tracker/Protocol.hs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Network/BitTorrent/Tracker/Protocol.hs b/src/Network/BitTorrent/Tracker/Protocol.hs index 7a5039cf..23bbe498 100644 --- a/src/Network/BitTorrent/Tracker/Protocol.hs +++ b/src/Network/BitTorrent/Tracker/Protocol.hs @@ -319,13 +319,13 @@ type ScrapeQuery = [InfoHash] -- | Overall information about particular torrent. data ScrapeInfo = ScrapeInfo { -- | Number of seeders - peers with the entire file. - siComplete :: !Int + siComplete :: {-# UNPACK #-} !Int -- | Total number of times the tracker has registered a completion. - , siDownloaded :: !Int + , siDownloaded :: {-# UNPACK #-} !Int -- | Number of leechers. - , siIncomplete :: !Int + , siIncomplete :: {-# UNPACK #-} !Int -- | Name of the torrent file, as specified by the "name" -- file in the info section of the .torrent file. @@ -349,6 +349,24 @@ instance BEncodable ScrapeInfo where <*> d >--? "name" fromBEncode _ = decodingError "ScrapeInfo" +instance Serialize ScrapeInfo where + put ScrapeInfo {..} = do + putWord32be $ fromIntegral siComplete + putWord32be $ fromIntegral siDownloaded + putWord32be $ fromIntegral siIncomplete + + get = do + seeders <- getWord32be + downTimes <- getWord32be + leechers <- getWord32be + + return $ ScrapeInfo { + siComplete = fromIntegral seeders + , siDownloaded = fromIntegral downTimes + , siIncomplete = fromIntegral leechers + , siName = Nothing + } + {----------------------------------------------------------------------- Tracker -----------------------------------------------------------------------} -- cgit v1.2.3