From 8526ebaa230d98f70654e6bcfc64dcd511712f7b Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Wed, 26 Feb 2014 08:00:16 +0400 Subject: Minor refactoring --- src/Network/BitTorrent/Exchange/Session.hs | 21 +++++++++++++++------ src/Network/BitTorrent/Exchange/Session/Metadata.hs | 7 ++++--- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs index be8d3835..921571f5 100644 --- a/src/Network/BitTorrent/Exchange/Session.hs +++ b/src/Network/BitTorrent/Exchange/Session.hs @@ -12,6 +12,9 @@ module Network.BitTorrent.Exchange.Session , Network.BitTorrent.Exchange.Session.attach , Network.BitTorrent.Exchange.Session.delete , Network.BitTorrent.Exchange.Session.deleteAll + + -- * Events + , waitMetadata ) where import Control.Applicative @@ -86,12 +89,11 @@ data Session = Session , status :: !(MVar SessionStatus) , storage :: !(Storage) - , broadcast :: !(Chan Message) - - , unchoked :: [PeerAddr IP] , connectionsPrefs :: !ConnectionPrefs , connectionsPending :: !(TVar (Set (PeerAddr IP))) , connectionsEstablished :: !(TVar (Map (PeerAddr IP) (Connection Session))) + , connectionsUnchoked :: [PeerAddr IP] + , broadcast :: !(Chan Message) , logger :: !(LogFun) } @@ -117,16 +119,20 @@ newSession logFun addr rootPath dict = do return Session { sessionPeerId = pid , sessionTopic = idInfoHash dict + + , metadata = undefined + , infodict = undefined + , status = statusVar , storage = store - , unchoked = [] + , connectionsPrefs = def , connectionsPending = pconnVar , connectionsEstablished = econnVar + , connectionsUnchoked = [] , broadcast = chan + , logger = logFun - , metadata = undefined - , infodict = undefined } closeSession :: Session -> IO () @@ -134,6 +140,9 @@ closeSession ses = do deleteAll ses undefined +waitMetadata :: Session -> IO InfoDict +waitMetadata Session {..} = cachedValue <$> readMVar infodict + {----------------------------------------------------------------------- -- Logging -----------------------------------------------------------------------} diff --git a/src/Network/BitTorrent/Exchange/Session/Metadata.hs b/src/Network/BitTorrent/Exchange/Session/Metadata.hs index 02c2269f..79fd03b0 100644 --- a/src/Network/BitTorrent/Exchange/Session/Metadata.hs +++ b/src/Network/BitTorrent/Exchange/Session/Metadata.hs @@ -1,14 +1,14 @@ {-# LANGUAGE TemplateHaskell #-} module Network.BitTorrent.Exchange.Session.Metadata - ( -- * Metadata transfer state + ( -- * Transfer state Status , nullStatus - -- * Metadata updates + -- * State updates , Updates , runUpdates - -- * Metadata piece control + -- * Piece transfer control , scheduleBlock , resetPending , cancelPending @@ -33,6 +33,7 @@ import Network.BitTorrent.Exchange.Block as Block import Network.BitTorrent.Exchange.Message as Message hiding (Status) +-- | Current transfer status. data Status = Status { _pending :: [(PeerAddr IP, PieceIx)] , _bucket :: Bucket -- cgit v1.2.3