summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent.hs
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-06-13 06:32:45 +0400
committerSam T <pxqr.sta@gmail.com>2013-06-13 06:32:45 +0400
commit49caf224c2d51cae2ca2a345e9bcca4368e66701 (patch)
treedf778b5f24f110b38fa8b211a322f681e024cae9 /src/Network/BitTorrent.hs
parent6042f69d711cddc0bb42457e0d16d45e7b34e431 (diff)
~ Bound count of concurrent sessions.
Diffstat (limited to 'src/Network/BitTorrent.hs')
-rw-r--r--src/Network/BitTorrent.hs17
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
32import Control.Concurrent
32import Control.Exception 33import Control.Exception
33import Control.Monad 34import Control.Monad
35import Control.Monad.Reader
34 36
35import Network 37import Network
36 38
@@ -41,9 +43,8 @@ import Network.BitTorrent.Exchange.Protocol
41import Network.BitTorrent.Tracker 43import 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
48discover :: SwarmSession -> P2P () -> IO () 49discover :: SwarmSession -> P2P () -> IO ()
49discover swarm action = do 50discover 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
70listener :: SwarmSession -> P2P () -> IO PortNumber 71listener :: SwarmSession -> P2P () -> IO PortNumber
71listener _ _ = do 72listener _ _ = do