summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-12-11 02:42:40 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-12-11 02:42:40 +0400
commit38c1f019d4fdb0fa776c7364d28a2cc96d570bb3 (patch)
tree8cfec635cdc0036d2439f516dd83550f2b613d38 /src
parent2defefa35ba45ca773160c8c4b01c73c61fc3fc0 (diff)
Do NOT ignore MetadataData payload in putExtendedMessage
Also fix -Wall suggestions.
Diffstat (limited to 'src')
-rw-r--r--src/Network/BitTorrent/Exchange/Message.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs
index 3fe3f1bf..335a9050 100644
--- a/src/Network/BitTorrent/Exchange/Message.hs
+++ b/src/Network/BitTorrent/Exchange/Message.hs
@@ -474,7 +474,7 @@ instance PeerMessage Transfer where
474 {-# INLINE envelop #-} 474 {-# INLINE envelop #-}
475 475
476 stats (Request _ ) = ByteStats (4 + 1) (3 * 4) 0 476 stats (Request _ ) = ByteStats (4 + 1) (3 * 4) 0
477 stats (Piece pi ) = ByteStats (4 + 1) (4 + 4 + blockSize pi) 0 477 stats (Piece p ) = ByteStats (4 + 1) (4 + 4 + blockSize p) 0
478 stats (Cancel _ ) = ByteStats (4 + 1) (3 * 4) 0 478 stats (Cancel _ ) = ByteStats (4 + 1) (3 * 4) 0
479 479
480{----------------------------------------------------------------------- 480{-----------------------------------------------------------------------
@@ -801,7 +801,7 @@ instance BEncode ExtendedMetadata where
801-- | Piece data bytes are omitted. 801-- | Piece data bytes are omitted.
802instance Pretty ExtendedMetadata where 802instance Pretty ExtendedMetadata where
803 pretty (MetadataRequest pix ) = "Request" <+> PP.int pix 803 pretty (MetadataRequest pix ) = "Request" <+> PP.int pix
804 pretty (MetadataData pi t) = "Data" <+> pretty pi <+> PP.int t 804 pretty (MetadataData p t) = "Data" <+> pretty p <+> PP.int t
805 pretty (MetadataReject pix ) = "Reject" <+> PP.int pix 805 pretty (MetadataReject pix ) = "Reject" <+> PP.int pix
806 pretty (MetadataUnknown bval ) = "Unknown" <+> ppBEncode bval 806 pretty (MetadataUnknown bval ) = "Unknown" <+> ppBEncode bval
807 807
@@ -814,8 +814,8 @@ instance PeerMessage ExtendedMetadata where
814 {-# INLINE requires #-} 814 {-# INLINE requires #-}
815 815
816 stats (MetadataRequest _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0 816 stats (MetadataRequest _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0
817 stats (MetadataData pi t) = ByteStats (4 + 1 + 1) {- ~ -} 41 $ 817 stats (MetadataData p _) = ByteStats (4 + 1 + 1) {- ~ -} 41 $
818 BS.length (Data.pieceData pi) 818 BS.length (Data.pieceData p)
819 stats (MetadataReject _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0 819 stats (MetadataReject _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0
820 stats (MetadataUnknown _) = ByteStats (4 + 1 + 1) {- ? -} 0 0 820 stats (MetadataUnknown _) = ByteStats (4 + 1 + 1) {- ? -} 0 0
821 821
@@ -868,7 +868,7 @@ getMetadata len
868 parseError reason = "unable to parse metadata message: " ++ reason 868 parseError reason = "unable to parse metadata message: " ++ reason
869 869
870 parseRes (BS.Fail _ _ _) = fail $ parseError "bdict: possible corrupted" 870 parseRes (BS.Fail _ _ _) = fail $ parseError "bdict: possible corrupted"
871 parseRes (BS.Partial c) = fail $ parseError "bdict: not enough bytes" 871 parseRes (BS.Partial _) = fail $ parseError "bdict: not enough bytes"
872 parseRes (BS.Done piece bvalueBS) 872 parseRes (BS.Done piece bvalueBS)
873 | BS.length piece > metadataPieceSize 873 | BS.length piece > metadataPieceSize
874 = fail "infodict piece: size exceeded limit" 874 = fail "infodict piece: size exceeded limit"
@@ -1157,6 +1157,6 @@ putExt mid lbs = do
1157-- NOTE: in contrast to getExtendedMessage this function put length 1157-- NOTE: in contrast to getExtendedMessage this function put length
1158-- and message id too! 1158-- and message id too!
1159putExtendedMessage :: Putter ExtendedMessage 1159putExtendedMessage :: Putter ExtendedMessage
1160putExtendedMessage (EHandshake hs) = putExt extHandshakeId (BE.encode hs) 1160putExtendedMessage (EHandshake hs) = putExt extHandshakeId $ BE.encode hs
1161putExtendedMessage (EMetadata mid msg) = putExt mid (BE.encode msg) 1161putExtendedMessage (EMetadata mid msg) = putExt mid $ putMetadata msg
1162putExtendedMessage (EUnknown mid bs) = putExt mid (BL.fromStrict bs) 1162putExtendedMessage (EUnknown mid bs) = putExt mid $ BL.fromStrict bs