summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Core
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-11-28 15:00:13 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-11-28 15:00:13 +0400
commit60d21cfefd82995265c00df9136b19fefa8910ac (patch)
tree4b6392f3dd30d9de981916dc5bd5e3ec5d20cbd0 /src/Network/BitTorrent/Core
parentfc3b090ac8dceefd315e6ca16f12d32dca11f580 (diff)
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.
Diffstat (limited to 'src/Network/BitTorrent/Core')
-rw-r--r--src/Network/BitTorrent/Core/PeerId.hs11
1 files changed, 9 insertions, 2 deletions
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
46import Data.List.Split as L 46import Data.List.Split as L
47import Data.Maybe (fromMaybe, catMaybes) 47import Data.Maybe (fromMaybe, catMaybes)
48import Data.Monoid 48import Data.Monoid
49import Data.Hashable
49import Data.Serialize as S 50import Data.Serialize as S
50import Data.String 51import Data.String
51import Data.Time.Clock (getCurrentTime) 52import Data.Time.Clock (getCurrentTime)
52import Data.Time.Format (formatTime) 53import Data.Time.Format (formatTime)
53import Data.URLEncoded 54import Data.URLEncoded
54import Data.Version (Version(Version), versionBranch) 55import Data.Version (Version(Version), versionBranch)
56import Network.HTTP.Types.QueryLike
55import System.Entropy (getEntropy) 57import System.Entropy (getEntropy)
56import System.Locale (defaultTimeLocale) 58import System.Locale (defaultTimeLocale)
57import Text.PrettyPrint hiding ((<>)) 59import Text.PrettyPrint hiding ((<>))
@@ -70,12 +72,17 @@ newtype PeerId = PeerId { getPeerId :: ByteString }
70peerIdLen :: Int 72peerIdLen :: Int
71peerIdLen = 20 73peerIdLen = 20
72 74
75instance Hashable PeerId where
76 hash = hash . getPeerId
77 {-# INLINE hash #-}
78
73instance Serialize PeerId where 79instance Serialize PeerId where
74 put = putByteString . getPeerId 80 put = putByteString . getPeerId
75 get = PeerId <$> getBytes peerIdLen 81 get = PeerId <$> getBytes peerIdLen
76 82
77instance URLShow PeerId where 83instance QueryValueLike PeerId where
78 urlShow = BC.unpack . getPeerId 84 toQueryValue (PeerId pid) = Just pid
85 {-# INLINE toQueryValue #-}
79 86
80instance IsString PeerId where 87instance IsString PeerId where
81 fromString str 88 fromString str