summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Network/BitTorrent/Internal.lhs70
1 files changed, 39 insertions, 31 deletions
diff --git a/src/Network/BitTorrent/Internal.lhs b/src/Network/BitTorrent/Internal.lhs
index 3f8f0371..078920a4 100644
--- a/src/Network/BitTorrent/Internal.lhs
+++ b/src/Network/BitTorrent/Internal.lhs
@@ -170,7 +170,7 @@
170 170
171 171
172Thread layout 172Thread layout
173------------- 173------------------------------------------------------------------------
174 174
175When client session created 2 new threads appear: 175When client session created 2 new threads appear:
176 176
@@ -193,20 +193,19 @@ When client\/swarm\/peer session gets closed kill the corresponding
193threads, but flush data to disc. (for e.g. storage block map) 193threads, but flush data to disc. (for e.g. storage block map)
194 194
195So for e.g., in order to obtain our first block we need to run at 195So for e.g., in order to obtain our first block we need to run at
196least 7 threads: main thread, 2 client session thread, 3 swarm session 196least 7 threads: main thread, 2 client session threads, 3 swarm session
197threads and PeerSession thread. 197threads and PeerSession thread.
198 198
199> {----------------------------------------------------------------------- 199Thread throttling
200> Client session 200------------------------------------------------------------------------
201> -----------------------------------------------------------------------}
202 201
203> {- NOTE: If we will not restrict number of threads we could end up 202If we will not restrict number of threads we could end up
204> with thousands of connected swarm and make no particular progress. 203with thousands of connected swarm and make no particular progress.
205> 204
206> Note also we do not bound number of swarms! This is not optimal 205Note also we do not bound number of swarms! This is not optimal
207> strategy because each swarm might have say 1 thread and we could end 206strategy because each swarm might have say 1 thread and we could end
208> up bounded by the meaningless limit. Bounding global number of p2p 207up bounded by the meaningless limit. Bounding global number of p2p
209> sessions should work better, and simpler.-} 208sessions should work better, and simpler.
210 209
211> -- | Each client might have a limited number of threads. 210> -- | Each client might have a limited number of threads.
212> type ThreadCount = Int 211> type ThreadCount = Int
@@ -215,16 +214,28 @@ threads and PeerSession thread.
215> defaultThreadCount :: ThreadCount 214> defaultThreadCount :: ThreadCount
216> defaultThreadCount = 1000 215> defaultThreadCount = 1000
217 216
218> {- PERFORMANCE NOTE: keeping torrent metafiles in memory is a _bad_ 217Torrent Map
219> idea: for 1TB of data we need at least 100MB of metadata. (using 256KB 218------------------------------------------------------------------------
220> piece size). This solution do not scale further. Solution with 219
221> TorrentLoc is much better and takes much more less space, moreover it 220TorrentMap is used to keep track all known torrents for the
222> depends on count of torrents but not on count of data itself. To scale 221client. When some peer trying to connect to us it's necessary to
223> further, in future we might add something like database (for 222dispatch appropriate 'SwarmSession' (or start new one if there are
224> e.g. sqlite) for this kind of things.-} 223none) in the listener loop: we only know 'InfoHash' from 'Handshake'
225 224but nothing more. So to accept new 'PeerSession' we need to lookup
226> -- | Identifies location of 225torrent metainfo and content files (if there are some) by the
226'InfoHash' and only after that enter exchange loop.
227
228*PERFORMANCE NOTE:* keeping torrent metafiles in memory is a _bad_
229idea: for 1TB of data we need at least 100MB of metadata. (using 256KB
230piece size). This solution do not scale further. Solution with
231TorrentLoc is much better and takes much more less space, moreover it
232depends on count of torrents but not on count of data itself. To scale
233further, in future we might add something like database (for
234e.g. sqlite) for this kind of things.
235
236> -- | Local identification info location about
227> data TorrentLoc = TorrentLoc { 237> data TorrentLoc = TorrentLoc {
238> -- |
228> metafilePath :: FilePath 239> metafilePath :: FilePath
229> , dataPath :: FilePath 240> , dataPath :: FilePath
230> } 241> }
@@ -232,19 +243,16 @@ threads and PeerSession thread.
232> validateTorrent :: TorrentLoc -> IO () 243> validateTorrent :: TorrentLoc -> IO ()
233> validateTorrent = error "validateTorrent: not implemented" 244> validateTorrent = error "validateTorrent: not implemented"
234 245
235> -- | TorrentMap is used to keep track all known torrents for the 246
236> -- client. When some peer trying to connect to us it's necessary to
237> -- dispatch appropriate 'SwarmSession' (or start new one if there are
238> -- none) in the listener loop: we only know 'InfoHash' from
239> -- 'Handshake' but nothing more. So to accept new 'PeerSession' we
240> -- need to lookup torrent metainfo and content files (if there are
241> -- some) by the 'InfoHash' and only after that enter exchange loop.
242> -- 247> --
243> type TorrentMap = HashMap InfoHash TorrentLoc 248> type TorrentMap = HashMap InfoHash TorrentLoc
244 249
245> {- NOTE: basically, client session should contain options which user 250Client session
246> app store in configuration files. (related to the protocol) Moreover 251------------------------------------------------------------------------
247> it should contain the all client identification info. (e.g. DHT) -} 252
253Basically, client session should contain options which user app store
254in configuration files. (related to the protocol) Moreover it should
255contain the all client identification info. (e.g. DHT)
248 256
249> -- | Client session is the basic unit of bittorrent network, it has: 257> -- | Client session is the basic unit of bittorrent network, it has:
250> -- 258> --