diff options
author | Sam T <pxqr.sta@gmail.com> | 2013-06-13 06:32:45 +0400 |
---|---|---|
committer | Sam T <pxqr.sta@gmail.com> | 2013-06-13 06:32:45 +0400 |
commit | 49caf224c2d51cae2ca2a345e9bcca4368e66701 (patch) | |
tree | df778b5f24f110b38fa8b211a322f681e024cae9 /src/Network/BitTorrent.hs | |
parent | 6042f69d711cddc0bb42457e0d16d45e7b34e431 (diff) |
~ Bound count of concurrent sessions.
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r-- | src/Network/BitTorrent.hs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/Network/BitTorrent.hs b/src/Network/BitTorrent.hs index 85571470..b9dc39eb 100644 --- a/src/Network/BitTorrent.hs +++ b/src/Network/BitTorrent.hs | |||
@@ -29,8 +29,10 @@ module Network.BitTorrent | |||
29 | , awaitEvent, yieldEvent | 29 | , awaitEvent, yieldEvent |
30 | ) where | 30 | ) where |
31 | 31 | ||
32 | import Control.Concurrent | ||
32 | import Control.Exception | 33 | import Control.Exception |
33 | import Control.Monad | 34 | import Control.Monad |
35 | import Control.Monad.Reader | ||
34 | 36 | ||
35 | import Network | 37 | import Network |
36 | 38 | ||
@@ -41,9 +43,8 @@ import Network.BitTorrent.Exchange.Protocol | |||
41 | import Network.BitTorrent.Tracker | 43 | import Network.BitTorrent.Tracker |
42 | 44 | ||
43 | 45 | ||
44 | |||
45 | -- discover should hide tracker and DHT communication under the hood | 46 | -- discover should hide tracker and DHT communication under the hood |
46 | -- thus we can obtain unified interface | 47 | -- thus we can obtain an unified interface |
47 | 48 | ||
48 | discover :: SwarmSession -> P2P () -> IO () | 49 | discover :: SwarmSession -> P2P () -> IO () |
49 | discover swarm action = do | 50 | discover swarm action = do |
@@ -58,14 +59,14 @@ discover swarm action = do | |||
58 | 59 | ||
59 | putStrLn "lookup peers" | 60 | putStrLn "lookup peers" |
60 | withTracker progress conn $ \tses -> do | 61 | withTracker progress conn $ \tses -> do |
62 | putStrLn "get peer list " | ||
61 | forever $ do | 63 | forever $ do |
62 | addr <- getPeerAddr tses | 64 | addr <- getPeerAddr tses |
63 | putStrLn "connecting to peer" | 65 | putStrLn "connect to peer" |
64 | handle handler (withPeer swarm addr action) | 66 | spawnP2P swarm addr $ do |
65 | 67 | liftIO $ putStrLn "run p2p session" | |
66 | where | 68 | action |
67 | handler :: IOException -> IO () | 69 | putStrLn "connected" |
68 | handler _ = return () | ||
69 | 70 | ||
70 | listener :: SwarmSession -> P2P () -> IO PortNumber | 71 | listener :: SwarmSession -> P2P () -> IO PortNumber |
71 | listener _ _ = do | 72 | listener _ _ = do |