summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Exchange/Message.hs6
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs2
-rw-r--r--src/Network/BitTorrent/Exchange/Wire.hs34
3 files changed, 22 insertions, 20 deletions
diff --git a/src/Network/BitTorrent/Exchange/Message.hs b/src/Network/BitTorrent/Exchange/Message.hs
index d0d2bb03..7748f843 100644
--- a/src/Network/BitTorrent/Exchange/Message.hs
+++ b/src/Network/BitTorrent/Exchange/Message.hs
@@ -62,6 +62,7 @@ module Network.BitTorrent.Exchange.Message
62 , StatusUpdate (..) 62 , StatusUpdate (..)
63 , Available (..) 63 , Available (..)
64 , Transfer (..) 64 , Transfer (..)
65 , defaultRequestQueueLength
65 66
66 -- ** Fast extension 67 -- ** Fast extension
67 , FastMessage (..) 68 , FastMessage (..)
@@ -483,6 +484,11 @@ instance PeerMessage Transfer where
483 stats (Piece p ) = ByteStats (4 + 1) (4 + 4 + blockSize p) 0 484 stats (Piece p ) = ByteStats (4 + 1) (4 + 4 + blockSize p) 0
484 stats (Cancel _ ) = ByteStats (4 + 1) (3 * 4) 0 485 stats (Cancel _ ) = ByteStats (4 + 1) (3 * 4) 0
485 486
487-- TODO increase
488-- | Max number of pending 'Request's inflight.
489defaultRequestQueueLength :: Int
490defaultRequestQueueLength = 1
491
486{----------------------------------------------------------------------- 492{-----------------------------------------------------------------------
487-- Fast messages 493-- Fast messages
488-----------------------------------------------------------------------} 494-----------------------------------------------------------------------}
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs
index 416e00fd..1e72ba96 100644
--- a/src/Network/BitTorrent/Exchange/Session.hs
+++ b/src/Network/BitTorrent/Exchange/Session.hs
@@ -191,7 +191,7 @@ sendBroadcast msg = do
191 191
192fillRequestQueue :: Wire Session () 192fillRequestQueue :: Wire Session ()
193fillRequestQueue = do 193fillRequestQueue = do
194 maxN <- lift $ getAdvertisedQueueLength 194 maxN <- lift getMaxQueueLength
195 rbf <- use connBitfield 195 rbf <- use connBitfield
196 addr <- asks connRemoteAddr 196 addr <- asks connRemoteAddr
197 blks <- withStatusUpdates $ do 197 blks <- withStatusUpdates $ do
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