summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/PeerWire/Message.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/PeerWire/Message.hs')
-rw-r--r--src/Network/BitTorrent/PeerWire/Message.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/PeerWire/Message.hs b/src/Network/BitTorrent/PeerWire/Message.hs
index 6515fdf2..3895ed5f 100644
--- a/src/Network/BitTorrent/PeerWire/Message.hs
+++ b/src/Network/BitTorrent/PeerWire/Message.hs
@@ -7,6 +7,7 @@ module Network.BitTorrent.PeerWire.Message
7 7
8import Control.Applicative 8import Control.Applicative
9import qualified Data.ByteString as B 9import qualified Data.ByteString as B
10import qualified Data.ByteString.Lazy as Lazy
10import Data.Serialize 11import Data.Serialize
11import Text.PrettyPrint 12import Text.PrettyPrint
12import Network 13import Network
@@ -91,7 +92,7 @@ instance Serialize Message where
91 0x02 -> return Interested 92 0x02 -> return Interested
92 0x03 -> return NotInterested 93 0x03 -> return NotInterested
93 0x04 -> Have <$> getInt 94 0x04 -> Have <$> getInt
94 0x05 -> Bitfield <$> getBitfield (pred len) 95 0x05 -> (Bitfield . fromBitmap) <$> getByteString (pred len)
95 0x06 -> Request <$> get 96 0x06 -> Request <$> get
96 0x07 -> Piece <$> getBlock (len - 9) 97 0x07 -> Piece <$> getBlock (len - 9)
97 0x08 -> Cancel <$> get 98 0x08 -> Cancel <$> get
@@ -118,8 +119,9 @@ instance Serialize Message where
118 put Interested = putInt 1 >> putWord8 0x02 119 put Interested = putInt 1 >> putWord8 0x02
119 put NotInterested = putInt 1 >> putWord8 0x03 120 put NotInterested = putInt 1 >> putWord8 0x03
120 put (Have i) = putInt 5 >> putWord8 0x04 >> putInt i 121 put (Have i) = putInt 5 >> putWord8 0x04 >> putInt i
121 put (Bitfield b) = putInt l >> putWord8 0x05 >> putBitfield b 122 put (Bitfield bf) = putInt l >> putWord8 0x05 >> putLazyByteString b
122 where l = succ (bitfieldByteCount b) 123 where b = toBitmap bf
124 l = succ (fromIntegral (Lazy.length b))
123 {-# INLINE l #-} 125 {-# INLINE l #-}
124 put (Request blk) = putInt 13 >> putWord8 0x06 >> put blk 126 put (Request blk) = putInt 13 >> putWord8 0x06 >> put blk
125 put (Piece blk) = putInt l >> putWord8 0x07 >> putBlock 127 put (Piece blk) = putInt l >> putWord8 0x07 >> putBlock