diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-09 03:39:34 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-09 03:39:34 +0400 |
commit | f2ebdc9e4b0ad69a5a878c8e14b4e1a6bd34a831 (patch) | |
tree | 8e4e3a02fc1c2cb87773674bc192f6e6a81b1ad1 | |
parent | 7bbd628732ec65f9428d7792aa265152a88b5483 (diff) |
~ Hide *.Protocol modules.
-rw-r--r-- | bench/Main.hs | 2 | ||||
-rw-r--r-- | bittorrent.cabal | 11 | ||||
-rw-r--r-- | src/Network/BitTorrent.hs | 6 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange.hs | 57 | ||||
-rw-r--r-- | src/Network/BitTorrent/Peer.hs | 3 | ||||
-rw-r--r-- | tests/Main.hs | 3 |
6 files changed, 69 insertions, 13 deletions
diff --git a/bench/Main.hs b/bench/Main.hs index 120f5b04..0037c66b 100644 --- a/bench/Main.hs +++ b/bench/Main.hs | |||
@@ -10,6 +10,8 @@ import Data.Serialize | |||
10 | import Network | 10 | import Network |
11 | 11 | ||
12 | import Network.BitTorrent as BT | 12 | import Network.BitTorrent as BT |
13 | import Network.BitTorrent.Exchange.Protocol as BT | ||
14 | import Network.BitTorrent.Tracker.Protocol as BT | ||
13 | import Data.Bitfield as BT | 15 | import Data.Bitfield as BT |
14 | 16 | ||
15 | 17 | ||
diff --git a/bittorrent.cabal b/bittorrent.cabal index cdc332ab..3b5d0a90 100644 --- a/bittorrent.cabal +++ b/bittorrent.cabal | |||
@@ -41,14 +41,19 @@ library | |||
41 | , Network.BitTorrent.Peer | 41 | , Network.BitTorrent.Peer |
42 | 42 | ||
43 | , Network.BitTorrent.Tracker | 43 | , Network.BitTorrent.Tracker |
44 | , Network.BitTorrent.Tracker.Protocol | ||
45 | , Network.BitTorrent.Tracker.Scrape | 44 | , Network.BitTorrent.Tracker.Scrape |
46 | 45 | ||
47 | , Network.BitTorrent.Exchange | 46 | , Network.BitTorrent.Exchange |
48 | , Network.BitTorrent.Exchange.Selection | 47 | , Network.BitTorrent.Exchange.Selection |
49 | , Network.BitTorrent.Exchange.Protocol | ||
50 | 48 | ||
51 | other-modules: | 49 | if flag(testing) |
50 | exposed-modules: Network.BitTorrent.Exchange.Protocol | ||
51 | , Network.BitTorrent.Tracker.Protocol | ||
52 | |||
53 | if !flag(testing) | ||
54 | other-modules: | ||
55 | Network.BitTorrent.Exchange.Protocol | ||
56 | , Network.BitTorrent.Tracker.Protocol | ||
52 | 57 | ||
53 | 58 | ||
54 | build-depends: | 59 | build-depends: |
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs index 51ba6aac..ac9ed50a 100644 --- a/src/Network/BitTorrent.hs +++ b/src/Network/BitTorrent.hs | |||
@@ -5,7 +5,11 @@ | |||
5 | -- Stability : experimental | 5 | -- Stability : experimental |
6 | -- Portability : portable | 6 | -- Portability : portable |
7 | -- | 7 | -- |
8 | module Network.BitTorrent (module BT) where | 8 | module Network.BitTorrent |
9 | (module BT | ||
10 | |||
11 | -- , ClientSession, newClient | ||
12 | ) where | ||
9 | 13 | ||
10 | import Network.BitTorrent.Extension as BT | 14 | import Network.BitTorrent.Extension as BT |
11 | import Network.BitTorrent.Peer as BT | 15 | import Network.BitTorrent.Peer as BT |
diff --git a/src/Network/BitTorrent/Exchange.hs b/src/Network/BitTorrent/Exchange.hs index d75fdf96..425ed2a3 100644 --- a/src/Network/BitTorrent/Exchange.hs +++ b/src/Network/BitTorrent/Exchange.hs | |||
@@ -6,18 +6,61 @@ | |||
6 | -- Portability : portable | 6 | -- Portability : portable |
7 | -- | 7 | -- |
8 | {-# LANGUAGE DoAndIfThenElse #-} | 8 | {-# LANGUAGE DoAndIfThenElse #-} |
9 | module Network.BitTorrent.Exchange (module PW) where | 9 | module Network.BitTorrent.Exchange |
10 | ( | ||
11 | -- * Session | ||
12 | PeerSession, newLeacher, newSeeder | ||
13 | ) where | ||
14 | |||
15 | import Control.Applicative | ||
16 | import Control.Concurrent | ||
17 | import Control.Concurrent.STM | ||
18 | import Data.IORef | ||
19 | import Data.Function | ||
20 | import Data.Ord | ||
21 | import Data.Set as S | ||
22 | |||
23 | import Data.Conduit | ||
24 | import Data.Conduit.Cereal | ||
25 | import Data.Conduit.Network | ||
26 | import Data.Serialize | ||
10 | 27 | ||
11 | import Network.BitTorrent.Exchange.Selection as PW | 28 | import Network.BitTorrent.Exchange.Selection as PW |
12 | import Network.BitTorrent.Exchange.Protocol as PW | 29 | import Network.BitTorrent.Exchange.Protocol as PW |
13 | 30 | ||
31 | import Network.BitTorrent.Internal | ||
32 | import Network.BitTorrent.Extension | ||
33 | import Network.BitTorrent.Peer | ||
34 | import Data.Bitfield as BF | ||
35 | import Data.Torrent | ||
36 | |||
37 | {----------------------------------------------------------------------- | ||
38 | P2P monad | ||
39 | -----------------------------------------------------------------------} | ||
40 | |||
14 | {- | 41 | {- |
42 | type P2P = Reader PeerSession (ConduitM Message Message IO) | ||
15 | 43 | ||
16 | newtype P2P a = P2P { | 44 | conduit :: Socket -> P2P a -> IO a |
17 | getP2P :: ReaderT PSession State PState (Conduit Message IO Message) a | 45 | conduit sock p2p = |
18 | } | 46 | sourceSocket sock $= |
47 | conduitGet get $= | ||
48 | messageLoop p2p $= | ||
49 | conduitPut put $$ | ||
50 | sinkSocket sock | ||
19 | 51 | ||
20 | runP2P :: PConnection -> P2P a -> IO a | 52 | messageLoop :: P2P () -> P2P () |
21 | recvMessage :: P2P Message | 53 | messageLoop = undefined |
22 | sendMessage :: Message -> P2P () | 54 | |
55 | runP2P :: SSession -> PeerAddr -> P2P a -> IO a | ||
56 | runP2P se addr p2p = withPeer se addr $ conduit messageLoop | ||
57 | |||
58 | data Event = Available | ||
59 | | Want | ||
60 | | Block | ||
61 | |||
62 | {- | ||
63 | waitForEvent :: P2P Event | ||
64 | signalEvent :: Event -> P2P () | ||
65 | -} | ||
23 | -} \ No newline at end of file | 66 | -} \ No newline at end of file |
diff --git a/src/Network/BitTorrent/Peer.hs b/src/Network/BitTorrent/Peer.hs index 6ab80fb6..9aa924d3 100644 --- a/src/Network/BitTorrent/Peer.hs +++ b/src/Network/BitTorrent/Peer.hs | |||
@@ -488,7 +488,8 @@ data PeerAddr = PeerAddr { | |||
488 | peerID :: Maybe PeerID | 488 | peerID :: Maybe PeerID |
489 | , peerIP :: HostAddress | 489 | , peerIP :: HostAddress |
490 | , peerPort :: PortNumber | 490 | , peerPort :: PortNumber |
491 | } deriving (Show, Eq) | 491 | } deriving (Show, Eq, Ord) |
492 | -- TODO verify semantic of ord and eq instances | ||
492 | 493 | ||
493 | instance BEncodable PortNumber where | 494 | instance BEncodable PortNumber where |
494 | toBEncode = toBEncode . fromEnum | 495 | toBEncode = toBEncode . fromEnum |
diff --git a/tests/Main.hs b/tests/Main.hs index 84870d66..f71f2b00 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -25,7 +25,8 @@ import Data.BEncode as BE | |||
25 | import Data.Bitfield as BF | 25 | import Data.Bitfield as BF |
26 | import Data.Torrent | 26 | import Data.Torrent |
27 | import Network.BitTorrent as BT | 27 | import Network.BitTorrent as BT |
28 | 28 | import Network.BitTorrent.Exchange.Protocol | |
29 | import Network.BitTorrent.Tracker.Protocol | ||
29 | -- import Debug.Trace | 30 | -- import Debug.Trace |
30 | 31 | ||
31 | 32 | ||