diff options
Diffstat (limited to 'src/Network')
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session.hs | 21 | ||||
-rw-r--r-- | src/Network/BitTorrent/Exchange/Session/Metadata.hs | 7 |
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 | ||
17 | import Control.Applicative | 20 | import 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 | ||
132 | closeSession :: Session -> IO () | 138 | closeSession :: Session -> IO () |
@@ -134,6 +140,9 @@ closeSession ses = do | |||
134 | deleteAll ses | 140 | deleteAll ses |
135 | undefined | 141 | undefined |
136 | 142 | ||
143 | waitMetadata :: Session -> IO InfoDict | ||
144 | waitMetadata 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 #-} |
2 | module Network.BitTorrent.Exchange.Session.Metadata | 2 | module 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 | |||
33 | import Network.BitTorrent.Exchange.Message as Message hiding (Status) | 33 | import Network.BitTorrent.Exchange.Message as Message hiding (Status) |
34 | 34 | ||
35 | 35 | ||
36 | -- | Current transfer status. | ||
36 | data Status = Status | 37 | data Status = Status |
37 | { _pending :: [(PeerAddr IP, PieceIx)] | 38 | { _pending :: [(PeerAddr IP, PieceIx)] |
38 | , _bucket :: Bucket | 39 | , _bucket :: Bucket |