summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-09 03:39:34 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-09 03:39:34 +0400
commitf2ebdc9e4b0ad69a5a878c8e14b4e1a6bd34a831 (patch)
tree8e4e3a02fc1c2cb87773674bc192f6e6a81b1ad1
parent7bbd628732ec65f9428d7792aa265152a88b5483 (diff)
~ Hide *.Protocol modules.
-rw-r--r--bench/Main.hs2
-rw-r--r--bittorrent.cabal11
-rw-r--r--src/Network/BitTorrent.hs6
-rw-r--r--src/Network/BitTorrent/Exchange.hs57
-rw-r--r--src/Network/BitTorrent/Peer.hs3
-rw-r--r--tests/Main.hs3
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
10import Network 10import Network
11 11
12import Network.BitTorrent as BT 12import Network.BitTorrent as BT
13import Network.BitTorrent.Exchange.Protocol as BT
14import Network.BitTorrent.Tracker.Protocol as BT
13import Data.Bitfield as BT 15import 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--
8module Network.BitTorrent (module BT) where 8module Network.BitTorrent
9 (module BT
10
11-- , ClientSession, newClient
12 ) where
9 13
10import Network.BitTorrent.Extension as BT 14import Network.BitTorrent.Extension as BT
11import Network.BitTorrent.Peer as BT 15import 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 #-}
9module Network.BitTorrent.Exchange (module PW) where 9module Network.BitTorrent.Exchange
10 (
11 -- * Session
12 PeerSession, newLeacher, newSeeder
13 ) where
14
15import Control.Applicative
16import Control.Concurrent
17import Control.Concurrent.STM
18import Data.IORef
19import Data.Function
20import Data.Ord
21import Data.Set as S
22
23import Data.Conduit
24import Data.Conduit.Cereal
25import Data.Conduit.Network
26import Data.Serialize
10 27
11import Network.BitTorrent.Exchange.Selection as PW 28import Network.BitTorrent.Exchange.Selection as PW
12import Network.BitTorrent.Exchange.Protocol as PW 29import Network.BitTorrent.Exchange.Protocol as PW
13 30
31import Network.BitTorrent.Internal
32import Network.BitTorrent.Extension
33import Network.BitTorrent.Peer
34import Data.Bitfield as BF
35import Data.Torrent
36
37{-----------------------------------------------------------------------
38 P2P monad
39-----------------------------------------------------------------------}
40
14{- 41{-
42type P2P = Reader PeerSession (ConduitM Message Message IO)
15 43
16newtype P2P a = P2P { 44conduit :: Socket -> P2P a -> IO a
17 getP2P :: ReaderT PSession State PState (Conduit Message IO Message) a 45conduit sock p2p =
18 } 46 sourceSocket sock $=
47 conduitGet get $=
48 messageLoop p2p $=
49 conduitPut put $$
50 sinkSocket sock
19 51
20runP2P :: PConnection -> P2P a -> IO a 52messageLoop :: P2P () -> P2P ()
21recvMessage :: P2P Message 53messageLoop = undefined
22sendMessage :: Message -> P2P () 54
55runP2P :: SSession -> PeerAddr -> P2P a -> IO a
56runP2P se addr p2p = withPeer se addr $ conduit messageLoop
57
58data Event = Available
59 | Want
60 | Block
61
62{-
63waitForEvent :: P2P Event
64signalEvent :: 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
493instance BEncodable PortNumber where 494instance 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
25import Data.Bitfield as BF 25import Data.Bitfield as BF
26import Data.Torrent 26import Data.Torrent
27import Network.BitTorrent as BT 27import Network.BitTorrent as BT
28 28import Network.BitTorrent.Exchange.Protocol
29import Network.BitTorrent.Tracker.Protocol
29-- import Debug.Trace 30-- import Debug.Trace
30 31
31 32