summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Address.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Address.hs')
-rw-r--r--src/Network/BitTorrent/Address.hs48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/Network/BitTorrent/Address.hs b/src/Network/BitTorrent/Address.hs
index eeb04c74..3159fab0 100644
--- a/src/Network/BitTorrent/Address.hs
+++ b/src/Network/BitTorrent/Address.hs
@@ -110,7 +110,7 @@ import Text.Read (readMaybe)
110import Network.HTTP.Types.QueryLike 110import Network.HTTP.Types.QueryLike
111import Network.Socket 111import Network.Socket
112import Text.PrettyPrint as PP hiding ((<>)) 112import Text.PrettyPrint as PP hiding ((<>))
113import Text.PrettyPrint.Class 113import Text.PrettyPrint.HughesPJClass hiding ((<>),($$))
114import System.Locale (defaultTimeLocale) 114import System.Locale (defaultTimeLocale)
115import System.Entropy 115import System.Entropy
116 116
@@ -121,7 +121,7 @@ import System.Entropy
121-----------------------------------------------------------------------} 121-----------------------------------------------------------------------}
122 122
123instance Pretty UTCTime where 123instance Pretty UTCTime where
124 pretty = PP.text . show 124 pPrint = PP.text . show
125 125
126class (Eq a, Serialize a, Typeable a, Hashable a, Pretty a) 126class (Eq a, Serialize a, Typeable a, Hashable a, Pretty a)
127 => Address a where 127 => Address a where
@@ -216,7 +216,7 @@ instance IsString PeerId where
216 bs = fromString str 216 bs = fromString str
217 217
218instance Pretty PeerId where 218instance Pretty PeerId where
219 pretty = text . BC.unpack . getPeerId 219 pPrint = text . BC.unpack . getPeerId
220 220
221instance Convertible BS.ByteString PeerId where 221instance Convertible BS.ByteString PeerId where
222 safeConvert bs 222 safeConvert bs
@@ -373,8 +373,8 @@ instance Hashable PortNumber where
373 {-# INLINE hashWithSalt #-} 373 {-# INLINE hashWithSalt #-}
374 374
375instance Pretty PortNumber where 375instance Pretty PortNumber where
376 pretty = PP.int . fromEnum 376 pPrint = PP.int . fromEnum
377 {-# INLINE pretty #-} 377 {-# INLINE pPrint #-}
378 378
379{----------------------------------------------------------------------- 379{-----------------------------------------------------------------------
380-- IP addr 380-- IP addr
@@ -451,16 +451,16 @@ instance Serialize IPv6 where
451 get = fromHostAddress6 <$> get 451 get = fromHostAddress6 <$> get
452 452
453instance Pretty IPv4 where 453instance Pretty IPv4 where
454 pretty = PP.text . show 454 pPrint = PP.text . show
455 {-# INLINE pretty #-} 455 {-# INLINE pPrint #-}
456 456
457instance Pretty IPv6 where 457instance Pretty IPv6 where
458 pretty = PP.text . show 458 pPrint = PP.text . show
459 {-# INLINE pretty #-} 459 {-# INLINE pPrint #-}
460 460
461instance Pretty IP where 461instance Pretty IP where
462 pretty = PP.text . show 462 pPrint = PP.text . show
463 {-# INLINE pretty #-} 463 {-# INLINE pPrint #-}
464 464
465instance Hashable IPv4 where 465instance Hashable IPv4 where
466 hashWithSalt = hashUsing toHostAddress 466 hashWithSalt = hashUsing toHostAddress
@@ -569,11 +569,11 @@ instance IsString (PeerAddr IP) where
569-- | fingerprint + "at" + dotted.host.inet.addr:port 569-- | fingerprint + "at" + dotted.host.inet.addr:port
570-- TODO: instances for IPv6, HostName 570-- TODO: instances for IPv6, HostName
571instance Pretty a => Pretty (PeerAddr a) where 571instance Pretty a => Pretty (PeerAddr a) where
572 pretty PeerAddr {..} 572 pPrint PeerAddr {..}
573 | Just pid <- peerId = pretty (fingerprint pid) <+> "at" <+> paddr 573 | Just pid <- peerId = pPrint (fingerprint pid) <+> "at" <+> paddr
574 | otherwise = paddr 574 | otherwise = paddr
575 where 575 where
576 paddr = pretty peerHost <> ":" <> text (show peerPort) 576 paddr = pPrint peerHost <> ":" <> text (show peerPort)
577 577
578instance Hashable a => Hashable (PeerAddr a) where 578instance Hashable a => Hashable (PeerAddr a) where
579 hashWithSalt s PeerAddr {..} = 579 hashWithSalt s PeerAddr {..} =
@@ -649,7 +649,7 @@ instance IsString NodeId where
649 649
650-- | base16 encoded. 650-- | base16 encoded.
651instance Pretty NodeId where 651instance Pretty NodeId where
652 pretty (NodeId nid) = PP.text $ BC.unpack $ Base16.encode nid 652 pPrint (NodeId nid) = PP.text $ BC.unpack $ Base16.encode nid
653 653
654-- | Test if the nth bit is set. 654-- | Test if the nth bit is set.
655testIdBit :: NodeId -> Word -> Bool 655testIdBit :: NodeId -> Word -> Bool
@@ -675,7 +675,7 @@ newtype NodeDistance = NodeDistance BS.ByteString
675 deriving (Eq, Ord) 675 deriving (Eq, Ord)
676 676
677instance Pretty NodeDistance where 677instance Pretty NodeDistance where
678 pretty (NodeDistance bs) = foldMap bitseq $ BS.unpack bs 678 pPrint (NodeDistance bs) = foldMap bitseq $ BS.unpack bs
679 where 679 where
680 listBits w = L.map (testBit w) (L.reverse [0..bitSize w - 1]) 680 listBits w = L.map (testBit w) (L.reverse [0..bitSize w - 1])
681 bitseq = foldMap (int . fromEnum) . listBits 681 bitseq = foldMap (int . fromEnum) . listBits
@@ -721,7 +721,7 @@ instance Hashable a => Hashable (NodeAddr a) where
721 {-# INLINE hashWithSalt #-} 721 {-# INLINE hashWithSalt #-}
722 722
723instance Pretty ip => Pretty (NodeAddr ip) where 723instance Pretty ip => Pretty (NodeAddr ip) where
724 pretty NodeAddr {..} = pretty nodeHost <> ":" <> pretty nodePort 724 pPrint NodeAddr {..} = pPrint nodeHost <> ":" <> pPrint nodePort
725 725
726-- | Example: 726-- | Example:
727-- 727--
@@ -755,10 +755,10 @@ instance Serialize a => Serialize (NodeInfo a) where
755 put NodeInfo {..} = put nodeId >> put nodeAddr 755 put NodeInfo {..} = put nodeId >> put nodeAddr
756 756
757instance Pretty ip => Pretty (NodeInfo ip) where 757instance Pretty ip => Pretty (NodeInfo ip) where
758 pretty NodeInfo {..} = pretty nodeId <> "@(" <> pretty nodeAddr <> ")" 758 pPrint NodeInfo {..} = pPrint nodeId <> "@(" <> pPrint nodeAddr <> ")"
759 759
760instance Pretty ip => Pretty [NodeInfo ip] where 760instance Pretty ip => Pretty [NodeInfo ip] where
761 pretty = PP.vcat . PP.punctuate "," . L.map pretty 761 pPrint = PP.vcat . PP.punctuate "," . L.map pPrint
762 762
763-- | Order by closeness: nearest nodes first. 763-- | Order by closeness: nearest nodes first.
764rank :: Eq ip => NodeId -> [NodeInfo ip] -> [NodeInfo ip] 764rank :: Eq ip => NodeId -> [NodeInfo ip] -> [NodeInfo ip]
@@ -952,9 +952,9 @@ instance IsString Software where
952 alist = L.map mk [minBound..maxBound] 952 alist = L.map mk [minBound..maxBound]
953 mk x = (L.tail $ show x, x) 953 mk x = (L.tail $ show x, x)
954 954
955-- | Example: @pretty 'IBitLet' == \"IBitLet\"@ 955-- | Example: @pPrint 'IBitLet' == \"IBitLet\"@
956instance Pretty Software where 956instance Pretty Software where
957 pretty = text . L.tail . show 957 pPrint = text . L.tail . show
958 958
959-- | Just the '0' version. 959-- | Just the '0' version.
960instance Default Version where 960instance Default Version where
@@ -972,7 +972,7 @@ instance IsString Version where
972 chunkNums = sequence . L.map readMaybe . L.linesBy ('.' ==) 972 chunkNums = sequence . L.map readMaybe . L.linesBy ('.' ==)
973 973
974instance Pretty Version where 974instance Pretty Version where
975 pretty = text . showVersion 975 pPrint = text . showVersion
976 976
977-- | The all sensible infomation that can be obtained from a peer 977-- | The all sensible infomation that can be obtained from a peer
978-- identifier or torrent /createdBy/ field. 978-- identifier or torrent /createdBy/ field.
@@ -993,7 +993,7 @@ instance IsString Fingerprint where
993 (impl, _ver) = L.span ((/=) '-') str 993 (impl, _ver) = L.span ((/=) '-') str
994 994
995instance Pretty Fingerprint where 995instance Pretty Fingerprint where
996 pretty (Fingerprint s v) = pretty s <+> "version" <+> pretty v 996 pPrint (Fingerprint s v) = pPrint s <+> "version" <+> pPrint v
997 997
998-- | Fingerprint of this (the bittorrent library) package. Normally, 998-- | Fingerprint of this (the bittorrent library) package. Normally,
999-- applications should introduce its own fingerprints, otherwise they 999-- applications should introduce its own fingerprints, otherwise they
@@ -1005,7 +1005,7 @@ libFingerprint = Fingerprint IlibHSbittorrent version
1005-- | HTTP user agent of this (the bittorrent library) package. Can be 1005-- | HTTP user agent of this (the bittorrent library) package. Can be
1006-- used in HTTP tracker requests. 1006-- used in HTTP tracker requests.
1007libUserAgent :: String 1007libUserAgent :: String
1008libUserAgent = render (pretty IlibHSbittorrent <> "/" <> pretty version) 1008libUserAgent = render (pPrint IlibHSbittorrent <> "/" <> pPrint version)
1009 1009
1010{----------------------------------------------------------------------- 1010{-----------------------------------------------------------------------
1011-- For torrent file 1011-- For torrent file