diff options
Diffstat (limited to 'src/Network/BitTorrent/Discovery.hs')
-rw-r--r-- | src/Network/BitTorrent/Discovery.hs | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/src/Network/BitTorrent/Discovery.hs b/src/Network/BitTorrent/Discovery.hs index 770ae818..1b9e7b26 100644 --- a/src/Network/BitTorrent/Discovery.hs +++ b/src/Network/BitTorrent/Discovery.hs | |||
@@ -41,16 +41,14 @@ discover swarm @ SwarmSession {..} action = {-# SCC discover #-} do | |||
41 | 41 | ||
42 | startListener :: ClientSession -> PortNumber -> IO () | 42 | startListener :: ClientSession -> PortNumber -> IO () |
43 | startListener cs @ ClientSession {..} port = | 43 | startListener cs @ ClientSession {..} port = |
44 | putMVar peerListener =<< startService port (listener cs (error "listener")) | 44 | startService peerListener port $ listener cs (error "listener") |
45 | 45 | ||
46 | startDHT :: ClientSession -> PortNumber -> IO () | 46 | startDHT :: ClientSession -> PortNumber -> IO () |
47 | startDHT ClientSession {..} nodePort = do | 47 | startDHT ClientSession {..} nodePort = withRunning peerListener failure start |
48 | maybe failure start =<< tryTakeMVar peerListener | ||
49 | where | 48 | where |
50 | start ClientService {..} = do | 49 | start ClientService {..} = do |
51 | ses <- newNodeSession servPort | 50 | ses <- newNodeSession servPort |
52 | serv <- startService nodePort (dhtServer ses) | 51 | startService nodeListener nodePort (dhtServer ses) |
53 | putMVar nodeListener serv | ||
54 | 52 | ||
55 | failure = throwIO $ userError msg | 53 | failure = throwIO $ userError msg |
56 | msg = "unable to start DHT server: peer listener is not running" | 54 | msg = "unable to start DHT server: peer listener is not running" |