summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Exchange')
-rw-r--r--src/Network/BitTorrent/Exchange/Message.hs5
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs2
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs29
3 files changed, 18 insertions, 18 deletions
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
81import Data.Serialize as S 81import Data.Serialize as S
82import Data.Text as T 82import Data.Text as T
83import Data.Typeable 83import Data.Typeable
84import Data.Tuple
85import Data.Word 84import Data.Word
86import Network 85import Network
87import Network.Socket hiding (KeepAlive) 86import Network.Socket hiding (KeepAlive)
88import Network.Socket.ByteString as BS
89import Text.PrettyPrint as PP 87import Text.PrettyPrint as PP
90import Text.PrettyPrint.Class 88import Text.PrettyPrint.Class
91 89
92import Data.Torrent.Bitfield 90import Data.Torrent.Bitfield
93import Data.Torrent.InfoHash 91import Data.Torrent.InfoHash
94import Network.BitTorrent.Core.PeerId 92import Network.BitTorrent.Core
95import Network.BitTorrent.Core.PeerAddr ()
96import Network.BitTorrent.Exchange.Block 93import 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
16import Data.Torrent.Bitfield 16import Data.Torrent.Bitfield
17import Data.Torrent.InfoHash 17import Data.Torrent.InfoHash
18import Network.BitTorrent.Core.PeerAddr 18import Network.BitTorrent.Core
19import Network.BitTorrent.Exchange.Message 19import Network.BitTorrent.Exchange.Message
20import Network.BitTorrent.Exchange.Status 20import 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 (($$), (<>))
38import Text.PrettyPrint.Class 38import Text.PrettyPrint.Class
39 39
40import Data.Torrent.InfoHash 40import Data.Torrent.InfoHash
41import Network.BitTorrent.Core.PeerId 41import Network.BitTorrent.Core
42import Network.BitTorrent.Core.PeerAddr
43import Network.BitTorrent.Exchange.Message 42import Network.BitTorrent.Exchange.Message
44 43
45 44
@@ -147,15 +146,21 @@ connectToPeer p = do
147 146
148type Wire = ConduitM Message Message (ReaderT Connection IO) 147type Wire = ConduitM Message Message (ReaderT Connection IO)
149 148
150validate :: Wire () 149validate :: ChannelSide -> Wire ()
151validate = do 150validate 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
160validate' action = do
161 validate RemotePeer
162 action
163 validate ThisPeer
159 164
160runWire :: Wire () -> Socket -> Connection -> IO () 165runWire :: Wire () -> Socket -> Connection -> IO ()
161runWire action sock = runReaderT $ 166runWire action sock = runReaderT $
@@ -173,8 +178,6 @@ sendMessage msg = do
173recvMessage :: Wire Message 178recvMessage :: Wire Message
174recvMessage = undefined 179recvMessage = undefined
175 180
176
177
178extendedHandshake :: Wire () 181extendedHandshake :: Wire ()
179extendedHandshake = undefined 182extendedHandshake = undefined
180 183