summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bench/Main.hs5
-rw-r--r--network-bittorrent.cabal1
-rw-r--r--src/Network/BitTorrent/PeerWire/Message.hs6
-rw-r--r--tests/Encoding.hs7
4 files changed, 15 insertions, 4 deletions
diff --git a/bench/Main.hs b/bench/Main.hs
index 269e60f5..6e8a0ce3 100644
--- a/bench/Main.hs
+++ b/bench/Main.hs
@@ -7,10 +7,15 @@ import Criterion.Main
7import Data.ByteString (ByteString) 7import Data.ByteString (ByteString)
8import qualified Data.ByteString as B 8import qualified Data.ByteString as B
9import Data.Serialize 9import Data.Serialize
10import Network
11
10import Network.BitTorrent as BT 12import Network.BitTorrent as BT
11import Data.Bitfield as BT 13import Data.Bitfield as BT
12 14
13 15
16instance NFData PortNumber where
17 rnf = rnf . (fromIntegral :: PortNumber -> Int)
18
14instance NFData BlockIx where 19instance NFData BlockIx where
15 rnf (BlockIx a b c) = a `deepseq` b `deepseq` rnf c 20 rnf (BlockIx a b c) = a `deepseq` b `deepseq` rnf c
16 21
diff --git a/network-bittorrent.cabal b/network-bittorrent.cabal
index 339dc376..0a89603a 100644
--- a/network-bittorrent.cabal
+++ b/network-bittorrent.cabal
@@ -127,6 +127,7 @@ benchmark benchmarks
127 build-depends: base == 4.* 127 build-depends: base == 4.*
128 , bytestring >= 0.10.2.0 128 , bytestring >= 0.10.2.0
129 , cereal 129 , cereal
130 , network
130 131
131 , criterion 132 , criterion
132 , deepseq 133 , deepseq
diff --git a/src/Network/BitTorrent/PeerWire/Message.hs b/src/Network/BitTorrent/PeerWire/Message.hs
index 1c520221..5544dca7 100644
--- a/src/Network/BitTorrent/PeerWire/Message.hs
+++ b/src/Network/BitTorrent/PeerWire/Message.hs
@@ -6,13 +6,13 @@ module Network.BitTorrent.PeerWire.Message
6 6
7import Control.Applicative 7import Control.Applicative
8import qualified Data.ByteString as B 8import qualified Data.ByteString as B
9
10import Data.Serialize 9import Data.Serialize
10import Network
11 11
12import Network.BitTorrent.PeerWire.Block 12import Network.BitTorrent.PeerWire.Block
13import Data.Bitfield 13import Data.Bitfield
14 14
15import Data.Array 15
16 16
17-- | Messages used in communication between peers. 17-- | Messages used in communication between peers.
18-- 18--
@@ -48,7 +48,7 @@ data Message = KeepAlive
48 -- used during "End Game". 48 -- used during "End Game".
49 | Cancel BlockIx 49 | Cancel BlockIx
50 50
51 | Port Int 51 | Port PortNumber
52 52
53 -- | BEP 6: Then peer have all pieces it might send the 53 -- | BEP 6: Then peer have all pieces it might send the
54 -- 'HaveAll' message instead of 'Bitfield' 54 -- 'HaveAll' message instead of 'Bitfield'
diff --git a/tests/Encoding.hs b/tests/Encoding.hs
index fe0e1d7e..d43045bc 100644
--- a/tests/Encoding.hs
+++ b/tests/Encoding.hs
@@ -13,6 +13,8 @@ import Test.Framework.Providers.QuickCheck2 (testProperty)
13import Test.QuickCheck 13import Test.QuickCheck
14 14
15import Network.URI 15import Network.URI
16import Network
17
16 18
17import Data.Bitfield 19import Data.Bitfield
18import Data.Torrent 20import Data.Torrent
@@ -33,6 +35,9 @@ instance Arbitrary Block where
33 35
34deriving instance Arbitrary Bitfield 36deriving instance Arbitrary Bitfield
35 37
38instance Arbitrary PortNumber where
39 arbitrary = fromIntegral <$> (arbitrary :: Gen Word16)
40
36instance Arbitrary Message where 41instance Arbitrary Message where
37 arbitrary = oneof 42 arbitrary = oneof
38 [ pure KeepAlive 43 [ pure KeepAlive
@@ -45,7 +50,7 @@ instance Arbitrary Message where
45 , Request <$> arbitrary 50 , Request <$> arbitrary
46 , Piece <$> arbitrary 51 , Piece <$> arbitrary
47 , Cancel <$> arbitrary 52 , Cancel <$> arbitrary
48 , Port <$> choose (0, fromIntegral (maxBound :: Word16)) 53 , Port <$> arbitrary
49 ] 54 ]
50 55
51instance Arbitrary PeerID where 56instance Arbitrary PeerID where