summaryrefslogtreecommitdiff
path: root/src/Network/Torrent/PeerID.hs
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-07 05:11:42 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-07 05:11:42 +0400
commitd04ee2a3f65ba8d191bba778a66f771e4530b99b (patch)
tree5542448ab5cb9c8f5cd683fd3c9fac44a4798e86 /src/Network/Torrent/PeerID.hs
parent0b93032e3f7488681d5cb402cb5b4c9e566628b2 (diff)
~ fix bugs in encoding
Diffstat (limited to 'src/Network/Torrent/PeerID.hs')
-rw-r--r--src/Network/Torrent/PeerID.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Network/Torrent/PeerID.hs b/src/Network/Torrent/PeerID.hs
index 551b0dcc..0eb4cbbb 100644
--- a/src/Network/Torrent/PeerID.hs
+++ b/src/Network/Torrent/PeerID.hs
@@ -24,7 +24,7 @@ import qualified Data.ByteString.Lazy as BL
24import qualified Data.ByteString.Builder as B 24import qualified Data.ByteString.Builder as B
25import Data.Foldable (foldMap) 25import Data.Foldable (foldMap)
26import Data.Monoid ((<>)) 26import Data.Monoid ((<>))
27import Data.Serialize (Serialize) 27import Data.Serialize
28import Data.Version (Version(Version), versionBranch) 28import Data.Version (Version(Version), versionBranch)
29import Data.Time.Clock (getCurrentTime) 29import Data.Time.Clock (getCurrentTime)
30import Data.Time.Format (formatTime) 30import Data.Time.Format (formatTime)
@@ -37,7 +37,11 @@ version = Version [0, 10, 0, 0] []
37 37
38-- | Peer identifier is exactly 20 bytes long bytestring. 38-- | Peer identifier is exactly 20 bytes long bytestring.
39newtype PeerID = PeerID { getPeerID :: ByteString } 39newtype PeerID = PeerID { getPeerID :: ByteString }
40 deriving (Show, Eq, Ord, BEncodable, Serialize) 40 deriving (Show, Eq, Ord, BEncodable)
41
42instance Serialize PeerID where
43 put = putByteString . getPeerID
44 get = PeerID <$> getBytes 20
41 45
42-- | Azureus-style encoding: 46-- | Azureus-style encoding:
43-- * 1 byte : '-' 47-- * 1 byte : '-'
@@ -115,4 +119,4 @@ byteStringPadded bs s c =
115 B.byteString (B.take s bs) <> 119 B.byteString (B.take s bs) <>
116 B.byteString (BC.replicate padLen c) 120 B.byteString (BC.replicate padLen c)
117 where 121 where
118 padLen = s - max (B.length bs) s \ No newline at end of file 122 padLen = s - min (B.length bs) s \ No newline at end of file