summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bittorrent.cabal7
-rw-r--r--examples/Main.hs8
-rw-r--r--src/Network/BitTorrent.hs2
-rw-r--r--src/Network/BitTorrent/Internal.hs14
4 files changed, 17 insertions, 14 deletions
diff --git a/bittorrent.cabal b/bittorrent.cabal
index b3ffbe49..46d04999 100644
--- a/bittorrent.cabal
+++ b/bittorrent.cabal
@@ -127,10 +127,9 @@ executable example
127 , bittorrent 127 , bittorrent
128 , mtl 128 , mtl
129 129
130 ghc-options: -O2 -rtsopts -threaded 130 ghc-options:
131-- -threaded -rtsopts 131-- -threaded -eventlog
132-- -eventlog 132 ghc-prof-options: -rtsopts -auto-all -caf-all
133-- ghc-prof-options: -prof -auto-all -caf-all
134 133
135 if !flag(testing) 134 if !flag(testing)
136 buildable: False 135 buildable: False
diff --git a/examples/Main.hs b/examples/Main.hs
index 8d976aed..18cbefe3 100644
--- a/examples/Main.hs
+++ b/examples/Main.hs
@@ -13,7 +13,7 @@ main = do
13 13
14 print (contentLayout "./" (tInfo torrent)) 14 print (contentLayout "./" (tInfo torrent))
15 15
16 client <- newClient 100 [] 16 client <- newClient 10 []
17 swarm <- newLeecher client torrent 17 swarm <- newLeecher client torrent
18 18
19 storage <- swarm `bindTo` "/tmp/" 19 storage <- swarm `bindTo` "/tmp/"
@@ -22,5 +22,7 @@ main = do
22 22
23 discover swarm $ do 23 discover swarm $ do
24 liftIO $ print "connected to peer" 24 liftIO $ print "connected to peer"
25 forever $ exchange storage 25 forever $ do
26 liftIO $ print "disconnect to peer" \ No newline at end of file 26 liftIO (getCurrentProgress client >>= print)
27 exchange storage
28 liftIO $ print "disconnected" \ No newline at end of file
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs
index 30735023..b6e2eadf 100644
--- a/src/Network/BitTorrent.hs
+++ b/src/Network/BitTorrent.hs
@@ -154,4 +154,4 @@ exchange storage = awaitEvent >>= handler
154 offer <- peerOffer 154 offer <- peerOffer
155 if BF.null offer 155 if BF.null offer
156 then return () 156 then return ()
157 else handler (Available offer) \ No newline at end of file 157 else handler (Available offer)
diff --git a/src/Network/BitTorrent/Internal.hs b/src/Network/BitTorrent/Internal.hs
index bf47b87b..eaeb04e8 100644
--- a/src/Network/BitTorrent/Internal.hs
+++ b/src/Network/BitTorrent/Internal.hs
@@ -153,14 +153,14 @@ uploadedProgress (fromIntegral -> amount) = uploaded +~ amount
153{-# INLINE uploadedProgress #-} 153{-# INLINE uploadedProgress #-}
154 154
155-- | Used when leecher join client session. 155-- | Used when leecher join client session.
156enqueuedProgress :: Int -> Progress -> Progress 156enqueuedProgress :: Integer -> Progress -> Progress
157enqueuedProgress (fromIntegral -> amount) = left +~ amount 157enqueuedProgress amount = left +~ amount
158{-# INLINE enqueuedProgress #-} 158{-# INLINE enqueuedProgress #-}
159 159
160-- | Used when leecher leave client session. 160-- | Used when leecher leave client session.
161-- (e.g. user deletes not completed torrent) 161-- (e.g. user deletes not completed torrent)
162dequeuedProgress :: Int -> Progress -> Progress 162dequeuedProgress :: Integer -> Progress -> Progress
163dequeuedProgress (fromIntegral -> amount) = left -~ amount 163dequeuedProgress amount = left -~ amount
164{-# INLINE dequeuedProgress #-} 164{-# INLINE dequeuedProgress #-}
165 165
166{----------------------------------------------------------------------- 166{-----------------------------------------------------------------------
@@ -349,8 +349,10 @@ newSeeder cs t @ Torrent {..}
349 349
350-- | New swarm in which the client allowed both download and upload. 350-- | New swarm in which the client allowed both download and upload.
351newLeecher :: ClientSession -> Torrent -> IO SwarmSession 351newLeecher :: ClientSession -> Torrent -> IO SwarmSession
352newLeecher cs t @ Torrent {..} 352newLeecher cs t @ Torrent {..} = do
353 = newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t 353 se <- newSwarmSession defLeacherConns (haveNone (pieceCount tInfo)) cs t
354 atomically $ modifyTVar' (currentProgress cs) (enqueuedProgress (contentLength tInfo))
355 return se
354 356
355--isLeacher :: SwarmSession -> IO Bool 357--isLeacher :: SwarmSession -> IO Bool
356--isLeacher = undefined 358--isLeacher = undefined