diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-30 05:18:24 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-30 05:18:24 +0400 |
commit | c15da2e2b376d81671f35e821e94db19e59d5ddd (patch) | |
tree | 7bcc2c929df2dd49f27ef3083eb830344b3d7685 /src/Network/BitTorrent/Exchange.hs | |
parent | f556bf196bf07308f024cc43c1a51dfd4c21188c (diff) |
+ Add very basic storage operations.
Now we can download and make some progress, but very unstable.
Diffstat (limited to 'src/Network/BitTorrent/Exchange.hs')
-rw-r--r-- | src/Network/BitTorrent/Exchange.hs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/Exchange.hs b/src/Network/BitTorrent/Exchange.hs index 505360a4..66112f14 100644 --- a/src/Network/BitTorrent/Exchange.hs +++ b/src/Network/BitTorrent/Exchange.hs | |||
@@ -53,6 +53,7 @@ module Network.BitTorrent.Exchange | |||
53 | , getHaveCount | 53 | , getHaveCount |
54 | , getWantCount | 54 | , getWantCount |
55 | , getPieceCount | 55 | , getPieceCount |
56 | , peerOffer | ||
56 | 57 | ||
57 | -- * Events | 58 | -- * Events |
58 | , Event(..) | 59 | , Event(..) |
@@ -295,6 +296,10 @@ data Event | |||
295 | | Fragment Block | 296 | | Fragment Block |
296 | deriving Show | 297 | deriving Show |
297 | 298 | ||
299 | -- INVARIANT: | ||
300 | -- | ||
301 | -- * Available Bitfield is never empty | ||
302 | -- | ||
298 | 303 | ||
299 | -- | You could think of 'awaitEvent' as wait until something interesting occur. | 304 | -- | You could think of 'awaitEvent' as wait until something interesting occur. |
300 | -- | 305 | -- |
@@ -316,9 +321,7 @@ data Event | |||
316 | -- forall (Fragment block). isPiece block == True | 321 | -- forall (Fragment block). isPiece block == True |
317 | -- | 322 | -- |
318 | awaitEvent :: P2P Event | 323 | awaitEvent :: P2P Event |
319 | awaitEvent = do | 324 | awaitEvent = awaitMessage >>= go |
320 | |||
321 | awaitMessage >>= go | ||
322 | where | 325 | where |
323 | go KeepAlive = awaitEvent | 326 | go KeepAlive = awaitEvent |
324 | go Choke = do | 327 | go Choke = do |
@@ -341,8 +344,7 @@ awaitEvent = do | |||
341 | awaitEvent | 344 | awaitEvent |
342 | 345 | ||
343 | go (Have idx) = do | 346 | go (Have idx) = do |
344 | new <- singletonBF idx | 347 | bitfield %= have idx |
345 | bitfield %= BF.union new | ||
346 | _ <- revise | 348 | _ <- revise |
347 | 349 | ||
348 | offer <- peerOffer | 350 | offer <- peerOffer |