summaryrefslogtreecommitdiff
path: root/src/Network
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-26 08:00:16 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-26 08:00:16 +0400
commit8526ebaa230d98f70654e6bcfc64dcd511712f7b (patch)
tree0e8d3b10dd400bb982cffb574c5287a6d9351042 /src/Network
parent1c38e5857764fe2ab8cb5ec55b31f13239278599 (diff)
Minor refactoring
Diffstat (limited to 'src/Network')
-rw-r--r--src/Network/BitTorrent/Exchange/Session.hs21
-rw-r--r--src/Network/BitTorrent/Exchange/Session/Metadata.hs7
2 files changed, 19 insertions, 9 deletions
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
12 , Network.BitTorrent.Exchange.Session.attach 12 , Network.BitTorrent.Exchange.Session.attach
13 , Network.BitTorrent.Exchange.Session.delete 13 , Network.BitTorrent.Exchange.Session.delete
14 , Network.BitTorrent.Exchange.Session.deleteAll 14 , Network.BitTorrent.Exchange.Session.deleteAll
15
16 -- * Events
17 , waitMetadata
15 ) where 18 ) where
16 19
17import Control.Applicative 20import Control.Applicative
@@ -86,12 +89,11 @@ data Session = Session
86 , status :: !(MVar SessionStatus) 89 , status :: !(MVar SessionStatus)
87 , storage :: !(Storage) 90 , storage :: !(Storage)
88 91
89 , broadcast :: !(Chan Message)
90
91 , unchoked :: [PeerAddr IP]
92 , connectionsPrefs :: !ConnectionPrefs 92 , connectionsPrefs :: !ConnectionPrefs
93 , connectionsPending :: !(TVar (Set (PeerAddr IP))) 93 , connectionsPending :: !(TVar (Set (PeerAddr IP)))
94 , connectionsEstablished :: !(TVar (Map (PeerAddr IP) (Connection Session))) 94 , connectionsEstablished :: !(TVar (Map (PeerAddr IP) (Connection Session)))
95 , connectionsUnchoked :: [PeerAddr IP]
96 , broadcast :: !(Chan Message)
95 97
96 , logger :: !(LogFun) 98 , logger :: !(LogFun)
97 } 99 }
@@ -117,16 +119,20 @@ newSession logFun addr rootPath dict = do
117 return Session 119 return Session
118 { sessionPeerId = pid 120 { sessionPeerId = pid
119 , sessionTopic = idInfoHash dict 121 , sessionTopic = idInfoHash dict
122
123 , metadata = undefined
124 , infodict = undefined
125
120 , status = statusVar 126 , status = statusVar
121 , storage = store 127 , storage = store
122 , unchoked = [] 128
123 , connectionsPrefs = def 129 , connectionsPrefs = def
124 , connectionsPending = pconnVar 130 , connectionsPending = pconnVar
125 , connectionsEstablished = econnVar 131 , connectionsEstablished = econnVar
132 , connectionsUnchoked = []
126 , broadcast = chan 133 , broadcast = chan
134
127 , logger = logFun 135 , logger = logFun
128 , metadata = undefined
129 , infodict = undefined
130 } 136 }
131 137
132closeSession :: Session -> IO () 138closeSession :: Session -> IO ()
@@ -134,6 +140,9 @@ closeSession ses = do
134 deleteAll ses 140 deleteAll ses
135 undefined 141 undefined
136 142
143waitMetadata :: Session -> IO InfoDict
144waitMetadata Session {..} = cachedValue <$> readMVar infodict
145
137{----------------------------------------------------------------------- 146{-----------------------------------------------------------------------
138-- Logging 147-- Logging
139-----------------------------------------------------------------------} 148-----------------------------------------------------------------------}
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 @@
1{-# LANGUAGE TemplateHaskell #-} 1{-# LANGUAGE TemplateHaskell #-}
2module Network.BitTorrent.Exchange.Session.Metadata 2module Network.BitTorrent.Exchange.Session.Metadata
3 ( -- * Metadata transfer state 3 ( -- * Transfer state
4 Status 4 Status
5 , nullStatus 5 , nullStatus
6 6
7 -- * Metadata updates 7 -- * State updates
8 , Updates 8 , Updates
9 , runUpdates 9 , runUpdates
10 10
11 -- * Metadata piece control 11 -- * Piece transfer control
12 , scheduleBlock 12 , scheduleBlock
13 , resetPending 13 , resetPending
14 , cancelPending 14 , cancelPending
@@ -33,6 +33,7 @@ import Network.BitTorrent.Exchange.Block as Block
33import Network.BitTorrent.Exchange.Message as Message hiding (Status) 33import Network.BitTorrent.Exchange.Message as Message hiding (Status)
34 34
35 35
36-- | Current transfer status.
36data Status = Status 37data Status = Status
37 { _pending :: [(PeerAddr IP, PieceIx)] 38 { _pending :: [(PeerAddr IP, PieceIx)]
38 , _bucket :: Bucket 39 , _bucket :: Bucket