diff options
author | Sam T <sta.cs.vsu@gmail.com> | 2013-04-07 05:11:42 +0400 |
---|---|---|
committer | Sam T <sta.cs.vsu@gmail.com> | 2013-04-07 05:11:42 +0400 |
commit | d04ee2a3f65ba8d191bba778a66f771e4530b99b (patch) | |
tree | 5542448ab5cb9c8f5cd683fd3c9fac44a4798e86 /src/Network/Torrent/PeerID.hs | |
parent | 0b93032e3f7488681d5cb402cb5b4c9e566628b2 (diff) |
~ fix bugs in encoding
Diffstat (limited to 'src/Network/Torrent/PeerID.hs')
-rw-r--r-- | src/Network/Torrent/PeerID.hs | 10 |
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 | |||
24 | import qualified Data.ByteString.Builder as B | 24 | import qualified Data.ByteString.Builder as B |
25 | import Data.Foldable (foldMap) | 25 | import Data.Foldable (foldMap) |
26 | import Data.Monoid ((<>)) | 26 | import Data.Monoid ((<>)) |
27 | import Data.Serialize (Serialize) | 27 | import Data.Serialize |
28 | import Data.Version (Version(Version), versionBranch) | 28 | import Data.Version (Version(Version), versionBranch) |
29 | import Data.Time.Clock (getCurrentTime) | 29 | import Data.Time.Clock (getCurrentTime) |
30 | import Data.Time.Format (formatTime) | 30 | import 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. |
39 | newtype PeerID = PeerID { getPeerID :: ByteString } | 39 | newtype PeerID = PeerID { getPeerID :: ByteString } |
40 | deriving (Show, Eq, Ord, BEncodable, Serialize) | 40 | deriving (Show, Eq, Ord, BEncodable) |
41 | |||
42 | instance 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 |