diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/Torrent/Handshake.hs | 2 | ||||
-rw-r--r-- | src/Network/Torrent/PeerID.hs | 10 |
2 files changed, 8 insertions, 4 deletions
diff --git a/src/Network/Torrent/Handshake.hs b/src/Network/Torrent/Handshake.hs index 7643b2e9..b17afaf7 100644 --- a/src/Network/Torrent/Handshake.hs +++ b/src/Network/Torrent/Handshake.hs | |||
@@ -34,7 +34,7 @@ instance Serialize Handshake where | |||
34 | 34 | ||
35 | get = do | 35 | get = do |
36 | len <- getWord8 | 36 | len <- getWord8 |
37 | Handshake <$> getBytes (fromIntegral len) | 37 | Handshake <$> getBytes (fromIntegral (len - 49)) |
38 | <*> getWord64be | 38 | <*> getWord64be |
39 | <*> getBytes 20 | 39 | <*> getBytes 20 |
40 | <*> get | 40 | <*> get |
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 |