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 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/Network/BitTorrent/Exchange/Session.hs') 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 -----------------------------------------------------------------------} -- cgit v1.2.3