diff options
author | joe <joe@jerkface.net> | 2015-03-29 01:06:34 -0400 |
---|---|---|
committer | joe <joe@jerkface.net> | 2015-03-29 01:06:34 -0400 |
commit | c88a76cb1c6ee7e54628b78a56f1a25415a39c30 (patch) | |
tree | 567ee2accc815e3f2a71c8f8434eefef82e60ef7 /src/Network/BitTorrent/Exchange/Message.hs | |
parent | e569586521be76e0f02137e01af9375d327d461c (diff) |
Updates to build against newer libraries:
* prettyclass instead of deprecated pretty-class
* use pPrint instead of pretty
* backported to iproute-1.2.11 (convenient for debian jessie)
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Message.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Message.hs | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index f8b76186..74232b47 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs | |||
@@ -115,7 +115,7 @@ import Data.IP | |||
115 | import Network | 115 | import Network |
116 | import Network.Socket hiding (KeepAlive) | 116 | import Network.Socket hiding (KeepAlive) |
117 | import Text.PrettyPrint as PP hiding ((<>)) | 117 | import Text.PrettyPrint as PP hiding ((<>)) |
118 | import Text.PrettyPrint.Class | 118 | import Text.PrettyPrint.HughesPJClass hiding ((<>),($$)) |
119 | 119 | ||
120 | import Data.Torrent hiding (Piece (..)) | 120 | import Data.Torrent hiding (Piece (..)) |
121 | import qualified Data.Torrent as P (Piece (..)) | 121 | import qualified Data.Torrent as P (Piece (..)) |
@@ -141,7 +141,7 @@ class Capabilities caps where | |||
141 | allowed :: Ext caps -> caps -> Bool | 141 | allowed :: Ext caps -> caps -> Bool |
142 | 142 | ||
143 | ppCaps :: Capabilities caps => Pretty (Ext caps) => caps -> Doc | 143 | ppCaps :: Capabilities caps => Pretty (Ext caps) => caps -> Doc |
144 | ppCaps = hcat . punctuate ", " . L.map pretty . fromCaps | 144 | ppCaps = hcat . punctuate ", " . L.map pPrint . fromCaps |
145 | 145 | ||
146 | {----------------------------------------------------------------------- | 146 | {----------------------------------------------------------------------- |
147 | -- Extensions | 147 | -- Extensions |
@@ -159,9 +159,9 @@ data Extension | |||
159 | 159 | ||
160 | -- | Full extension names, suitable for logging. | 160 | -- | Full extension names, suitable for logging. |
161 | instance Pretty Extension where | 161 | instance Pretty Extension where |
162 | pretty ExtDHT = "Distributed Hash Table Protocol" | 162 | pPrint ExtDHT = "Distributed Hash Table Protocol" |
163 | pretty ExtFast = "Fast Extension" | 163 | pPrint ExtFast = "Fast Extension" |
164 | pretty ExtExtended = "Extension Protocol" | 164 | pPrint ExtExtended = "Extension Protocol" |
165 | 165 | ||
166 | -- | Extension bitmask as specified by BEP 4. | 166 | -- | Extension bitmask as specified by BEP 4. |
167 | extMask :: Extension -> Word64 | 167 | extMask :: Extension -> Word64 |
@@ -180,8 +180,8 @@ newtype Caps = Caps Word64 | |||
180 | 180 | ||
181 | -- | Render set of extensions as comma separated list. | 181 | -- | Render set of extensions as comma separated list. |
182 | instance Pretty Caps where | 182 | instance Pretty Caps where |
183 | pretty = ppCaps | 183 | pPrint = ppCaps |
184 | {-# INLINE pretty #-} | 184 | {-# INLINE pPrint #-} |
185 | 185 | ||
186 | -- | The empty set. | 186 | -- | The empty set. |
187 | instance Default Caps where | 187 | instance Default Caps where |
@@ -235,7 +235,7 @@ instance Show ProtocolName where | |||
235 | show (ProtocolName bs) = show bs | 235 | show (ProtocolName bs) = show bs |
236 | 236 | ||
237 | instance Pretty ProtocolName where | 237 | instance Pretty ProtocolName where |
238 | pretty (ProtocolName bs) = PP.text $ BC.unpack bs | 238 | pPrint (ProtocolName bs) = PP.text $ BC.unpack bs |
239 | 239 | ||
240 | instance IsString ProtocolName where | 240 | instance IsString ProtocolName where |
241 | fromString str | 241 | fromString str |
@@ -287,10 +287,10 @@ instance Serialize Handshake where | |||
287 | 287 | ||
288 | -- | Show handshake protocol string, caps and fingerprint. | 288 | -- | Show handshake protocol string, caps and fingerprint. |
289 | instance Pretty Handshake where | 289 | instance Pretty Handshake where |
290 | pretty Handshake {..} | 290 | pPrint Handshake {..} |
291 | = pretty hsProtocol $$ | 291 | = pPrint hsProtocol $$ |
292 | pretty hsReserved $$ | 292 | pPrint hsReserved $$ |
293 | pretty (fingerprint hsPeerId) | 293 | pPrint (fingerprint hsPeerId) |
294 | 294 | ||
295 | -- | Get handshake message size in bytes from the length of protocol | 295 | -- | Get handshake message size in bytes from the length of protocol |
296 | -- string. | 296 | -- string. |
@@ -334,7 +334,7 @@ data ByteStats = ByteStats | |||
334 | } deriving Show | 334 | } deriving Show |
335 | 335 | ||
336 | instance Pretty ByteStats where | 336 | instance Pretty ByteStats where |
337 | pretty s @ ByteStats {..} = fsep | 337 | pPrint s @ ByteStats {..} = fsep |
338 | [ PP.int overhead, "overhead" | 338 | [ PP.int overhead, "overhead" |
339 | , PP.int control, "control" | 339 | , PP.int control, "control" |
340 | , PP.int payload, "payload" | 340 | , PP.int payload, "payload" |
@@ -408,10 +408,10 @@ data StatusUpdate | |||
408 | deriving (Show, Eq, Ord, Typeable) | 408 | deriving (Show, Eq, Ord, Typeable) |
409 | 409 | ||
410 | instance Pretty StatusUpdate where | 410 | instance Pretty StatusUpdate where |
411 | pretty (Choking False) = "not choking" | 411 | pPrint (Choking False) = "not choking" |
412 | pretty (Choking True ) = "choking" | 412 | pPrint (Choking True ) = "choking" |
413 | pretty (Interested False) = "not interested" | 413 | pPrint (Interested False) = "not interested" |
414 | pretty (Interested True ) = "interested" | 414 | pPrint (Interested True ) = "interested" |
415 | 415 | ||
416 | instance PeerMessage StatusUpdate where | 416 | instance PeerMessage StatusUpdate where |
417 | envelop _ = Status | 417 | envelop _ = Status |
@@ -439,8 +439,8 @@ data Available = | |||
439 | deriving (Show, Eq) | 439 | deriving (Show, Eq) |
440 | 440 | ||
441 | instance Pretty Available where | 441 | instance Pretty Available where |
442 | pretty (Have ix ) = "Have" <+> int ix | 442 | pPrint (Have ix ) = "Have" <+> int ix |
443 | pretty (Bitfield _ ) = "Bitfield" | 443 | pPrint (Bitfield _ ) = "Bitfield" |
444 | 444 | ||
445 | instance PeerMessage Available where | 445 | instance PeerMessage Available where |
446 | envelop _ = Available | 446 | envelop _ = Available |
@@ -472,9 +472,9 @@ data Transfer | |||
472 | deriving (Show, Eq) | 472 | deriving (Show, Eq) |
473 | 473 | ||
474 | instance Pretty Transfer where | 474 | instance Pretty Transfer where |
475 | pretty (Request ix ) = "Request" <+> pretty ix | 475 | pPrint (Request ix ) = "Request" <+> pPrint ix |
476 | pretty (Piece blk) = "Piece" <+> pretty blk | 476 | pPrint (Piece blk) = "Piece" <+> pPrint blk |
477 | pretty (Cancel i ) = "Cancel" <+> pretty i | 477 | pPrint (Cancel i ) = "Cancel" <+> pPrint i |
478 | 478 | ||
479 | instance PeerMessage Transfer where | 479 | instance PeerMessage Transfer where |
480 | envelop _ = Transfer | 480 | envelop _ = Transfer |
@@ -519,11 +519,11 @@ data FastMessage = | |||
519 | deriving (Show, Eq) | 519 | deriving (Show, Eq) |
520 | 520 | ||
521 | instance Pretty FastMessage where | 521 | instance Pretty FastMessage where |
522 | pretty (HaveAll ) = "Have all" | 522 | pPrint (HaveAll ) = "Have all" |
523 | pretty (HaveNone ) = "Have none" | 523 | pPrint (HaveNone ) = "Have none" |
524 | pretty (SuggestPiece pix) = "Suggest" <+> int pix | 524 | pPrint (SuggestPiece pix) = "Suggest" <+> int pix |
525 | pretty (RejectRequest bix) = "Reject" <+> pretty bix | 525 | pPrint (RejectRequest bix) = "Reject" <+> pPrint bix |
526 | pretty (AllowedFast pix) = "Allowed fast" <+> int pix | 526 | pPrint (AllowedFast pix) = "Allowed fast" <+> int pix |
527 | 527 | ||
528 | instance PeerMessage FastMessage where | 528 | instance PeerMessage FastMessage where |
529 | envelop _ = Fast | 529 | envelop _ = Fast |
@@ -556,7 +556,7 @@ instance IsString ExtendedExtension where | |||
556 | msg = "fromString: could not parse ExtendedExtension" | 556 | msg = "fromString: could not parse ExtendedExtension" |
557 | 557 | ||
558 | instance Pretty ExtendedExtension where | 558 | instance Pretty ExtendedExtension where |
559 | pretty ExtMetadata = "Extension for Peers to Send Metadata Files" | 559 | pPrint ExtMetadata = "Extension for Peers to Send Metadata Files" |
560 | 560 | ||
561 | fromKey :: BKey -> Maybe ExtendedExtension | 561 | fromKey :: BKey -> Maybe ExtendedExtension |
562 | fromKey "ut_metadata" = Just ExtMetadata | 562 | fromKey "ut_metadata" = Just ExtMetadata |
@@ -582,8 +582,8 @@ newtype ExtendedCaps = ExtendedCaps { extendedCaps :: ExtendedMap } | |||
582 | deriving (Show, Eq) | 582 | deriving (Show, Eq) |
583 | 583 | ||
584 | instance Pretty ExtendedCaps where | 584 | instance Pretty ExtendedCaps where |
585 | pretty = ppCaps | 585 | pPrint = ppCaps |
586 | {-# INLINE pretty #-} | 586 | {-# INLINE pPrint #-} |
587 | 587 | ||
588 | -- | The empty set. | 588 | -- | The empty set. |
589 | instance Default ExtendedCaps where | 589 | instance Default ExtendedCaps where |
@@ -738,7 +738,7 @@ getYourIp f = | |||
738 | _ -> fail "" | 738 | _ -> fail "" |
739 | 739 | ||
740 | instance Pretty ExtendedHandshake where | 740 | instance Pretty ExtendedHandshake where |
741 | pretty = PP.text . show | 741 | pPrint = PP.text . show |
742 | 742 | ||
743 | -- | NOTE: Approximated 'stats'. | 743 | -- | NOTE: Approximated 'stats'. |
744 | instance PeerMessage ExtendedHandshake where | 744 | instance PeerMessage ExtendedHandshake where |
@@ -760,7 +760,7 @@ nullExtendedHandshake caps = ExtendedHandshake | |||
760 | , ehsMetadataSize = Nothing | 760 | , ehsMetadataSize = Nothing |
761 | , ehsPort = Nothing | 761 | , ehsPort = Nothing |
762 | , ehsQueueLength = Just defaultQueueLength | 762 | , ehsQueueLength = Just defaultQueueLength |
763 | , ehsVersion = Just $ T.pack $ render $ pretty libFingerprint | 763 | , ehsVersion = Just $ T.pack $ render $ pPrint libFingerprint |
764 | , ehsYourIp = Nothing | 764 | , ehsYourIp = Nothing |
765 | } | 765 | } |
766 | 766 | ||
@@ -843,10 +843,10 @@ instance BEncode ExtendedMetadata where | |||
843 | 843 | ||
844 | -- | Piece data bytes are omitted. | 844 | -- | Piece data bytes are omitted. |
845 | instance Pretty ExtendedMetadata where | 845 | instance Pretty ExtendedMetadata where |
846 | pretty (MetadataRequest pix ) = "Request" <+> PP.int pix | 846 | pPrint (MetadataRequest pix ) = "Request" <+> PP.int pix |
847 | pretty (MetadataData p t) = "Data" <+> pretty p <+> PP.int t | 847 | pPrint (MetadataData p t) = "Data" <+> pPrint p <+> PP.int t |
848 | pretty (MetadataReject pix ) = "Reject" <+> PP.int pix | 848 | pPrint (MetadataReject pix ) = "Reject" <+> PP.int pix |
849 | pretty (MetadataUnknown bval ) = "Unknown" <+> ppBEncode bval | 849 | pPrint (MetadataUnknown bval ) = "Unknown" <+> ppBEncode bval |
850 | 850 | ||
851 | -- | NOTE: Approximated 'stats'. | 851 | -- | NOTE: Approximated 'stats'. |
852 | instance PeerMessage ExtendedMetadata where | 852 | instance PeerMessage ExtendedMetadata where |
@@ -957,9 +957,9 @@ data ExtendedMessage | |||
957 | deriving (Show, Eq, Typeable) | 957 | deriving (Show, Eq, Typeable) |
958 | 958 | ||
959 | instance Pretty ExtendedMessage where | 959 | instance Pretty ExtendedMessage where |
960 | pretty (EHandshake ehs) = pretty ehs | 960 | pPrint (EHandshake ehs) = pPrint ehs |
961 | pretty (EMetadata _ msg) = "Metadata" <+> pretty msg | 961 | pPrint (EMetadata _ msg) = "Metadata" <+> pPrint msg |
962 | pretty (EUnknown mid _ ) = "Unknown" <+> PP.text (show mid) | 962 | pPrint (EUnknown mid _ ) = "Unknown" <+> PP.text (show mid) |
963 | 963 | ||
964 | instance PeerMessage ExtendedMessage where | 964 | instance PeerMessage ExtendedMessage where |
965 | envelop _ = Extended | 965 | envelop _ = Extended |
@@ -1010,13 +1010,13 @@ instance Default Message where | |||
1010 | 1010 | ||
1011 | -- | Payload bytes are omitted. | 1011 | -- | Payload bytes are omitted. |
1012 | instance Pretty Message where | 1012 | instance Pretty Message where |
1013 | pretty (KeepAlive ) = "Keep alive" | 1013 | pPrint (KeepAlive ) = "Keep alive" |
1014 | pretty (Status m) = "Status" <+> pretty m | 1014 | pPrint (Status m) = "Status" <+> pPrint m |
1015 | pretty (Available m) = pretty m | 1015 | pPrint (Available m) = pPrint m |
1016 | pretty (Transfer m) = pretty m | 1016 | pPrint (Transfer m) = pPrint m |
1017 | pretty (Port p) = "Port" <+> int (fromEnum p) | 1017 | pPrint (Port p) = "Port" <+> int (fromEnum p) |
1018 | pretty (Fast m) = pretty m | 1018 | pPrint (Fast m) = pPrint m |
1019 | pretty (Extended m) = pretty m | 1019 | pPrint (Extended m) = pPrint m |
1020 | 1020 | ||
1021 | instance PeerMessage Message where | 1021 | instance PeerMessage Message where |
1022 | envelop _ = id | 1022 | envelop _ = id |