summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange/Wire.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Wire.hs')
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/Network/BitTorrent/Exchange/Wire.hs b/src/Network/BitTorrent/Exchange/Wire.hs
index e88b3ae5..4aebdd24 100644
--- a/src/Network/BitTorrent/Exchange/Wire.hs
+++ b/src/Network/BitTorrent/Exchange/Wire.hs
@@ -52,7 +52,7 @@ module Network.BitTorrent.Exchange.Wire
52 , recvMessage 52 , recvMessage
53 , sendMessage 53 , sendMessage
54 , filterQueue 54 , filterQueue
55 , getAdvertisedQueueLength 55 , getMaxQueueLength
56 56
57 -- * Query 57 -- * Query
58 , getMetadata 58 , getMetadata
@@ -404,6 +404,8 @@ data Options = Options
404 -- send any message for this period of time. 404 -- send any message for this period of time.
405 , keepaliveTimeout :: {-# UNPACK #-} !Int 405 , keepaliveTimeout :: {-# UNPACK #-} !Int
406 406
407 , requestQueueLength :: {-# UNPACK #-} !Int
408
407 -- | Used to protect against flood attacks. 409 -- | Used to protect against flood attacks.
408 , floodDetector :: FloodDetector 410 , floodDetector :: FloodDetector
409 411
@@ -434,11 +436,12 @@ data Options = Options
434-- change them. 436-- change them.
435instance Default Options where 437instance Default Options where
436 def = Options 438 def = Options
437 { keepaliveInterval = defaultKeepAliveInterval 439 { keepaliveInterval = defaultKeepAliveInterval
438 , keepaliveTimeout = defaultKeepAliveTimeout 440 , keepaliveTimeout = defaultKeepAliveTimeout
439 , floodDetector = def 441 , requestQueueLength = defaultRequestQueueLength
440 , metadataFactor = defaultMetadataFactor 442 , floodDetector = def
441 , maxInfoDictSize = defaultMaxInfoDictSize 443 , metadataFactor = defaultMetadataFactor
444 , maxInfoDictSize = defaultMaxInfoDictSize
442 } 445 }
443 446
444{----------------------------------------------------------------------- 447{-----------------------------------------------------------------------
@@ -591,19 +594,6 @@ instance MonadState ConnectionState (Connected s) where
591type Wire s a = ConduitM Message Message (Connected s) a 594type Wire s a = ConduitM Message Message (Connected s) a
592 595
593{----------------------------------------------------------------------- 596{-----------------------------------------------------------------------
594-- Query
595-----------------------------------------------------------------------}
596
597-- TODO configurable
598defQueueLength :: Int
599defQueueLength = 1
600
601getAdvertisedQueueLength :: Connected s Int
602getAdvertisedQueueLength = do
603 ExtendedHandshake {..} <- use connRemoteEhs
604 return $ fromMaybe defQueueLength ehsQueueLength
605
606{-----------------------------------------------------------------------
607-- Wrapper 597-- Wrapper
608-----------------------------------------------------------------------} 598-----------------------------------------------------------------------}
609 599
@@ -661,6 +651,12 @@ sendMessage msg = do
661 ecaps <- use connExtCaps 651 ecaps <- use connExtCaps
662 yield $ envelop ecaps msg 652 yield $ envelop ecaps msg
663 653
654getMaxQueueLength :: Connected s Int
655getMaxQueueLength = do
656 advertisedLen <- ehsQueueLength <$> use connRemoteEhs
657 defaultLen <- asks (requestQueueLength . connOptions)
658 return $ fromMaybe defaultLen advertisedLen
659
664-- | Filter pending messages from send buffer. 660-- | Filter pending messages from send buffer.
665filterQueue :: (Message -> Bool) -> Wire s () 661filterQueue :: (Message -> Bool) -> Wire s ()
666filterQueue p = lift $ do 662filterQueue p = lift $ do