summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/PeerWire/Message.hs
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-24 21:57:57 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-24 21:57:57 +0400
commite94425b9c4764ec545284e06f1046e6601ec9ea7 (patch)
treef1dd866e3c9f44d67503c2e5affb917fb946dc70 /src/Network/BitTorrent/PeerWire/Message.hs
parenta7c82906934d7e640cda5c26448ce4fa232d2b46 (diff)
+ Add message and block pprint for logging.
Diffstat (limited to 'src/Network/BitTorrent/PeerWire/Message.hs')
-rw-r--r--src/Network/BitTorrent/PeerWire/Message.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/PeerWire/Message.hs b/src/Network/BitTorrent/PeerWire/Message.hs
index 650e0082..c98c9808 100644
--- a/src/Network/BitTorrent/PeerWire/Message.hs
+++ b/src/Network/BitTorrent/PeerWire/Message.hs
@@ -1,5 +1,6 @@
1module Network.BitTorrent.PeerWire.Message 1module Network.BitTorrent.PeerWire.Message
2 ( Message(..) 2 ( Message(..)
3 , ppMessage
3 ) where 4 ) where
4 5
5import Control.Applicative 6import Control.Applicative
@@ -129,3 +130,13 @@ instance Serialize Message where
129 put (SuggestPiece pix) = putInt 5 >> putWord8 0x0D >> putInt pix 130 put (SuggestPiece pix) = putInt 5 >> putWord8 0x0D >> putInt pix
130 put (RejectRequest ix) = putInt 13 >> putWord8 0x10 >> put ix 131 put (RejectRequest ix) = putInt 13 >> putWord8 0x10 >> put ix
131 put (AllowedFast ix) = putInt 5 >> putWord8 0x11 >> putInt ix 132 put (AllowedFast ix) = putInt 5 >> putWord8 0x11 >> putInt ix
133
134
135-- | Compact output for logging: only useful information but not payload bytes.
136ppMessage :: Message -> String
137ppMessage (Bitfield _) = "Bitfield "
138ppMessage (Piece blk) = "Piece " ++ ppBlock blk
139ppMessage (Cancel ix) = "Cancel " ++ ppBlockIx ix
140ppMessage (SuggestPiece pix) = "Suggest" ++ show pix
141ppMessage (RejectRequest ix) = "Reject" ++ ppBlockIx ix
142ppMessage msg = show msg \ No newline at end of file