summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent
diff options
context:
space:
mode:
authorjoe <joe@jerkface.net>2017-01-23 22:32:17 -0500
committerjoe <joe@jerkface.net>2017-01-23 22:33:08 -0500
commit058ccb22f43e9053fa37ed719d31c72dd6dac27c (patch)
treef6faea43c0b4cc9428e0b8cb8d0b836a9ec13107 /src/Network/BitTorrent
parent6a2506745dd06ad0849a1b0d440ad9751a69cf81 (diff)
Added thread-debug flag and "threads" command.
Diffstat (limited to 'src/Network/BitTorrent')
-rw-r--r--src/Network/BitTorrent/DHT/Query.hs13
-rw-r--r--src/Network/BitTorrent/DHT/Session.hs4
2 files changed, 15 insertions, 2 deletions
diff --git a/src/Network/BitTorrent/DHT/Query.hs b/src/Network/BitTorrent/DHT/Query.hs
index 73b3d492..47d17622 100644
--- a/src/Network/BitTorrent/DHT/Query.hs
+++ b/src/Network/BitTorrent/DHT/Query.hs
@@ -9,6 +9,7 @@
9-- Normally, you don't need to import this module, use 9-- Normally, you don't need to import this module, use
10-- "Network.BitTorrent.DHT" instead. 10-- "Network.BitTorrent.DHT" instead.
11-- 11--
12{-# LANGUAGE CPP #-}
12{-# LANGUAGE FlexibleContexts #-} 13{-# LANGUAGE FlexibleContexts #-}
13{-# LANGUAGE ScopedTypeVariables #-} 14{-# LANGUAGE ScopedTypeVariables #-}
14{-# LANGUAGE TemplateHaskell #-} 15{-# LANGUAGE TemplateHaskell #-}
@@ -49,7 +50,12 @@ module Network.BitTorrent.DHT.Query
49 , (<@>) 50 , (<@>)
50 ) where 51 ) where
51 52
53#ifdef THREAD_DEBUG
54import Control.Concurrent.Lifted.Instrument hiding (yield)
55#else
56import GHC.Conc (labelThread)
52import Control.Concurrent.Lifted hiding (yield) 57import Control.Concurrent.Lifted hiding (yield)
58#endif
53import Control.Exception.Lifted hiding (Handler) 59import Control.Exception.Lifted hiding (Handler)
54import Control.Monad.Reader 60import Control.Monad.Reader
55import Control.Monad.Logger 61import Control.Monad.Logger
@@ -227,6 +233,7 @@ refreshNodes nid = do
227-- routing table. 233-- routing table.
228insertNode :: forall ip. Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId 234insertNode :: forall ip. Address ip => NodeInfo ip -> Maybe ReflectedIP -> DHT ip ThreadId
229insertNode info witnessed_ip0 = fork $ do 235insertNode info witnessed_ip0 = fork $ do
236 -- myThreadId >>= liftIO . flip labelThread "DHT.insertNode"
230 var <- asks routingInfo 237 var <- asks routingInfo
231 tm <- getTimestamp 238 tm <- getTimestamp
232 let showTable = do 239 let showTable = do
@@ -286,8 +293,10 @@ insertNode info witnessed_ip0 = fork $ do
286 return ps 293 return ps
287 ps <- join $ liftIO $ atomically $ atomicInsert arrival0 witnessed_ip0 294 ps <- join $ liftIO $ atomically $ atomicInsert arrival0 witnessed_ip0
288 showTable 295 showTable
289 _ <- fork $ forM_ ps $ \(CheckPing ns)-> do 296 _ <- fork $ do
290 forM_ ns $ \n -> do 297 myThreadId >>= liftIO . flip labelThread "DHT.insertNode.pingResults"
298 forM_ ps $ \(CheckPing ns)-> do
299 forM_ ns $ \n -> do
291 (b,mip) <- probeNode (nodeAddr n) 300 (b,mip) <- probeNode (nodeAddr n)
292 let alive = PingResult n b 301 let alive = PingResult n b
293 $(logDebugS) "insertNode" $ T.pack ("PingResult "++show (nodeId n,b)) 302 $(logDebugS) "insertNode" $ T.pack ("PingResult "++show (nodeId n,b))
diff --git a/src/Network/BitTorrent/DHT/Session.hs b/src/Network/BitTorrent/DHT/Session.hs
index 8dc3f7ac..bad783a5 100644
--- a/src/Network/BitTorrent/DHT/Session.hs
+++ b/src/Network/BitTorrent/DHT/Session.hs
@@ -72,7 +72,11 @@ module Network.BitTorrent.DHT.Session
72import Prelude hiding (ioError) 72import Prelude hiding (ioError)
73 73
74import Control.Concurrent.STM 74import Control.Concurrent.STM
75#ifdef THREAD_DEBUG
76import Control.Concurrent.Async.Lifted.Instrument
77#else
75import Control.Concurrent.Async.Lifted 78import Control.Concurrent.Async.Lifted
79#endif
76import Control.Exception.Lifted hiding (Handler) 80import Control.Exception.Lifted hiding (Handler)
77import Control.Monad.Base 81import Control.Monad.Base
78import Control.Monad.Logger 82import Control.Monad.Logger