diff options
-rw-r--r-- | src/Data/Torrent/Bitfield.hs | 2 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core.hs | 5 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Message.hs | 5 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 2 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 29 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Message.hs | 3 | ||||
-rw-r--r-- | src/Network/BitTorrent/Tracker/Wai.hs | 2 |
7 files changed, 22 insertions, 26 deletions
diff --git a/src/Data/Torrent/Bitfield.hs b/src/Data/Torrent/Bitfield.hs index 17278a2c..176ba2c0 100644 --- a/src/Data/Torrent/Bitfield.hs +++ b/src/Data/Torrent/Bitfield.hs | |||
@@ -55,10 +55,8 @@ module Data.Torrent.Bitfield | |||
55 | , fromBitmap, toBitmap | 55 | , fromBitmap, toBitmap |
56 | , toList | 56 | , toList |
57 | 57 | ||
58 | #if defined (TESTING) | ||
59 | -- * Debug | 58 | -- * Debug |
60 | , mkBitfield | 59 | , mkBitfield |
61 | #endif | ||
62 | ) where | 60 | ) where |
63 | 61 | ||
64 | import Control.Monad | 62 | import Control.Monad |
diff --git a/src/Network/BitTorrent/Core.hs b/src/Network/BitTorrent/Core.hs index b4329598..990a5975 100644 --- a/src/Network/BitTorrent/Core.hs +++ b/src/Network/BitTorrent/Core.hs | |||
@@ -8,5 +8,6 @@ | |||
8 | -- Re-export every @Network.BitTorrent.Core.*@ module. | 8 | -- Re-export every @Network.BitTorrent.Core.*@ module. |
9 | -- | 9 | -- |
10 | module Network.BitTorrent.Core (module Core) where | 10 | module Network.BitTorrent.Core (module Core) where |
11 | import Network.BitTorrent.Core.PeerId as Core | 11 | import Network.BitTorrent.Core.Fingerprint as Core |
12 | import Network.BitTorrent.Core.PeerAddr as Core \ No newline at end of file | 12 | import Network.BitTorrent.Core.PeerId as Core |
13 | import Network.BitTorrent.Core.PeerAddr as Core \ No newline at end of file | ||
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs index 85ad76d6..b879e212 100644 --- a/src/Network/BitTorrent/Exchange/Message.hs +++ b/src/Network/BitTorrent/Exchange/Message.hs | |||
@@ -81,18 +81,15 @@ import Data.Ord | |||
81 | import Data.Serialize as S | 81 | import Data.Serialize as S |
82 | import Data.Text as T | 82 | import Data.Text as T |
83 | import Data.Typeable | 83 | import Data.Typeable |
84 | import Data.Tuple | ||
85 | import Data.Word | 84 | import Data.Word |
86 | import Network | 85 | import Network |
87 | import Network.Socket hiding (KeepAlive) | 86 | import Network.Socket hiding (KeepAlive) |
88 | import Network.Socket.ByteString as BS | ||
89 | import Text.PrettyPrint as PP | 87 | import Text.PrettyPrint as PP |
90 | import Text.PrettyPrint.Class | 88 | import Text.PrettyPrint.Class |
91 | 89 | ||
92 | import Data.Torrent.Bitfield | 90 | import Data.Torrent.Bitfield |
93 | import Data.Torrent.InfoHash | 91 | import Data.Torrent.InfoHash |
94 | import Network.BitTorrent.Core.PeerId | 92 | import Network.BitTorrent.Core |
95 | import Network.BitTorrent.Core.PeerAddr () | ||
96 | import Network.BitTorrent.Exchange.Block | 93 | import Network.BitTorrent.Exchange.Block |
97 | 94 | ||
98 | {----------------------------------------------------------------------- | 95 | {----------------------------------------------------------------------- |
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs index d2a9aaaf..c24e2b0b 100644 --- a/src/Network/BitTorrent/Exchange/Session.hs +++ b/src/Network/BitTorrent/Exchange/Session.hs | |||
@@ -15,7 +15,7 @@ import Text.PrettyPrint | |||
15 | 15 | ||
16 | import Data.Torrent.Bitfield | 16 | import Data.Torrent.Bitfield |
17 | import Data.Torrent.InfoHash | 17 | import Data.Torrent.InfoHash |
18 | import Network.BitTorrent.Core.PeerAddr | 18 | import Network.BitTorrent.Core |
19 | import Network.BitTorrent.Exchange.Message | 19 | import Network.BitTorrent.Exchange.Message |
20 | import Network.BitTorrent.Exchange.Status | 20 | import Network.BitTorrent.Exchange.Status |
21 | 21 | ||
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs index dd77a915..68c9b355 100644 --- a/src/Network/BitTorrent/Exchange/Wire.hs +++ b/src/Network/BitTorrent/Exchange/Wire.hs | |||
@@ -38,8 +38,7 @@ import Text.PrettyPrint as PP hiding (($$), (<>)) | |||
38 | import Text.PrettyPrint.Class | 38 | import Text.PrettyPrint.Class |
39 | 39 | ||
40 | import Data.Torrent.InfoHash | 40 | import Data.Torrent.InfoHash |
41 | import Network.BitTorrent.Core.PeerId | 41 | import Network.BitTorrent.Core |
42 | import Network.BitTorrent.Core.PeerAddr | ||
43 | import Network.BitTorrent.Exchange.Message | 42 | import Network.BitTorrent.Exchange.Message |
44 | 43 | ||
45 | 44 | ||
@@ -147,15 +146,21 @@ connectToPeer p = do | |||
147 | 146 | ||
148 | type Wire = ConduitM Message Message (ReaderT Connection IO) | 147 | type Wire = ConduitM Message Message (ReaderT Connection IO) |
149 | 148 | ||
150 | validate :: Wire () | 149 | validate :: ChannelSide -> Wire () |
151 | validate = do | 150 | validate side = await >>= maybe (return ()) yieldCheck |
152 | mmsg <- await | 151 | where |
153 | case mmsg of | 152 | yieldCheck msg = do |
154 | Nothing -> return () | 153 | caps <- lift $ asks connCaps |
155 | Just msg -> do | 154 | case requires msg of |
156 | valid <- lift $ asks (`isAllowed` msg) | 155 | Nothing -> return () |
157 | if valid then yield msg else error "TODO" | 156 | Just ext |
158 | 157 | | allowed caps ext -> yield msg | |
158 | | otherwise -> monadThrow $ ProtocolError $ InvalidMessage side ext | ||
159 | |||
160 | validate' action = do | ||
161 | validate RemotePeer | ||
162 | action | ||
163 | validate ThisPeer | ||
159 | 164 | ||
160 | runWire :: Wire () -> Socket -> Connection -> IO () | 165 | runWire :: Wire () -> Socket -> Connection -> IO () |
161 | runWire action sock = runReaderT $ | 166 | runWire action sock = runReaderT $ |
@@ -173,8 +178,6 @@ sendMessage msg = do | |||
173 | recvMessage :: Wire Message | 178 | recvMessage :: Wire Message |
174 | recvMessage = undefined | 179 | recvMessage = undefined |
175 | 180 | ||
176 | |||
177 | |||
178 | extendedHandshake :: Wire () | 181 | extendedHandshake :: Wire () |
179 | extendedHandshake = undefined | 182 | extendedHandshake = undefined |
180 | 183 | ||
diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index e8e4cf0e..212181b9 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs | |||
@@ -88,8 +88,7 @@ import Text.Read (readMaybe) | |||
88 | 88 | ||
89 | import Data.Torrent.InfoHash | 89 | import Data.Torrent.InfoHash |
90 | import Data.Torrent.Progress | 90 | import Data.Torrent.Progress |
91 | import Network.BitTorrent.Core.PeerId | 91 | import Network.BitTorrent.Core |
92 | import Network.BitTorrent.Core.PeerAddr | ||
93 | 92 | ||
94 | 93 | ||
95 | {----------------------------------------------------------------------- | 94 | {----------------------------------------------------------------------- |
diff --git a/src/Network/BitTorrent/Tracker/Wai.hs b/src/Network/BitTorrent/Tracker/Wai.hs index 51fd8153..770816b4 100644 --- a/src/Network/BitTorrent/Tracker/Wai.hs +++ b/src/Network/BitTorrent/Tracker/Wai.hs | |||
@@ -12,8 +12,6 @@ import Network.HTTP.Types | |||
12 | import Network.Wai | 12 | import Network.Wai |
13 | 13 | ||
14 | import Data.Torrent.Progress | 14 | import Data.Torrent.Progress |
15 | import Network.BitTorrent.Core.PeerId | ||
16 | import Network.BitTorrent.Core.PeerAddr | ||
17 | import Network.BitTorrent.Tracker.Message | 15 | import Network.BitTorrent.Tracker.Message |
18 | 16 | ||
19 | 17 | ||