From 12cbb3af2413dc28838ed271351dda16df8f7bdb Mon Sep 17 00:00:00 2001 From: joe Date: Fri, 15 Sep 2017 06:22:10 -0400 Subject: Separating dht-client library from bittorrent package. --- bittorrent/bench/Throughtput.hs | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 bittorrent/bench/Throughtput.hs (limited to 'bittorrent/bench/Throughtput.hs') diff --git a/bittorrent/bench/Throughtput.hs b/bittorrent/bench/Throughtput.hs new file mode 100644 index 00000000..d0404405 --- /dev/null +++ b/bittorrent/bench/Throughtput.hs @@ -0,0 +1,46 @@ +{-# LANGUAGE ViewPatterns #-} +{-# LANGUAGE PatternGuards #-} +module Main (main) where + +import Control.Concurrent +import Data.Bitfield +import Network.BitTorrent +import System.Environment +import Control.Monad.Reader +import Data.IORef + + +main :: IO () +main = do + [path] <- getArgs + torrent <- fromFile path + + print (contentLayout "./" (tInfo torrent)) + + client <- newClient 100 [] + swarm <- newLeecher client torrent + + ref <- liftIO $ newIORef 0 + discover swarm $ do + forever $ do + e <- awaitEvent + case e of + Available bf + | Just m <- findMin bf -> yieldEvent (Want (BlockIx m 0 10)) + | otherwise -> return () + Want bix -> liftIO $ print bix + Fragment blk -> do + + sc <- liftIO $ getSessionCount swarm + addr <- asks connectedPeerAddr + + liftIO $ do + x <- atomicModifyIORef ref (\x -> (succ x, x)) + if x `mod` 100 == 0 + then print (x, sc, addr) + else return () + + yieldEvent (Want (BlockIx 0 0 (16 * 1024))) + + + print "Bye-bye! =_=" \ No newline at end of file -- cgit v1.2.3