summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-12 21:55:58 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-12 21:55:58 +0400
commita220935e3d83cf6d96e767baa04c71a2f174f1ef (patch)
tree8908e9e49eedb13af2072e3b748d2a3ce151a8b3
parent1864fb2106c29b64af0cb80bebd91209b67d5fd3 (diff)
Add filterQueue function
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs3
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs11
2 files changed, 11 insertions, 3 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs
index 695ac18a..dce2572f 100644
--- a/src/Network/BitTorrent/Exchange/Session.hs
+++ b/src/Network/BitTorrent/Exchange/Session.hs
@@ -169,9 +169,6 @@ handleMessage (Port n) = undefined
169handleMessage (Fast _) = undefined 169handleMessage (Fast _) = undefined
170handleMessage (Extended _) = undefined 170handleMessage (Extended _) = undefined
171 171
172filterQueue :: (Message -> Bool) -> Wire s ()
173filterQueue = undefined
174
175exchange :: Wire Session () 172exchange :: Wire Session ()
176exchange = do 173exchange = do
177 e <- recvMessage 174 e <- recvMessage
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs
index 6b6abde1..6ef33b85 100644
--- a/src/Network/BitTorrent/Exchange/Wire.hs
+++ b/src/Network/BitTorrent/Exchange/Wire.hs
@@ -53,6 +53,7 @@ module Network.BitTorrent.Exchange.Wire
53 -- ** Messaging 53 -- ** Messaging
54 , recvMessage 54 , recvMessage
55 , sendMessage 55 , sendMessage
56 , filterQueue
56 57
57 -- ** Query 58 -- ** Query
58 , getConnection 59 , getConnection
@@ -76,6 +77,7 @@ import Data.Conduit.List
76import Data.Conduit.Network 77import Data.Conduit.Network
77import Data.Default 78import Data.Default
78import Data.IORef 79import Data.IORef
80import Data.List as L
79import Data.Maybe 81import Data.Maybe
80import Data.Monoid 82import Data.Monoid
81import Data.Serialize as S 83import Data.Serialize as S
@@ -483,6 +485,8 @@ data Connection s = Connection
483 485
484 -- | Environment data. 486 -- | Environment data.
485 , connSession :: !s 487 , connSession :: !s
488
489 , connChan :: !(Chan Message)
486 } 490 }
487 491
488instance Pretty (Connection s) where 492instance Pretty (Connection s) where
@@ -635,6 +639,12 @@ sendMessage msg = do
635 ecaps <- use connExtCaps 639 ecaps <- use connExtCaps
636 yield $ envelop ecaps msg 640 yield $ envelop ecaps msg
637 641
642-- | Filter pending messages from send buffer.
643filterQueue :: (Message -> Bool) -> Wire s ()
644filterQueue p = lift $ do
645 chan <- asks connChan
646 liftIO $ getChanContents chan >>= writeList2Chan chan . L.filter p
647
638-- | Forcefully terminate wire session and close socket. 648-- | Forcefully terminate wire session and close socket.
639disconnectPeer :: Wire s a 649disconnectPeer :: Wire s a
640disconnectPeer = monadThrow DisconnectPeer 650disconnectPeer = monadThrow DisconnectPeer
@@ -708,6 +718,7 @@ connectWire session hs addr extCaps chan wire =
708 , connOptions = def 718 , connOptions = def
709 , connState = cstate 719 , connState = cstate
710 , connSession = session 720 , connSession = session
721 , connChan = chan
711 } 722 }
712 723
713-- | Accept 'Wire' connection using already 'Network.Socket.accept'ed 724-- | Accept 'Wire' connection using already 'Network.Socket.accept'ed