diff options
-rw-r--r-- | bench/Main.hs | 5 | ||||
-rw-r--r-- | network-bittorrent.cabal | 1 | ||||
-rw-r--r-- | src/Network/BitTorrent/PeerWire/Message.hs | 6 | ||||
-rw-r--r-- | tests/Encoding.hs | 7 |
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 | |||
7 | import Data.ByteString (ByteString) | 7 | import Data.ByteString (ByteString) |
8 | import qualified Data.ByteString as B | 8 | import qualified Data.ByteString as B |
9 | import Data.Serialize | 9 | import Data.Serialize |
10 | import Network | ||
11 | |||
10 | import Network.BitTorrent as BT | 12 | import Network.BitTorrent as BT |
11 | import Data.Bitfield as BT | 13 | import Data.Bitfield as BT |
12 | 14 | ||
13 | 15 | ||
16 | instance NFData PortNumber where | ||
17 | rnf = rnf . (fromIntegral :: PortNumber -> Int) | ||
18 | |||
14 | instance NFData BlockIx where | 19 | instance 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 | ||
7 | import Control.Applicative | 7 | import Control.Applicative |
8 | import qualified Data.ByteString as B | 8 | import qualified Data.ByteString as B |
9 | |||
10 | import Data.Serialize | 9 | import Data.Serialize |
10 | import Network | ||
11 | 11 | ||
12 | import Network.BitTorrent.PeerWire.Block | 12 | import Network.BitTorrent.PeerWire.Block |
13 | import Data.Bitfield | 13 | import Data.Bitfield |
14 | 14 | ||
15 | import 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) | |||
13 | import Test.QuickCheck | 13 | import Test.QuickCheck |
14 | 14 | ||
15 | import Network.URI | 15 | import Network.URI |
16 | import Network | ||
17 | |||
16 | 18 | ||
17 | import Data.Bitfield | 19 | import Data.Bitfield |
18 | import Data.Torrent | 20 | import Data.Torrent |
@@ -33,6 +35,9 @@ instance Arbitrary Block where | |||
33 | 35 | ||
34 | deriving instance Arbitrary Bitfield | 36 | deriving instance Arbitrary Bitfield |
35 | 37 | ||
38 | instance Arbitrary PortNumber where | ||
39 | arbitrary = fromIntegral <$> (arbitrary :: Gen Word16) | ||
40 | |||
36 | instance Arbitrary Message where | 41 | instance 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 | ||
51 | instance Arbitrary PeerID where | 56 | instance Arbitrary PeerID where |