diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-20 21:12:46 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-20 21:12:46 +0400 |
commit | 4693ed53ec5cdbf0b2fa993d169c96e45f2dce91 (patch) | |
tree | b73e40e1279b72e36bb235003f30ea4d89746b81 /src/Network | |
parent | 17be47e8f10907ff1479a83595ef5fb920b6acbd (diff) | |
parent | 268a6e1b161ffae29c32a0a5cbc5b62158d67956 (diff) |
Merge branch 'dev' of https://github.com/DanielG/bittorrent
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Message.hs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index fb3a5c82..d0b6c19d 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs | |||
@@ -115,7 +115,7 @@ import Text.PrettyPrint.Class | |||
115 | 115 | ||
116 | import Data.Torrent.Bitfield | 116 | import Data.Torrent.Bitfield |
117 | import Data.Torrent.InfoHash | 117 | import Data.Torrent.InfoHash |
118 | import qualified Data.Torrent.Piece as Data | 118 | import qualified Data.Torrent.Piece as P |
119 | import Network.BitTorrent.Core | 119 | import Network.BitTorrent.Core |
120 | import Network.BitTorrent.Exchange.Block | 120 | import Network.BitTorrent.Exchange.Block |
121 | 121 | ||
@@ -744,7 +744,7 @@ data ExtendedMetadata | |||
744 | -- message. | 744 | -- message. |
745 | | MetadataData | 745 | | MetadataData |
746 | { -- | A piece of 'Data.Torrent.InfoDict'. | 746 | { -- | A piece of 'Data.Torrent.InfoDict'. |
747 | piece :: Data.Piece BS.ByteString | 747 | piece :: P.Piece BS.ByteString |
748 | 748 | ||
749 | -- | This key has the same semantics as the 'ehsMetadataSize' in | 749 | -- | This key has the same semantics as the 'ehsMetadataSize' in |
750 | -- the 'ExtendedHandshake' — it is size of the torrent info | 750 | -- the 'ExtendedHandshake' — it is size of the torrent info |
@@ -780,7 +780,7 @@ instance BEncode ExtendedMetadata where | |||
780 | msg_type_key .=! (0 :: MetadataId) | 780 | msg_type_key .=! (0 :: MetadataId) |
781 | .: piece_key .=! pix | 781 | .: piece_key .=! pix |
782 | .: endDict | 782 | .: endDict |
783 | toBEncode (MetadataData (Data.Piece pix _) totalSize) = toDict $ | 783 | toBEncode (MetadataData (P.Piece pix _) totalSize) = toDict $ |
784 | msg_type_key .=! (1 :: MetadataId) | 784 | msg_type_key .=! (1 :: MetadataId) |
785 | .: piece_key .=! pix | 785 | .: piece_key .=! pix |
786 | .: total_size_key .=! totalSize | 786 | .: total_size_key .=! totalSize |
@@ -799,7 +799,7 @@ instance BEncode ExtendedMetadata where | |||
799 | 2 -> MetadataReject <$>! piece_key | 799 | 2 -> MetadataReject <$>! piece_key |
800 | _ -> pure (MetadataUnknown bval) | 800 | _ -> pure (MetadataUnknown bval) |
801 | where | 801 | where |
802 | metadataData pix s = MetadataData (Data.Piece pix BS.empty) s | 802 | metadataData pix s = MetadataData (P.Piece pix BS.empty) s |
803 | 803 | ||
804 | -- | Piece data bytes are omitted. | 804 | -- | Piece data bytes are omitted. |
805 | instance Pretty ExtendedMetadata where | 805 | instance Pretty ExtendedMetadata where |
@@ -818,7 +818,7 @@ instance PeerMessage ExtendedMetadata where | |||
818 | 818 | ||
819 | stats (MetadataRequest _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0 | 819 | stats (MetadataRequest _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0 |
820 | stats (MetadataData p _) = ByteStats (4 + 1 + 1) {- ~ -} 41 $ | 820 | stats (MetadataData p _) = ByteStats (4 + 1 + 1) {- ~ -} 41 $ |
821 | BS.length (Data.pieceData p) | 821 | BS.length (P.pieceData p) |
822 | stats (MetadataReject _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0 | 822 | stats (MetadataReject _) = ByteStats (4 + 1 + 1) {- ~ -} 25 0 |
823 | stats (MetadataUnknown _) = ByteStats (4 + 1 + 1) {- ? -} 0 0 | 823 | stats (MetadataUnknown _) = ByteStats (4 + 1 + 1) {- ? -} 0 0 |
824 | 824 | ||
@@ -836,12 +836,12 @@ checkPiece :: ExtendedMetadata -> Bool | |||
836 | checkPiece = undefined -- FIXME | 836 | checkPiece = undefined -- FIXME |
837 | 837 | ||
838 | setMetadataPayload :: BS.ByteString -> ExtendedMetadata -> ExtendedMetadata | 838 | setMetadataPayload :: BS.ByteString -> ExtendedMetadata -> ExtendedMetadata |
839 | setMetadataPayload bs (MetadataData (Data.Piece pix _) t) = | 839 | setMetadataPayload bs (MetadataData (P.Piece pix _) t) = |
840 | MetadataData (Data.Piece pix bs) t | 840 | MetadataData (P.Piece pix bs) t |
841 | setMetadataPayload _ msg = msg | 841 | setMetadataPayload _ msg = msg |
842 | 842 | ||
843 | getMetadataPayload :: ExtendedMetadata -> Maybe BS.ByteString | 843 | getMetadataPayload :: ExtendedMetadata -> Maybe BS.ByteString |
844 | getMetadataPayload (MetadataData (Data.Piece _ bs) _) = Just bs | 844 | getMetadataPayload (MetadataData (P.Piece _ bs) _) = Just bs |
845 | getMetadataPayload _ = Nothing | 845 | getMetadataPayload _ = Nothing |
846 | 846 | ||
847 | -- | Metadata BDict usually contain only 'msg_type_key', 'piece_key' | 847 | -- | Metadata BDict usually contain only 'msg_type_key', 'piece_key' |