diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-26 07:42:57 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-04-26 07:42:57 +0400 |
commit | a7fda9d39ed82cb9d3ad0c28e76e88e59539a492 (patch) | |
tree | 925183a691bbb57ca5f7140614e1fdbc610b3b1e /src/Network/BitTorrent/Exchange/Session.hs | |
parent | 4587ffd5406162bb06a6549ffd2ff277e0a93916 (diff) | |
parent | 85bf8475bbbce79b1bedde641192fa945614283d (diff) |
Merge branch 'tidy' into dev
Diffstat (limited to 'src/Network/BitTorrent/Exchange/Session.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 26 |
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 | |||
45 | import System.Log.FastLogger (LogStr, ToLogStr (..)) | 45 | import System.Log.FastLogger (LogStr, ToLogStr (..)) |
46 | 46 | ||
47 | import Data.BEncode as BE | 47 | import Data.BEncode as BE |
48 | import Data.Torrent (InfoDict (..)) | 48 | import Data.Torrent as Torrent |
49 | import Data.Torrent.Bitfield as BF | ||
50 | import Data.Torrent.InfoHash | ||
51 | import Data.Torrent.Piece | ||
52 | import qualified Data.Torrent.Piece as Torrent (Piece ()) | ||
53 | import Network.BitTorrent.Internal.Types | 49 | import Network.BitTorrent.Internal.Types |
54 | import Network.BitTorrent.Core | 50 | import Network.BitTorrent.Address |
51 | import Network.BitTorrent.Exchange.Bitfield as BF | ||
55 | import Network.BitTorrent.Exchange.Block as Block | 52 | import Network.BitTorrent.Exchange.Block as Block |
56 | import Network.BitTorrent.Exchange.Connection | 53 | import Network.BitTorrent.Exchange.Connection |
54 | import Network.BitTorrent.Exchange.Download as D | ||
57 | import Network.BitTorrent.Exchange.Message as Message | 55 | import Network.BitTorrent.Exchange.Message as Message |
58 | import Network.BitTorrent.Exchange.Session.Metadata as Metadata | ||
59 | import Network.BitTorrent.Exchange.Session.Status as SS | ||
60 | import System.Torrent.Storage | 56 | import System.Torrent.Storage |
61 | 57 | ||
62 | {----------------------------------------------------------------------- | 58 | {----------------------------------------------------------------------- |
@@ -93,13 +89,13 @@ type LogFun = Loc -> LogSource -> LogLevel -> LogStr -> IO () | |||
93 | 89 | ||
94 | data SessionState | 90 | data 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 |
109 | newSessionState rootPath (Right dict) = do | 105 | newSessionState 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 | ||
115 | closeSessionState :: SessionState -> IO () | 112 | closeSessionState :: SessionState -> IO () |
@@ -119,8 +116,9 @@ closeSessionState HavingMetadata {..} = close contentStorage | |||
119 | haveMetadata :: InfoDict -> SessionState -> IO SessionState | 116 | haveMetadata :: InfoDict -> SessionState -> IO SessionState |
120 | haveMetadata dict WaitingMetadata {..} = do | 117 | haveMetadata 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 |