diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-05 05:39:30 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-12-05 05:39:30 +0400 |
commit | 6f092fb275367b6afe4f0745f975e8ee53012d56 (patch) | |
tree | ad38491e0fa45989d143f8050839ceefb5788b87 /src/Network/BitTorrent/Exchange/Wire.hs | |
parent | 7680dbe4eea3c4882e67cef01d6c7aded8639c13 (diff) |
Simplify Core modules imports
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Wire.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Wire.hs | 29 |
1 files changed, 16 insertions, 13 deletions
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 | ||