summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Network/Torrent/Handshake.hs2
-rw-r--r--src/Network/Torrent/PeerID.hs10
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
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