From 60d21cfefd82995265c00df9136b19fefa8910ac Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Thu, 28 Nov 2013 15:00:13 +0400 Subject: Get rid of the urlencoded package * It uses slow String's instead of Text. * It does not allow to encode infohash and peer ids properly. * It does not provide API for query string parsing. So it is better to use http-types package. --- src/Network/BitTorrent/Core/PeerId.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/Network/BitTorrent/Core') diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs index a2b03e92..f5a40f29 100644 --- a/src/Network/BitTorrent/Core/PeerId.hs +++ b/src/Network/BitTorrent/Core/PeerId.hs @@ -46,12 +46,14 @@ import Data.List as L import Data.List.Split as L import Data.Maybe (fromMaybe, catMaybes) import Data.Monoid +import Data.Hashable import Data.Serialize as S import Data.String import Data.Time.Clock (getCurrentTime) import Data.Time.Format (formatTime) import Data.URLEncoded import Data.Version (Version(Version), versionBranch) +import Network.HTTP.Types.QueryLike import System.Entropy (getEntropy) import System.Locale (defaultTimeLocale) import Text.PrettyPrint hiding ((<>)) @@ -70,12 +72,17 @@ newtype PeerId = PeerId { getPeerId :: ByteString } peerIdLen :: Int peerIdLen = 20 +instance Hashable PeerId where + hash = hash . getPeerId + {-# INLINE hash #-} + instance Serialize PeerId where put = putByteString . getPeerId get = PeerId <$> getBytes peerIdLen -instance URLShow PeerId where - urlShow = BC.unpack . getPeerId +instance QueryValueLike PeerId where + toQueryValue (PeerId pid) = Just pid + {-# INLINE toQueryValue #-} instance IsString PeerId where fromString str -- cgit v1.2.3