From 3e61effb90416456f98c3db3224db9c7343eed6c Mon Sep 17 00:00:00 2001 From: Sam T Date: Sun, 14 Jul 2013 03:30:43 +0400 Subject: ~ Remove keepalives stuff. --- src/Network/BitTorrent/Sessions.hs | 44 +------------------------------ src/Network/BitTorrent/Sessions/Types.lhs | 24 ----------------- 2 files changed, 1 insertion(+), 67 deletions(-) (limited to 'src') diff --git a/src/Network/BitTorrent/Sessions.hs b/src/Network/BitTorrent/Sessions.hs index 9a1d0c6a..7fcde20b 100644 --- a/src/Network/BitTorrent/Sessions.hs +++ b/src/Network/BitTorrent/Sessions.hs @@ -43,8 +43,6 @@ module Network.BitTorrent.Sessions , newSeeder , getClientBitfield - -- * Timeouts - , updateIncoming, updateOutcoming , discover ) where @@ -70,8 +68,6 @@ import Network hiding (accept) import Network.Socket import Network.Socket.ByteString -import GHC.Event as Ev - import Data.Bitfield as BF import Data.Torrent import Network.BitTorrent.Extension @@ -144,10 +140,6 @@ startDHT ClientSession {..} nodePort = withRunning peerListener failure start -- usually loaded from configuration file. openClientSession :: SessionCount -> [Extension] -> PortNumber -> PortNumber -> IO ClientSession openClientSession n exts listenerPort _ = do - mgr <- Ev.new - -- TODO kill this thread when leave client - _ <- forkIO $ loop mgr - cs <- ClientSession <$> genPeerId <*> pure exts @@ -156,7 +148,6 @@ openClientSession n exts listenerPort _ = do <*> MSem.new n <*> pure n <*> newTVarIO M.empty - <*> pure mgr <*> newTVarIO (startProgress 0) <*> newTVarIO HM.empty @@ -373,9 +364,7 @@ openSession ss @ SwarmSession {..} addr Handshake {..} = do let clientCaps = encodeExts $ allowedExtensions $ clientSession let enabled = decodeExts (enabledCaps clientCaps hsReserved) ps <- PeerSession addr ss enabled - <$> registerTimeout (eventManager clientSession) maxIncomingTime (return ()) - <*> registerTimeout (eventManager clientSession) maxOutcomingTime (return ()) - <*> atomically (dupTChan broadcastMessages) + <$> atomically (dupTChan broadcastMessages) <*> (newIORef . initialSessionState . totalCount =<< readTVarIO clientBitfield) -- TODO we could implement more interesting throtling scheme -- using connected peer information @@ -460,34 +449,3 @@ listener cs action serverPort = bracket openListener close loop bindSocket sock (SockAddrInet serverPort 0) listen sock 1 return sock - - -{----------------------------------------------------------------------- - Keepalives ------------------------------------------------------------------------- -TODO move to exchange ------------------------------------------------------------------------} - -sec :: Int -sec = 1000 * 1000 - -maxIncomingTime :: Int -maxIncomingTime = 120 * sec - -maxOutcomingTime :: Int -maxOutcomingTime = 1 * sec - --- | Should be called after we have received any message from a peer. -updateIncoming :: PeerSession -> IO () -updateIncoming PeerSession {..} = do - updateTimeout (eventManager (clientSession swarmSession)) - incomingTimeout maxIncomingTime - --- | Should be called before we have send any message to a peer. -updateOutcoming :: PeerSession -> IO () -updateOutcoming PeerSession {..} = - updateTimeout (eventManager (clientSession swarmSession)) - outcomingTimeout maxOutcomingTime - -sendKA :: Socket -> IO () -sendKA sock = return () diff --git a/src/Network/BitTorrent/Sessions/Types.lhs b/src/Network/BitTorrent/Sessions/Types.lhs index 3f9c6db1..855e9a08 100644 --- a/src/Network/BitTorrent/Sessions/Types.lhs +++ b/src/Network/BitTorrent/Sessions/Types.lhs @@ -58,8 +58,6 @@ > import Network -> import GHC.Event as Ev - > import Data.Bitfield as BF > import Data.Torrent > import Network.BitTorrent.Extension @@ -272,8 +270,6 @@ and different enabled extensions at the same time. > -- | Used to traverse the swarm session. > , swarmSessions :: !(TVar (Map InfoHash SwarmSession)) -> , eventManager :: !EventManager - > -- | Used to keep track global client progress. > , currentProgress :: !(TVar Progress) @@ -394,26 +390,6 @@ Peer sessions > -- | Extensions such that both peer and client support. > , enabledExtensions :: [Extension] -To dissconnect from died peers appropriately we should check if a peer -do not sent the KA message within given interval. If yes, we should -throw an exception in 'TimeoutCallback' and close session between -peers. - -We should update timeout if we /receive/ any message within timeout -interval to keep connection up. - -> , incomingTimeout :: !TimeoutKey - -To send KA message appropriately we should know when was last time we -sent a message to a peer. To do that we keep registered timeout in -event manager and if we do not sent any message to the peer within -given interval then we send KA message in 'TimeoutCallback'. - -We should update timeout if we /send/ any message within timeout to -avoid reduntant KA messages. - -> , outcomingTimeout :: !TimeoutKey -> > -- | Broadcast messages waiting to be sent to peer. > , pendingMessages :: !(TChan Message) -- cgit v1.2.3