summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/Exchange/Session.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-04-26 07:42:57 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-04-26 07:42:57 +0400
commita7fda9d39ed82cb9d3ad0c28e76e88e59539a492 (patch)
tree925183a691bbb57ca5f7140614e1fdbc610b3b1e /src/Network/BitTorrent/Exchange/Session.hs
parent4587ffd5406162bb06a6549ffd2ff277e0a93916 (diff)
parent85bf8475bbbce79b1bedde641192fa945614283d (diff)
Merge branch 'tidy' into dev
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Session.hs')
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/Network/BitTorrent/Exchange/Session.hs b/src/Network/BitTorrent/Exchange/Session.hs
index 6f480ce4..30b7ed0e 100644
--- a/src/Network/BitTorrent/Exchange/Session.hs
+++ b/src/Network/BitTorrent/Exchange/Session.hs
@@ -45,18 +45,14 @@ import Text.PrettyPrint.Class
45import System.Log.FastLogger (LogStr, ToLogStr (..)) 45import System.Log.FastLogger (LogStr, ToLogStr (..))
46 46
47import Data.BEncode as BE 47import Data.BEncode as BE
48import Data.Torrent (InfoDict (..)) 48import Data.Torrent as Torrent
49import Data.Torrent.Bitfield as BF
50import Data.Torrent.InfoHash
51import Data.Torrent.Piece
52import qualified Data.Torrent.Piece as Torrent (Piece ())
53import Network.BitTorrent.Internal.Types 49import Network.BitTorrent.Internal.Types
54import Network.BitTorrent.Core 50import Network.BitTorrent.Address
51import Network.BitTorrent.Exchange.Bitfield as BF
55import Network.BitTorrent.Exchange.Block as Block 52import Network.BitTorrent.Exchange.Block as Block
56import Network.BitTorrent.Exchange.Connection 53import Network.BitTorrent.Exchange.Connection
54import Network.BitTorrent.Exchange.Download as D
57import Network.BitTorrent.Exchange.Message as Message 55import Network.BitTorrent.Exchange.Message as Message
58import Network.BitTorrent.Exchange.Session.Metadata as Metadata
59import Network.BitTorrent.Exchange.Session.Status as SS
60import System.Torrent.Storage 56import System.Torrent.Storage
61 57
62{----------------------------------------------------------------------- 58{-----------------------------------------------------------------------
@@ -93,13 +89,13 @@ type LogFun = Loc -> LogSource -> LogLevel -> LogStr -> IO ()
93 89
94data SessionState 90data SessionState
95 = WaitingMetadata 91 = WaitingMetadata
96 { metadataDownload :: MVar Metadata.Status 92 { metadataDownload :: MVar MetadataDownload
97 , metadataCompleted :: MVar InfoDict -- ^ used to unblock waiters 93 , metadataCompleted :: MVar InfoDict -- ^ used to unblock waiters
98 , contentRootPath :: FilePath 94 , contentRootPath :: FilePath
99 } 95 }
100 | HavingMetadata 96 | HavingMetadata
101 { metadataCache :: Cached InfoDict 97 { metadataCache :: Cached InfoDict
102 , contentDownload :: MVar SessionStatus 98 , contentDownload :: MVar ContentDownload
103 , contentStorage :: Storage 99 , contentStorage :: Storage
104 } 100 }
105 101
@@ -108,8 +104,9 @@ newSessionState rootPath (Left ih ) = do
108 WaitingMetadata <$> newMVar def <*> newEmptyMVar <*> pure rootPath 104 WaitingMetadata <$> newMVar def <*> newEmptyMVar <*> pure rootPath
109newSessionState rootPath (Right dict) = do 105newSessionState rootPath (Right dict) = do
110 storage <- openInfoDict ReadWriteEx rootPath dict 106 storage <- openInfoDict ReadWriteEx rootPath dict
111 download <- newMVar $ sessionStatus (BF.haveNone (totalPieces storage)) 107 download <- newMVar $ D.contentDownload (BF.haveNone (totalPieces storage))
112 (piPieceLength (idPieceInfo dict)) 108 (piPieceLength (idPieceInfo dict))
109 storage
113 return $ HavingMetadata (cache dict) download storage 110 return $ HavingMetadata (cache dict) download storage
114 111
115closeSessionState :: SessionState -> IO () 112closeSessionState :: SessionState -> IO ()
@@ -119,8 +116,9 @@ closeSessionState HavingMetadata {..} = close contentStorage
119haveMetadata :: InfoDict -> SessionState -> IO SessionState 116haveMetadata :: InfoDict -> SessionState -> IO SessionState
120haveMetadata dict WaitingMetadata {..} = do 117haveMetadata dict WaitingMetadata {..} = do
121 storage <- openInfoDict ReadWriteEx contentRootPath dict 118 storage <- openInfoDict ReadWriteEx contentRootPath dict
122 download <- newMVar $ sessionStatus (BF.haveNone (totalPieces storage)) 119 download <- newMVar $ D.contentDownload (BF.haveNone (totalPieces storage))
123 (piPieceLength (idPieceInfo dict)) 120 (piPieceLength (idPieceInfo dict))
121 storage
124 return HavingMetadata 122 return HavingMetadata
125 { metadataCache = cache dict 123 { metadataCache = cache dict
126 , contentDownload = download 124 , contentDownload = download